mirror of
https://github.com/NixOS/nix.git
synced 2025-12-22 17:01:08 +01:00
Merge pull request #14552 from hsjobeki/docs-sort
docs: add explanation to sort primop
This commit is contained in:
commit
e0830681e2
1 changed files with 18 additions and 2 deletions
|
|
@ -4061,6 +4061,8 @@ static RegisterPrimOp primop_sort({
|
||||||
|
|
||||||
1. Transitivity
|
1. Transitivity
|
||||||
|
|
||||||
|
If a is less than b and b is less than c, then it follows that a is less than c.
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
comparator a b && comparator b c -> comparator a c
|
comparator a b && comparator b c -> comparator a c
|
||||||
```
|
```
|
||||||
|
|
@ -4073,9 +4075,23 @@ static RegisterPrimOp primop_sort({
|
||||||
|
|
||||||
1. Transitivity of equivalence
|
1. Transitivity of equivalence
|
||||||
|
|
||||||
|
First, two values a and b are considered equivalent with respect to the comparator if:
|
||||||
|
|
||||||
|
```
|
||||||
|
!comparator a b && !comparator b a
|
||||||
|
```
|
||||||
|
|
||||||
|
In other words, neither is considered "less than" the other.
|
||||||
|
|
||||||
|
Transitivity of equivalence means:
|
||||||
|
|
||||||
|
If a is equivalent to b, and b is equivalent to c, then a must also be equivalent to c.
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
let equiv = a: b: (!comparator a b && !comparator b a); in
|
let
|
||||||
equiv a b && equiv b c -> equiv a c
|
equiv = x: y: (!comparator x y && !comparator y x);
|
||||||
|
in
|
||||||
|
equiv a b && equiv b c -> equiv a c
|
||||||
```
|
```
|
||||||
|
|
||||||
If the *comparator* violates any of these properties, then `builtins.sort`
|
If the *comparator* violates any of these properties, then `builtins.sort`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue