Skip to main content
Module

x/fun/option.ts>filter

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function filter
import { filter } from "https://deno.land/x/fun@v2.0.0-alpha.12/option.ts";

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>