HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulevalidation-selective-0.2.0.0Haskell2010

Validation.Combinators

SPDX-License-Identifier: MPL-2.0 Maintainer: Kowainik xrom.xkov@gmail.com Stability: Stable Portability: Portable

Helpful combinators to work with Validation data type.

  • 13 values

When* functions

8 declarations
valuewhenSuccess :: Applicative f => x -> Validation e a -> (a -> f x) -> f x
#

Applies the given action to Validation if it is Success and returns the result. In case of Failure the default value is returned.

Example1 expression
whenSuccess "bar" (Failure "foo") (\a -> "success!" <$ print a)"bar"
Example1 expression
whenSuccess "bar" (Success 42) (\a -> "success!" <$ print a)42"success!"
valuewhenFailure :: Applicative f => x -> Validation e a -> (e -> f x) -> f x
#

Applies the given action to Validation if it is Failure and returns the result. In case of Success the default value is returned.

Example1 expression
whenFailure "bar" (Failure 42) (\a -> "foo" <$ print a)42"foo"
Example1 expression
whenFailure "bar" (Success 42) (\a -> "foo" <$ print a)"bar"
valuewhenSuccessM :: Monad m => x -> m (Validation e a) -> (a -> m x) -> m x
#

Monadic version of whenSuccess. Applies monadic action to the given Validation in case of Success. Returns the resulting value, or provided default.

Example1 expression
whenSuccessM "bar" (pure $ Failure "foo") (\a -> "success!" <$ print a)"bar"
Example1 expression
whenSuccessM "bar" (pure $ Success 42) (\a -> "success!" <$ print a)42"success!"
valuewhenFailureM :: Monad m => x -> m (Validation e a) -> (e -> m x) -> m x
#

Monadic version of whenFailure. Applies monadic action to the given Validation in case of Failure. Returns the resulting value, or provided default.

Example1 expression
whenFailureM "bar" (pure $ Failure 42) (\a -> "foo" <$ print a)42"foo"
Example1 expression
whenFailureM "bar" (pure $ Success 42) (\a -> "foo" <$ print a)"bar"

Maybe conversion

4 declarations