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>`.

18 lines (17 loc) 478 B
import { isNotNull } from '../core/nullable.js'; /** * Returns `null` if the _input_ is `null`, * otherwise calls _predicate_ with the value `T` and returns: * * * `T` if _predicate_ returns `true`. * * `null` if _predicate_ returns `false`. */ export async function filterAsyncForNullable(input, predicate) { if (isNotNull(input)) { const ok = await predicate(input); if (ok) { return input; } } return null; }