create 'Ordering' type
This commit is contained in:
parent
77dfc8b182
commit
b0023afe8c
15 changed files with 158 additions and 117 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// Total ordering of composed types
|
||||
|
||||
import { compareNumbers, compareStrings } from "./primitives.js"
|
||||
import { compareDoubles, compareStrings } from "./primitives.js"
|
||||
import { get, length as lengthLs } from "../structures/list.js";
|
||||
import { read as readSet, length as lengthSet, first as firstSet } from "../structures/set.js";
|
||||
import { read as readDict, length as lengthDict, first as firstDict } from "../structures/dict.js";
|
||||
|
|
@ -13,7 +13,7 @@ export const compareFunctions = _compareInput => _compareOutput => x => y => {
|
|||
}
|
||||
|
||||
export const compareLists = compareElems => x => y => {
|
||||
return compareNumbers(lengthLs(x))(lengthLs(y))
|
||||
return compareDoubles(lengthLs(x))(lengthLs(y))
|
||||
|| (() => {
|
||||
for (let i=0; i<lengthLs(x); i++) {
|
||||
const elemCmp = compareElems(get(x)(i))(get(y)(i));
|
||||
|
|
@ -50,7 +50,7 @@ export const compareSums = compareLeft => compareRight => x => y => {
|
|||
};
|
||||
|
||||
export const compareSets = compareElems => x => y => {
|
||||
return compareNumbers(lengthSet(x))(lengthSet(y))
|
||||
return compareDoubles(lengthSet(x))(lengthSet(y))
|
||||
|| (() => {
|
||||
// sets have same size -> iterate over both sets and compare their elements pairwise
|
||||
// because of the underlying red-black tree, iteration happens in ordered fashion
|
||||
|
|
@ -71,7 +71,7 @@ export const compareSets = compareElems => x => y => {
|
|||
};
|
||||
|
||||
export const compareDicts = compareKeys => compareValues => x => y => {
|
||||
return compareNumbers(lengthDict(x))(lengthDict(y))
|
||||
return compareDoubles(lengthDict(x))(lengthDict(y))
|
||||
|| (() => {
|
||||
// dicts have same size -> iterate over both and compare their entries pairwise
|
||||
// because of the underlying red-black tree, iteration happens in ordered fashion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue