Skip to content

Instantly share code, notes, and snippets.

@ccapndave
Created November 1, 2022 08:05
Show Gist options
  • Save ccapndave/b818db88f502d1bacea79db4513d07f3 to your computer and use it in GitHub Desktop.
Save ccapndave/b818db88f502d1bacea79db4513d07f3 to your computer and use it in GitHub Desktop.
function when<A, B>(value: A | null, f: (value: A) => B): B | null;
function when<A, B>(value: A | undefined, f: (value: A) => B): B | undefined;
function when<A, B>(value: A, f: (value: A) => B) {
return value === null || value === undefined ? f(value) : value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment