This file contains 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 utils | |
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends ( | |
x: infer R | |
) => any | |
? R | |
: never; | |
type UnionOf<T extends object> = T[keyof T]; | |
type IntersectionOf<T extends object> = UnionToIntersection<UnionOf<T>>; |
This file contains 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 ProcedureContext = { | |
path: Procedure[]; | |
next: (procedure: Procedure) => void; | |
}; | |
type Procedure = { | |
run: (ctx: ProcedureContext) => unknown; | |
}; | |
const runProcedure = ( |
This file contains 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
import { interval, isObservable } from 'rxjs' | |
import { tap } from 'rxjs/operators' | |
const type = { | |
isThenable: obj => !!(obj && typeof obj.then === 'function'), | |
isObservable: obj => !!(obj && isObservable(obj)), | |
isError: obj => obj instanceof Error, | |
isObject: obj => obj != null && typeof obj === 'object' | |
} |
This file contains 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 type Fetch<K = unknown, V = unknown> = (key: K) => V | |
type Task<K = unknown, V = unknown> = (fetch: Fetch<K, V>) => V | |
type Tasks<K = unknown, V = unknown> = (key: K) => Task<K, V> | null | |
type Store<K, V> = Map<K, V> | |
type Build<K, V> = (tasks: Tasks<K, V>, key: K, store: Store<K, V>) => void |
This file contains 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 PassengerEnName = { | |
type: 'PassengerEnName'; | |
firstname: string; | |
middlename?: string; | |
lastname: string; | |
}; | |
type PassengerCnName = { | |
type: 'PassengerCnName'; | |
firstname: string; |
This file contains 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 ResourcesValue<T> = T extends [] | |
? never | |
: T extends [Resource<infer V>] | |
? [V] | |
: T extends [Resource<infer V>, ...infer Rest] | |
? [V, ...ResourcesValue<Rest>] | |
: never; | |
type InitResource = { | |
init<T>( |
This file contains 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
// parser combinator | |
const fail = () => [] | |
const failed = list => list.length === 0 | |
const of = value => input => [value, input] | |
const bind = (parser, f) => input => { | |
let result = parser(input) |
This file contains 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 ParseResult = { | |
success: boolean, | |
data: any, | |
source: string | |
} | |
type ParseFailed = { | |
suceess: false, | |
data: any, | |
source: string |
This file contains 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 log = (message) => { | |
return { | |
__typename: 'log', | |
message, | |
}; | |
}; | |
const raise = (message) => { | |
return { | |
__typename: 'exception', |
This file contains 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
function pipe<T, A>(a: T[], a1: ListAction<T, A>): A[]; | |
function pipe<T, A, B>(a: T[], a1: ListAction<T, A>, a2: ListAction<A, B>): B[]; | |
function pipe<T, A, B, C>( | |
a: T[], | |
a1: ListAction<T, A>, | |
a2: ListAction<A, B>, | |
a3: ListAction<B, C> | |
): C[]; |