Skip to main content
Module

x/fun/record.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@v.2.0.0-alpha.11/record.ts";

Given a refinement or a predicate, filter a ReadonlyRecord by removing any values that do not match the predicate or refinement. ie. When the predicate/refinement return true a value is kept and when it returns false a value is removed.

Examples

Example 1

import * as R from "./record.ts";
import { pipe } from "./fn.ts";

const result = pipe(
  { one: 1, two: 2, three: 3 },
  R.filter(n => n > 1),
); // { one: 1 }

Type Parameters

A
I extends A

Parameters

refinement: (a: A, key: string) => a is I

Parameters

predicate: (a: A, key: string) => boolean