diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/prelude/array.ts | 7 | ||||
| -rw-r--r-- | src/prelude/relation.ts | 2 |
2 files changed, 6 insertions, 3 deletions
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<T>(f: (x: T) => boolean, xs: T[]): number { + +export function countIf<T>(f: Predicate<T>, 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<T>(f: (x: T) => boolean, xs: T[]): T[] { +export function takeWhile<T>(f: Predicate<T>, 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<T> = (x: T) => boolean; + export type Relation<T, U> = (x: T, y: U) => boolean; export type EndoRelation<T> = Relation<T, T>; |