-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add a function to traverse the contents of a lens #471
Comments
Hmm, we have I suppose we could have At the very least we could explain this better in |
Sorry, I should have said why instance Monoid a => Applicative ((,) a) This is why I'm looking for a lens-specific traversal, where I don't need as much as |
I see, sorry for not reading your example closely enough to spot that it doesn't support We currently have (excluding indexed versions) toIsoVL :: Is k An_Iso => Optic k is s t a b -> IsoVL s t a b
toPrismVL :: Is k A_Prism => Optic k is s t a b -> PrismVL s t a b
toLensVL :: Is k A_Lens => Optic k is s t a b -> LensVL s t a b
traverseOf :: (Is k A_Traversal, Applicative f) => Optic k is s t a b -> (a -> f b) -> s -> f t
atraverseOf :: (Is k An_AffineTraversal, Functor f) => Optic k is s t a b -> (forall r. r -> f r) -> (a -> f b) -> s -> f t
traverseOf_ :: (Is k A_Fold, Applicative f) => Optic' k is s a -> (a -> f r) -> s -> f () which feels a bit inconsistent. So it is plausible to add (some name for) traverseOf' :: (Is k A_Lens, Functor f) => Optic k is s t a b -> (a -> f b) -> (s -> f t) and perhaps we might also add toTraversalVL :: Is k A_Traversal => Optic k is s t a b -> TraversalVL s t a b
toAffineTraversalVL :: Is k An_AffineTraversal => Optic k is s t a b -> AffineTraversalVL s t a b
toFoldVL :: Is k A_Fold => Optic' k is s a -> FoldVL s a (and indexed versions). Of course these are somewhat redundant, but the fact they are redundant is a deep and interesting property of the van Laarhoven representation. So I can see that application code might well want " To summarise: I'm convinced we should add this, I'm just not sure what to call it. Neither |
No worries! Naming is indeed hard. My intuitive thoughts are something like |
The naming problem comes already from how to name a class: class Traversable t => Singleton t where
-- the member really should be verb... compare: traverse, map, ..., ...
singleton :: Functor f => (a -> f b) -> t a -> f (t b) It only has instances for types isomorphic to Agda calls it |
And FWIW, EDIT: In fact So we have:
|
In
lens
, we have:When
traverseOf
is given a lens, we getThe only corresponding function in
optics
istoLensVL
. This has the same type and behavior, but the name is much less informative. I'd like to suggestoptics
gets a combinator that has a better name thantoLensVL
.As an example of how I use this:
Here
V.ix
comes fromData.Vector.Sized
.Slot.uninstallTool :: MonadThrow m => Slot -> m (Tool, Slot)
, so by usingtraverseOf
withCompose
, I essentially get the way to update a "toolbank slot", while also returning aTool
as a result.Using
toLensVL
would make this much less obvious.The text was updated successfully, but these errors were encountered: