UNPKG

option-t

Version:

A toolkit of Nullable/Option/Result type implementation in ECMAScript. Their APIs are inspired by Rust's `Option<T>` and `Result<T, E>`.

20 lines (19 loc) 558 B
import { isNone, createNone } from './option.js'; /** * Returns `None` if the option is `None`, * otherwise the result should be resolved by the result of _predicate_ with the wrapped value as the arguments: * * * `Some(t)` if _predicate_ returns `true`. * * `None` if _predicate_ returns `false`. */ export function filterForOption(input, predicate) { if (isNone(input)) { return input; } const ok = predicate(input.val); if (!ok) { return createNone(); } const result = input; return result; }