defaultWith

If is Some, then returns its value. If is None, then returns the value returned by the defaultThunk.

Type

type defaultWith = <T>(defThunk: () => T) => (option: Option<T>) => T

Examples

import {defaultWith, Some} from 'fnxt/option';

const getValue = defaultWith(()=>0);
getValue(Some(42)) // -> 42
import {defaultWith, None} from 'fnxt/option';

const getValue = defaultWith(()=>0);
getValue(None) // -> 0

See Also