Skip to content

Instantly share code, notes, and snippets.

@zaetrik
Last active May 6, 2020 13:07
Show Gist options
  • Save zaetrik/ecf7b32087645811b84e0972261790a5 to your computer and use it in GitHub Desktop.
Save zaetrik/ecf7b32087645811b84e0972261790a5 to your computer and use it in GitHub Desktop.
Function Composition Lift
// 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