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 😄 It's part way between ala (map unwrap (f wrap) and alaF (map unwrap <<< f <<< map wrap). alaT? 😉
So I came up with this thing:
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
Firstsemigroup can replace the currentFirstmonoid provided byMaybe, but it works in a different way, you'd use it something like this:Or with the combinator:
So it's an
alakind of thing, but kinda traverse-y too 😄 It's part way betweenala(map unwrap (f wrap) andalaF(map unwrap <<< f <<< map wrap).alaT? 😉