Skip to main content
Module

x/fun/set.ts>filterMap

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 filterMap
import { filterMap } from "https://deno.land/x/fun@v2.0.0-alpha.6/set.ts";

Given a function A -> Option and a ReadonlySet return a ReadonlySet by applying the function to all values A. Any Nones will not enter the resultant set while Some values will. This is effectively filtering and mapping simultaneously.

Examples

Example 1

import * as S from "./set.ts";
import * as O from "./option.ts";
import { pipe } from "./fn.ts";

const set = S.set("one", "two", "three", "four", "five");

const result = pipe(
  set,
  S.filterMap(s => s.includes('o') ? O.some(s.length) : O.none),
); // Set(3, 4)

Parameters

fai: (a: A) => Option<I>

Returns

(ua: ReadonlySet<A>) => ReadonlySet<I>