mirror of
https://github.com/tweag/nickel.git
synced 2024-10-06 16:18:08 +03:00
[Fix] Fix contract.Sequence reversing order (#1510)
* Fix contract.Sequence reversing order This commit started by fixing tests that didn't fire, because they involved contracts but were never executed. On of those tests failed after being fixed, indicating that `std.contract.Sequence` wasn't preserving the order of applied contracts. This commit fixes this issue as well by using `fold_left` instead of `fold_right` in the implementation of `Sequence`. * Formatting (stdlib)
This commit is contained in:
parent
5572b444b0
commit
943430e07e
@ -968,7 +968,11 @@
|
||||
```
|
||||
"%
|
||||
= fun contracts label value =>
|
||||
std.array.fold_right (fun contract => std.contract.apply contract label) value contracts,
|
||||
std.array.fold_left
|
||||
(fun acc contract => std.contract.apply contract label acc)
|
||||
value
|
||||
contracts,
|
||||
|
||||
label
|
||||
| doc m%"
|
||||
The label submodule provides functions that manipulate the label
|
||||
|
@ -165,12 +165,17 @@ let {check, Assert, ..} = import "../lib/assert.ncl" in
|
||||
let f | forall r. { ; r } -> { g : forall r. { ; r } -> { z : Number ; r }; r }
|
||||
= fun r => %record_insert% "g" r g in
|
||||
let res = f { z = 3 }
|
||||
in true,
|
||||
in std.seq res true,
|
||||
|
||||
# std.contract.Sequence
|
||||
let three = 3 | std.contract.Sequence [ Number, std.contract.from_predicate (fun x => x < 5) ] in
|
||||
# preserves order
|
||||
let tag = "some_tag" | std.contract.Sequence [ std.enum.TagOrString, [| 'some_tag |] ]
|
||||
in true
|
||||
let SmallerThanFive = std.contract.from_predicate (fun x => x < 5) in
|
||||
let three | std.contract.Sequence [ Number, SmallerThanFive] = 3 in
|
||||
three == 3,
|
||||
|
||||
# std.contract.Sequence preserves order
|
||||
let tag | std.contract.Sequence [std.enum.TagOrString, [| 'some_tag |]]
|
||||
= "some_tag"
|
||||
in
|
||||
tag == 'some_tag,
|
||||
]
|
||||
|> check
|
||||
|
Loading…
Reference in New Issue
Block a user