Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the Set instance of ix a well-behaved optic? #83

Open
marick opened this issue Mar 19, 2018 · 0 comments
Open

Is the Set instance of ix a well-behaved optic? #83

marick opened this issue Mar 19, 2018 · 0 comments

Comments

@marick
Copy link
Collaborator

marick commented Mar 19, 2018

profunctor-lenses has the ix function to produce 0-or-1 (“affine”) Traversals. It’s nice for arrays and maps. I noticed it also has an instance for Set. Fooling around, I saw the following:

     > result = set (ix "foo") unit Set.empty
     > result
     (fromFoldable ("foo" : Nil))

    > preview (ix "foo") result
    Nothing

This is peculiar in several ways:

  1. You cannot use (ix “foo”) to insert a new value into a Map:

    > set (ix "foo") "bar" Map.empty
    (fromFoldable [])

    … and yet you can with a Set.

  2. I’m not sure what form the set-get optics law should take with ix optics. But you can’t get what you can set, which seems odd. Actually, as far as I can tell, you can’t view or preview anything in a Set:

    > preview (ix "foo") (Set.singleton "foo")
    Nothing
    
    > view (ix "foo") (Set.singleton "foo")
    unit

Is the instance for Set a well-behaved optic? Should it be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants