While trying to apply a function with multiple layers of functors to a member of a host data structure, as in the following example:
update ::
(SomeProductField -> Maybe (Int, SomeProductField)) ->
(SomeProduct -> Maybe (Int, SomeProduct))
I came up with the following utility:
inFunctor :: Functor f => Lens s t a b -> Lens s (f t) a (f b)
inFunctor lens f = getCompose . lens (Compose . f)
Allowing me to implement the update
function like this:
someProductFieldLens :: Lens' SomeProduct SomeProductField
update = inFunctor someProductFieldLens
I am wondering whether something like this is already present in "lens" and whether the same is achievable somehow otherwise using the existing means.