Skip to content

Some traversey type thing #16

@garyb

Description

@garyb

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? 😉

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs more infoThis issue needs more info before any action can be done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions