maybeOut :: (a -> b) -> (a -> Maybe b) maybeOut = (.) Just
const maybe = <T,>(f: (_: T) => T, d:T) => (x: T|null) => f(x || d); console.log(maybe((x) => 2 * x, 3)(null)); // returns: 6