Skip to main content
Module

x/fun/mod.ts>array.filter

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

Given a Predicate or Refinement, apply the predicate or refinement to every value in an array, removing (and refining) the elements that the predicate or refinement return false for.

Examples

Example 1

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

const result = pipe(
  A.array(1, 2, 3, 4, 5, 6),
  A.filter(n => n % 2 === 0),
); // [2, 4, 6]

Type Parameters

A
B extends A

Parameters

refinement: (a: A, index: number) => a is B

Returns

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

Parameters

predicate: (a: A, index: number) => boolean

Returns

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