HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

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.

Contents
  1. When* functions
  2. Maybe conversion
Synopsis

When* functions

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