Last active
May 6, 2020 13:07
-
-
Save zaetrik/ecf7b32087645811b84e0972261790a5 to your computer and use it in GitHub Desktop.
Function Composition Lift
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
// Taken from https://dev.to/gcanti/getting-started-with-fp-ts-functor-36ek | |
// Here we lift a pure function to work with Array | |
function lift<B, C>(g: (b: B) => C): (fb: Array<B>) => Array<C> { | |
return fb => fb.map(g) | |
} | |
import { Option, isNone, none, some } from 'fp-ts/lib/Option' | |
// Here we lift a pure function to work with Option | |
function lift<B, C>(g: (b: B) => C): (fb: Option<B>) => Option<C> { | |
return fb => (isNone(fb) ? none : some(g(fb.value))) // we just unwrap the value inside the Option and apply it to our pure function g() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment