-1

If Either fmap is

(a -> b) -> p a a -> p a b

which stops mapping once a Left is returned.

What's name or type signature for a function which doesn't stop until it gets a Right result.

I suspect a bifunctor, but I really need it spelled out - don't quite get the subtlety of the logic of these things yet.

Perhaps some sort of fold fits also...

user3264325
  • 237
  • 1
  • 2
  • 9

1 Answers1

5
Data.Bifunctor.first :: (a -> b) -> Either a c -> Either b c

In ghci:

Data.Bifunctor> first (+1) (Left 0)
Left 1
Data.Bifunctor> first (+1) (Right 0)
Right 0
Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380