Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4014,6 +4014,8 @@ static RegisterPrimOp primop_sort({

1. Transitivity

If a is less than b and b is less than c, then it follows that a is less than c.

```nix
comparator a b && comparator b c -> comparator a c
```
Expand All @@ -4026,9 +4028,23 @@ static RegisterPrimOp primop_sort({

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
let equiv = a: b: (!comparator a b && !comparator b a); in
equiv a b && equiv b c -> equiv a c
let
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`
Expand Down
Loading