This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // data version | |
| type DraftPost = { | |
| kind: 'DraftPost'; | |
| content: string; | |
| }; | |
| type ReviewingPost = { | |
| kind: 'ReviewingPost'; | |
| content: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const fetch = (url, options = {}) => { | |
| let { fetch = globalThis.fetch, ...restOptions } = options; | |
| if (typeof fetch !== 'function') { | |
| throw new Error(`Expected fetch to be a function, but received ${fetch}`); | |
| } | |
| let finalUrl = url; | |
| let finalOptions = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type State = { | |
| count: number; | |
| }; | |
| type ActionVisitor = { | |
| incre: (step: number) => State; | |
| decre: (step: number) => State; | |
| }; | |
| type Action = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // option type | |
| interface OptionVisitor<A, B> { | |
| None: () => B; | |
| Some: (a: A) => B; | |
| } | |
| type OptionData<A> = | |
| | { | |
| kind: 'None'; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let identity = x => x | |
| let createBF = (getChildren) => { | |
| let handler = (stack = [], results = [], f) => { | |
| if (stack.length === 0) return results; | |
| let [head, ...tail] = stack; | |
| let nextStack = tail.concat(getChildren(head)); | |
| return handler(nextStack, [...results, f(head)], f); | |
| }; | |
| return (tree, f = identity) => handler([tree], [], f); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const createTreeModule = (operations) => { | |
| const append = (tree, node) => { | |
| if (operations.matchChild(tree, node)) { | |
| return operations.appendChild(tree, node); | |
| } | |
| return operations.map(tree, (child) => { | |
| return append(child, node); | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let run = (f, handlers) => { | |
| try { | |
| return f(); | |
| } catch (effect) { | |
| if (effect.type in handlers) { | |
| handlers[effect.type](effect.payload, effect.continuation); | |
| } else { | |
| throw effect | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const createOperation = name => (...args) => { | |
| let operation = interpreter => | |
| interpreter[name]( | |
| ...args.map(f => (f && f.operation ? f(interpreter) : f)) | |
| ); | |
| operation.operation = true; | |
| return operation; | |
| }; | |
| const createOperations = (...names) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Parser where | |
| import Prelude (($), (<>), (==), (>=), (<=), (&&), (/=), (||), (>>>), negate) | |
| import Data.Show (class Show, show) | |
| import Data.Tuple (Tuple(..)) | |
| import Data.Either (Either(..)) | |
| import Data.Array ((:), intercalate) | |
| import Data.Foldable (foldl, foldr) | |
| import Data.Maybe (Maybe(..)) | |
| import Data.String (codePointAt) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type result('a, 'b) = | |
| | Ok('a) | |
| | Error('b) | |
| let inject = value => input => (Ok(value), input) | |
| let error = e => input => (Error(e), input) | |
| let item = input => { | |
| let (index, source) = input |