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
Cache-Control: no-cache, no-store, must-revalidate | |
Pragma: no-cache | |
Expires: 0 |
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
<html> | |
<head> | |
<style> | |
.type-chars { | |
font-family: monospace; | |
font-size: 30px; | |
} | |
</style> | |
</head> | |
<body> |
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 */ | |
const createPerson = ({}: { name: string, birth: Date, pets: number }): [] => [] | |
const a = {}; | |
//createPerson(a); | |
const b = { ...a, name: 'fred' }; | |
//createPerson(b); |
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 }; |
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
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
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 }) |
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
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); | |
} |
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> => ({ |