import { Arity1, curry, Is, Predicate } from '@typed/lambda' import { map as maybeMap, Maybe, Nothing } from '@typed/maybe' export interface Match extends Arity1> {} export namespace Match { export const map = curry( (fn: (value: B) => C, match: Match): Match => (value: A) => maybeMap(fn, match(value)), ) as { (fn: (value: B) => C, match: Match): Match (fn: (value: B) => C): (match: Match) => Match } export function fromPredicate(predicate: Predicate): Match export function fromPredicate(predicate: Is): Match export function fromPredicate(predicate: Predicate): Match { return (value: A) => (predicate(value) ? Maybe.of(value) : Nothing) } }