serokell / universum

:milky_way: Prelude written in @Serokell
MIT License
176 stars 28 forks source link

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

Open chshersh opened 6 years ago

chshersh commented 6 years ago

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.