Skip to content

Instantly share code, notes, and snippets.

@benjstephenson
Last active June 29, 2023 21:48
Show Gist options
  • Save benjstephenson/c77347f08721e85584c50a5c92ee7d08 to your computer and use it in GitHub Desktop.
Save benjstephenson/c77347f08721e85584c50a5c92ee7d08 to your computer and use it in GitHub Desktop.
const foo: number | undefined = 2
const inc: (x: number) => number = x => x + 1
const lift: <A, B>(f: (a: A) => B) => (a: A | undefined) => B | undefined =
f => a => a === undefined
? undefined
: f(a)
const map: <A, B>(a: A | undefined) => (f: (a: A) => B) => B | undefined =
a =>
f => a === undefined
? undefined
: f(a)
const bar = map(foo)(inc)
const baz = lift(inc)(foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment