Open
Description
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:
-
You cannot use
(ix “foo”)
to insert a new value into aMap
:> set (ix "foo") "bar" Map.empty (fromFoldable [])
… and yet you can with a
Set
. -
I’m not sure what form the
set-get
optics law should take withix
optics. But you can’t get what you can set, which seems odd. Actually, as far as I can tell, you can’tview
orpreview
anything in aSet
:> 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?
Metadata
Metadata
Assignees
Labels
No labels