Created
February 16, 2019 05:45
-
-
Save ktilcu/8d8505f1ba0d499e52fed534a5766f7e to your computer and use it in GitHub Desktop.
FP in Typescript
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
| 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