Emit standalone lens pairs for nested record composition

This commit is contained in:
milner committed 2019-03-18 10:46:43 +00:00
1 parent c2d6f2aa05
commit d4328bac3f
2 files changed
+16 -1

No files matched your search

+14
View File
@@ -38,3 +38,17 @@ let () =
(try ignore (Colour.update_red ~f:(fun _ -> failwith "callback") original); assert false
with Failure message -> assert (message = "callback"));
assert (Colour.red original = 3)
module Swatch = struct
type t = { colour : Colour.t; label : string } [@@fieldglass generate]
end
let () =
let open Fieldglass in
let original = Swatch.{ colour = Colour.{ red = 3; green = 4; blue = 5 }; label = "grey" } in
let focus = compose Swatch._colour Colour._red in
assert (view focus original = 3);
let changed = set focus 8 original in
assert (view focus changed = 8 && Swatch.label changed = "grey");
assert (set focus (view focus original) original = original);
assert (set Box._contents "grey" Box.{ contents = 9 } = Box.{ contents = "grey" })