Skip to content

Instantly share code, notes, and snippets.

@stijnmoreels
Created February 22, 2024 09:13
Show Gist options
  • Save stijnmoreels/bc644c772af10521f16c3d568e987357 to your computer and use it in GitHub Desktop.
Save stijnmoreels/bc644c772af10521f16c3d568e987357 to your computer and use it in GitHub Desktop.
// A lens that provides the name of the guest.
let name_ : ResultLens<Guest, string> =
(fun g -> Ok g.Name), (fun n _ -> Guest.create n)
// A lens on the guest list that provides the individual guests on the list.
let guests_ : ResultLens<GuestList, Guest list> =
(fun (GuestList xs) -> Ok xs), fun xs _ -> GuestList.create xs
// A lens that points to a single guest on the guest list.
let guest_ name : ResultLens<GuestList, Guest> =
guests_ >=> List.single_ (fun { Name = n } -> n = name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment