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 prime = <A>(iterable: AsyncIterable<A>): AsyncIterator<A> => { | |
| const iterator = iterable[Symbol.asyncIterator]() | |
| iterator.next() | |
| return iterator | |
| } |
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 Box<A> = () => A | null; | |
| type Sealer<A> = { | |
| seal(value: A): Box<A>; | |
| unseal(box: Box<A>): A | null; | |
| } | |
| const makeSealer = <A>(): Sealer<A> => { | |
| let open: Box<A> | null = null; | |
| return { | |
| seal(value: A): Box<A> { | |
| const box = (): A | null => (open === box ? value : null); |
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 getState = memoize(<A>(o: AsyncQueue<A>) => { | |
| const resolvers: Set<Array<(a: A) => void>> = new Set() | |
| const values: A[] = [] | |
| return { | |
| resolvers, | |
| values, | |
| update() { | |
| if (values.length === 0) { | |
| return | |
| } |
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
| class Deferred<A> { | |
| promise: Promise<A> | |
| constructor() { | |
| this.promise = new Promise((resolve, reject) => { | |
| this.resolve = resolve | |
| this.reject = reject | |
| }) | |
| } | |
| } |
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
| class Deferred<A> { | |
| promise: Promise<A> | |
| constructor() { | |
| this.promise = new Promise((resolve, reject) => { | |
| this.resolve = resolve | |
| this.reject = reject | |
| }) | |
| } | |
| } | |
| interface Deferred<A> { |
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 arraylikeToIterable = <A>(source: ArrayLike<A>): IterableIterator<A> => { | |
| let i = 0 | |
| return { | |
| next() { | |
| let done | |
| let value | |
| if (i < source.length) { | |
| done = false | |
| value = source[i] | |
| i += 1 |
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
| interface Settable<A, B> { | |
| set(key: A, value: B): this | |
| } | |
| interface Gettable<A, B> { | |
| get(key: A): B | undefined | |
| } | |
| interface GenericMap<A, B> extends GetSettable<A, B> { | |
| has(key: A): boolean |
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
| class PairWeakMap<A extends object, B extends object, C> { | |
| map: WeakMap<A, WeakMap<B, C>> | |
| constructor() { | |
| this.map = new WeakMap() | |
| } | |
| set(a: A, b: B, c: C): this { | |
| const { map } = this | |
| let submap = map.get(a) |
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 Delay = duration => new Promise(resolve => setTimeout(resolve, duration)) |
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 zip = (xs, ys) => xs.slice(0, Math.min(xs.length, ys.length)).map((x, i) => [x, ys[i]]); |