Skip to main content
Module

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

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>