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; |
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
// alternative observables, knowledge about Observables implemetation is required (ex: RxJs) | |
// this is fully type-annoteable (typescript, flowtype) | |
// An observer is a function that takes an item from the stream | |
// and must return a function that will be called with the next item in the stream | |
// this way stateful observers can mantain state in clojures and every instance of them if replayable. | |
// observers should not have side effects | |
// type Observer<T> = (item: T) => Observer<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
// @flow | |
/// as first we declare the contract our program will have with external world | |
type v1Api = { | |
getPerson(id: string): v1Person, | |
addPerson(person: v1Person): void | |
}; | |
type v1Person = { id: string, name: string, age: number }; |