Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>option.filter

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function option.filter
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

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

A
B extends A

Parameters

refinement: Refinement<A, B>

Returns

(ta: Option<A>) => Option<B>

Parameters

predicate: Predicate<A>

Returns

(ta: Option<A>) => Option<A>