import { curry } from '@typed/lambda' import { fromJust } from './fromJust' import { isNothing } from './isNothing' import { Maybe } from './Maybe' /** * Maps a `Maybe` to another `Maybe`. * @name chain(f: (value: A) => Maybe, maybe: Maybe): Maybe */ export const chain = curry(__chain) as { (f: (value: A) => Maybe, maybe: Maybe): Maybe (f: (value: A) => Maybe): (maybe: Maybe) => Maybe } function __chain(f: (value: A) => Maybe, maybe: Maybe): Maybe { return isNothing(maybe) ? maybe : f(fromJust(maybe)) }