diff --git a/src/prelude/array.ts b/src/prelude/array.ts index 7eee87bf8b..778e5e37c3 100644 --- a/src/prelude/array.ts +++ b/src/prelude/array.ts @@ -1,9 +1,10 @@ -import { EndoRelation } from "./relation"; +import { EndoRelation, Predicate } from './relation'; /** * Count the number of elements that satisfy the predicate */ -export function countIf(f: (x: T) => boolean, xs: T[]): number { + +export function countIf(f: Predicate, xs: T[]): number { return xs.filter(f).length; } @@ -97,7 +98,7 @@ export function lessThan(xs: number[], ys: number[]): boolean { /** * Returns the longest prefix of elements that satisfy the predicate */ -export function takeWhile(f: (x: T) => boolean, xs: T[]): T[] { +export function takeWhile(f: Predicate, xs: T[]): T[] { const ys = []; for (const x of xs) { if (f(x)) { diff --git a/src/prelude/relation.ts b/src/prelude/relation.ts index d3c3ee378a..b3aedc5ffc 100644 --- a/src/prelude/relation.ts +++ b/src/prelude/relation.ts @@ -1,3 +1,5 @@ +export type Predicate = (x: T) => boolean; + export type Relation = (x: T, y: U) => boolean; export type EndoRelation = Relation;