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 a Map:
> 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 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?
profunctor-lenseshas theixfunction to produce 0-or-1 (“affine”)Traversals. It’s nice for arrays and maps. I noticed it also has an instance forSet. Fooling around, I saw the following:This is peculiar in several ways:
You cannot use
(ix “foo”)to insert a new value into aMap:… and yet you can with a
Set.I’m not sure what form the
set-getoptics law should take withixoptics. But you can’t get what you can set, which seems odd. Actually, as far as I can tell, you can’tvieworpreviewanything in aSet:Is the instance for
Seta well-behaved optic? Should it be?