diff --git a/src/prelude/array.ts b/src/prelude/array.ts index 21d18a0af4..7eee87bf8b 100644 --- a/src/prelude/array.ts +++ b/src/prelude/array.ts @@ -1,3 +1,5 @@ +import { EndoRelation } from "./relation"; + /** * Count the number of elements that satisfy the predicate */ @@ -61,7 +63,7 @@ export function maximum(xs: number[]): number { * Splits an array based on the equivalence relation. * The concatenation of the result is equal to the argument. */ -export function groupBy(f: (x: T, y: T) => boolean, xs: T[]): T[][] { +export function groupBy(f: EndoRelation, xs: T[]): T[][] { const groups = [] as T[][]; for (const x of xs) { if (groups.length !== 0 && f(groups[groups.length - 1][0], x)) { diff --git a/src/prelude/relation.ts b/src/prelude/relation.ts new file mode 100644 index 0000000000..d3c3ee378a --- /dev/null +++ b/src/prelude/relation.ts @@ -0,0 +1,3 @@ +export type Relation = (x: T, y: U) => boolean; + +export type EndoRelation = Relation;