Compose lenses whilst preserving unfocussed data

This commit is contained in:
milner committed 2019-02-19 19:49:43 +00:00
1 parent 0f219fea14
commit d996eba971
3 files changed
+12

No files matched your search

+7
View File
@@ -13,3 +13,10 @@ let () =
let calls = ref 0 in
assert (over sample ~f:(fun text -> incr calls; text ^ "s") source = ("colours", true));
assert (!calls = 1)
let () =
let first = (fst, fun value (_, rest) -> value, rest) in
let second = (snd, fun value (rest, _) -> rest, value) in
let focus = compose first second in
assert (view focus ((true, "grey"), false) = "grey");
assert (set focus 9 ((true, "grey"), false) = ((true, 9), false))