Skip to content

Instantly share code, notes, and snippets.

@ktilcu
Created February 16, 2019 05:45
Show Gist options
  • Select an option

  • Save ktilcu/8d8505f1ba0d499e52fed534a5766f7e to your computer and use it in GitHub Desktop.

Select an option

Save ktilcu/8d8505f1ba0d499e52fed534a5766f7e to your computer and use it in GitHub Desktop.
FP in Typescript
function prop<T, K extends keyof T>(name: K, o: T): T[K] {
return o[name];
}
function maybeProp<T, K extends keyof T>(name: K, o: T): Option<T[K]> {
return fromNullable(o[name]);
}
const safeProp = R.curry(maybeProp);
const pipeK = R.pipeK;
function distribute<T>(os: Option<T[]>): Array<Option<T>> {
return R.sequence(R.of, os);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment