import { curry } from '@typed/lambda' import { chain } from './chain' import { Maybe } from './Maybe' /** * Applies a function to the value possibly contained in a `Maybe`. If the * maybe is a `Nothing` just the `Nothing` is returned. * @name map(f: (value: A) => B, maybe: Maybe): Maybe */ export const map = curry(__map) as { (f: (value: A) => B, maybe: Maybe): Maybe (f: (value: A) => B): (maybe: Maybe) => Maybe } function __map(f: (value: A) => B, maybe: Maybe): Maybe { return chain((a) => Maybe.of(f(a)), maybe) }