This article by Chris Penner talks about "Witherable Optics"; Optics that can be used to filter items out from a structure.
The article uses the following "Van Laarhoven" representation for these optics:
type Wither s t a b = forall f. Alternative f => (a -> f b) -> s -> f t
Most (if not all) Van Laarhoven optics have an equivalent profunctor representation. For example Lens:
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
Is equivalent to:
type Lens s t a b = forall p. Strong p => p a b -> p s t
Does Wither
also have a Profuctor representation? And if so, what is it?
Chris here; here's my swing at the profunctor optics representation:
Here's the profunctor class:
If you're interested in some of the optics that arise, I've implemented a few of those here:
It's definitely possible there are other interpretations or perhaps some simpler representation, but at the moment this seems to do the trick. If anyone else has other ideas I'd love to see them!
Happy to chat about it more if you have any other questions!