system-f / validation

A data-type like Either but with an accumulating Applicative
Other
99 stars 28 forks source link

Applicative/Monad version of bindValidation? #40

Closed symbiont-oskar-wickstrom closed 5 years ago

symbiont-oskar-wickstrom commented 5 years ago

Hey, thanks for the awesome library! I ran into a case where I wanted a monadic action on the right-hand side of bindValidation. I've written my own definition bindValidationA, as it could just as well be Applicative:

bindValidationA :: Applicative f => Validation e a -> (a -> f (Validation e b)) -> f (Validation e b)
bindValidationA (Failure e) _  = pure (Failure e)
bindValidationA (Success a) mb = mb a

Is this something you'd like added to the library? We could rewrite bindValidation using Identity with it, if desired. I can submit a PR. Thanks!

tonymorris commented 5 years ago

I think this is the use-case for what we used to have in the library, ValidationT, but can be done with ExceptT.

symbiont-oskar-wickstrom commented 5 years ago

All right. Yeah, if there's a lot of these in sequence then using ExceptT makes sense. I only have a single bindValidationA, so it feels a bit heavy-weight in my case. Maybe I can find another way around it. I'll close this ticket.