import { option } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { filter } = option;
Apply a refinement or predicate to the inner value of an Option, returning the original option if the value exists and the predicate/refinement return true, otherwise returning None.
Examples
Example 1
Example 1
import * as O from "./option.ts";
import { pipe } from "./fn.ts";
const positive = (n: number) => n > 0;
const result1 = pipe(O.some(1), O.filter(positive)); // Some(1)
const result2 = pipe(O.some(0), O.filter(positive)); // None
const result3 = pipe(O.none, O.filter(positive)); // None
Type Parameters
B extends A