import { curry } from '@typed/lambda' import { fromJust } from './fromJust' import { isJust } from './isJust' import { Maybe } from './Maybe' /** * Given a default value and a Maybe returns the default value if the Maybe is a * Nothing or the value contained in a Just. * @name withDefault(defaultValue: A, maybe: Maybe): A */ export const withDefault = curry(__withDefault) as { (defaultValue: A, maybe: Maybe): A (defaultValue: A): (maybe: Maybe) => A } function __withDefault(defaultValue: A, maybe: Maybe): A { return isJust(maybe) ? fromJust(maybe) : defaultValue }