Permalink
Browse files

mvap -> vapm, added apm, (under the old convention it was going to be…

…come 'map')
1 parent e8a1e8c commit 849342e9039f5a1be749ad4716a6e48553706284 @ekmett committed Dec 6, 2017
Showing with 16 additions and 6 deletions.
  1. +16 −6 src/Data/Either/Validation.hs
@@ -21,8 +21,10 @@ module Data.Either.Validation
, eitherToValidation
, validationToEither
, _Validation
- , vap, mvap
+ , vap
, ealt
+ -- combinators that leak less, but require monoid constraints
+ , vapm, apm
) where
import Control.Applicative
@@ -154,14 +156,22 @@ vap Right{} (Left n) = Left n
vap (Right f) (Right a) = Right (f a)
{-# INLINE vap #-}
+apm :: Monoid m => Validation m (a -> b) -> Validation m a -> Validation m b
+apm (Failure m) b = Failure $ m `mappend` case b of
+ Failure n -> n
+ Success{} -> mempty
+apm Success{} (Failure n) = Failure n
+apm (Success f) (Success a) = Success (f a)
+{-# INLINE apm #-}
+
-- lazier version of vap that can leak less, but which requires a Monoid
-mvap :: Monoid m => Either m (a -> b) -> Either m a -> Either m b
-mvap (Left m) b = Left $ m `mappend` case b of
+vapm :: Monoid m => Either m (a -> b) -> Either m a -> Either m b
+vapm (Left m) b = Left $ m `mappend` case b of
Left n -> n
Right{} -> mempty
-mvap Right{} (Left n) = Left n
-mvap (Right f) (Right a) = Right (f a)
-{-# INLINE mvap #-}
+vapm Right{} (Left n) = Left n
+vapm (Right f) (Right a) = Right (f a)
+{-# INLINE vapm #-}
ealt :: Validation e a -> Validation e a -> Validation e a
ealt Failure{} r = r

0 comments on commit 849342e

Please sign in to comment.