Add polymorphic tuple projections and replacements
This commit is contained in:
3 files changed
+10
No files matched your search
@@ -9,3 +9,6 @@ let over (get, put) ~f source = put (f (get source)) source
|
|||||||
let compose (outer_get, outer_put) (inner_get, inner_put) =
|
let compose (outer_get, outer_put) (inner_get, inner_put) =
|
||||||
(fun source -> inner_get (outer_get source)),
|
(fun source -> inner_get (outer_get source)),
|
||||||
(fun value source -> outer_put (inner_put value (outer_get source)) source)
|
(fun value source -> outer_put (inner_put value (outer_get source)) source)
|
||||||
|
|
||||||
|
let _1 = (fun (left, _) -> left), (fun left (_, right) -> left, right)
|
||||||
|
let _2 = (fun (_, right) -> right), (fun right (left, _) -> left, right)
|
||||||
@@ -6,3 +6,5 @@ val view : ('s, 't, 'a, 'b) lens -> 's -> 'a
|
|||||||
val set : ('s, 't, 'a, 'b) lens -> 'b -> 's -> 't
|
val set : ('s, 't, 'a, 'b) lens -> 'b -> 's -> 't
|
||||||
val over : ('s, 't, 'a, 'b) lens -> f:('a -> 'b) -> 's -> 't
|
val over : ('s, 't, 'a, 'b) lens -> f:('a -> 'b) -> 's -> 't
|
||||||
val compose : ('s, 't, 'a, 'b) lens -> ('a, 'b, 'c, 'd) lens -> ('s, 't, 'c, 'd) lens
|
val compose : ('s, 't, 'a, 'b) lens -> ('a, 'b, 'c, 'd) lens -> ('s, 't, 'c, 'd) lens
|
||||||
|
val _1 : ('a * 'c, 'b * 'c, 'a, 'b) lens
|
||||||
|
val _2 : ('c * 'a, 'c * 'b, 'a, 'b) lens
|
||||||
@@ -20,3 +20,8 @@ let () =
|
|||||||
let focus = compose first second in
|
let focus = compose first second in
|
||||||
assert (view focus ((true, "grey"), false) = "grey");
|
assert (view focus ((true, "grey"), false) = "grey");
|
||||||
assert (set focus 9 ((true, "grey"), false) = ((true, 9), false))
|
assert (set focus 9 ((true, "grey"), false) = ((true, 9), false))
|
||||||
|
|
||||||
|
let () =
|
||||||
|
assert (set _1 "grey" (1, true) = ("grey", true));
|
||||||
|
assert (over _2 ~f:string_of_int (false, 9) = (false, "9"));
|
||||||
|
assert (view (compose _1 _2) ((true, "grey"), ()) = "grey")
|
||||||
Reference in new issue
Block a user