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 interface ActionHandler<State, Payload> { | |
(state: State, payload: Payload): State; | |
} | |
export interface ActionHandlers<State> { | |
[index: string]: ActionHandler<State, any>; | |
} | |
export interface Action<Type, Payload> { | |
type: Type; | |
payload: Payload; |
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 type Parameter1Type<Fun extends (...parameters: any[]) => any> = Fun extends (parameter1: infer Parameter1, ...parameters: any[]) => any ? Parameter1 : never; | |
export type Parameter2Type<Fun extends (...parameters: any[]) => any> = Fun extends (parameter1: any, parameter2: infer Parameter2, ...parameters: any[]) => any ? Parameter2 : never; | |
export type Parameter3Type<Fun extends (...parameters: any[]) => any> = Fun extends (parameter1: any, parameter2: any, parameter3: infer Parameter3, ...parameters: any[]) => any ? Parameter3 : never; | |
export type Parameter4Type<Fun extends (...parameters: any[]) => any> = Fun extends (parameter1: any, parameter2: any, parameter3: any, parameter4: infer Parameter4, ...parameters: any[]) => any ? Parameter4 : never; | |
export type Parameter5Type<Fun extends (...parameters: any[]) => any> = Fun extends (parameter1: any, parameter2: any, parameter3: any, parameter4: any, parameter5: infer Parameter5, ...parameters: any[]) => any ? Parameter5 : never; | |
export type Parameter6Ty |
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 Reducer<Memo, Item> = (memo: Memo, item: Item) => Memo | |
type Transducer<Memo, Item, ToItem> = (reducing: Reducer<Memo, ToItem>) => Reducer<Memo, Item> | |
type Mapper<A, B> = (a: A) => B; | |
const mapping = <Memo, Item, ToItem>(mapper: Mapper<Item, ToItem>): Transducer<Memo, Item, ToItem> => | |
reducing => (memo, item) => | |
reducing(memo, mapper(item)) | |
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
#!/usr/bin/env bash | |
package_name=$1 | |
temp_dir="/tmp/ypx/$package_name/$(date +%s%N)" | |
mkdir -p $temp_dir | |
(cd $temp_dir; yarn add $package_name) && (PATH="$temp_dir/node_modules/.bin":$PATH; "$@") | |
rm -rf $temp_dir |
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 MyProgramDSL<T> { | |
read: () => Promise<string>; | |
write: (value: string) => Promise<void> | |
done: (value: T) => Promise<T> | |
} | |
const MyProgram = async ({ read, write, done }: MyProgramDSL<string>) => { | |
await write("Hello, what is your name?"); | |
const name = await read(); |
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 get = Symbol("get"); | |
export const set = Symbol("set"); | |
interface Lens<T, V> { | |
[get]: (o: T) => V; | |
[set]: (v: V) => (t: T) => T; | |
} | |
const identity = <T>(): Lens<T, T> => ({ |
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 Nothing<T> implements PromiseLike<T> { | |
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2> { | |
return (onrejected as any)(this); | |
} | |
} | |
class Just<T> implements PromiseLike<T> { | |
constructor(private value: T) { } | |
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2> { | |
return (onfulfilled as any)(this.value); | |
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 function singleton<T>(builder: () => T): () => T { | |
let getter = () => { | |
const value = builder(); | |
getter = () => value; | |
return value; | |
} | |
return () => getter() | |
} | |
const x = singleton(() => { console.log("creating 5"); return 5 }) |
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 function retrySync<Fun extends (...args: any[]) => any, State>({ | |
fun, | |
predicate, | |
nextState, | |
state | |
}: { | |
fun: Fun; | |
state: State; | |
nextState: (state: State) => State; | |
predicate: (state: State) => boolean; |