Skip to main content
Module

x/fun/array.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/array.ts";

Filter and map over an ReadonlyArray in the same step. This function applies the predicate to each value in an array. If the predicate returns Some, then the inner I is added to the output array.

Examples

Example 1

import * as A from "./array.ts";
import * as O from "./option.ts";
import { pipe } from "./fn.ts";

const result = pipe(
  A.array("Hello", "Big", "World"),
  A.filterMap(s => s.includes("o") ? O.some(s.toUpperCase()) : O.none),
); // ["HELLO", "WORLD"]

Parameters

predicate: (a: A, index: number) => Option<I>

Returns

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