Some traversey type thing
So I came up with this thing:
what
:: forall f g t a b
. Functor f
=> Functor g
=> Newtype t b
=> (b -> t)
-> ((g b -> g t) -> a -> f t)
-> a
-> f b
what _ f = map unwrap <<< f (map wrap)
I was thinking about calling it traverseF, but that's not really right at all aside from superficially having the same shape for the value being operated on and result.
The use case is motivated by @matthewleon's semigroups, for example, the First semigroup can replace the current First monoid provided by Maybe, but it works in a different way, you'd use it something like this:
map (un First) $ foldMap1 (map First) =<< NEA.fromArray [Nothing, Just "foo", Just "bar", Nothing]
Or with the combinator:
what First foldMap1 =<< NEA.fromArray [Nothing, Just "foo", Just "bar", Nothing]
So it's an ala kind of thing, but kinda traverse-y too :smile: It's part way between ala (map unwrap (f wrap) and alaF (map unwrap <<< f <<< map wrap). alaT? :wink:
Or maybe it shouldn't exist at all?
I was thinking, when I wrote the example code for using the First semigroup, that it would benefit from something like this. Will have a closer look later.
I think the code shown here can be written differently now that we have coerce.