One thing zou could do is create an IRef<int option> out of it with LensInto:

1
2
3
4
5
6
7
8
9
10
let dogOwner name =
    listModel.LensInto
        (function
            | Dog (_, owner) -> Some owner
            | Cat _ -> None)
        (fun a s ->
            match s, a with
            | Some o, Dog (name, owner) -> Dog (name, owner)
            | _, x -> x)
        name

It would probably be nice to have a Prism function to complement Lens like in Aether, which would have getters and setters of the form ('T -> 'V option) * ('T -> 'V -> 'V).

By on 4/4/2016 1:10 AM ()

Taking a deeper look into it Prism is not really applicable here as our lenses are a bit different because of how IRefs and Var operate in general.

By on 4/4/2016 2:09 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper