universum icon indicating copy to clipboard operation
universum copied to clipboard

Add 'whenLeft_' and 'whenLeftM_' (and same for '*Right*')

Open chshersh opened this issue 6 years ago • 0 comments

Currently whenLeft has this type:

whenLeft :: Applicative f => Either l r -> (l -> f ()) -> f ()

I propose to rename whenLeft to whenLeft_ and add the following whenLeft:

whenLeft :: Applicative f => Either l r -> (l -> f r) -> f r

This might be useful when you want to throw exception on Left constructor, like this:

foo = do
    result <- decodeFile "path/to/config/file"
    config <- whenLeft result throwIO
    ... 

Also consider doing the same for whenJust. Relates to #150.

chshersh avatar May 24 '18 03:05 chshersh