easytest-0.3: Simple, expressive testing library

Copyright(c) Joel Burget 2018-2019; Edward Kmett 2012-2016
LicenseMIT
Maintainerjoelburget@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell98

EasyTest.Prism

Description

This module defines lens-style prisms for use with matches / doesn'tMatch. These are equivalent and compatible with the definitions in Control.Lens.Prism.

Synopsis

Documentation

_Left :: Prism (Either a c) (Either b c) a b Source #

Prism to the Left half of an Either

_Right :: Prism (Either c a) (Either c b) a b Source #

Prism to the Right half of an Either

_Just :: Prism (Maybe a) (Maybe b) a b Source #

Prism to the Just in a Maybe

only :: Eq a => a -> Prism' a () Source #

This Prism compares for exact equality with a given value.

>>> only 4 # ()
4
>>> 5 ^? only 4
Nothing

nearly :: a -> (a -> Bool) -> Prism' a () Source #

This Prism compares for approximate equality with a given value and a predicate for testing, an example where the value is the empty list and the predicate checks that a list is empty (same as _Empty with the AsEmpty list instance):

>>> nearly [] null # ()
[]
>>> [1,2,3,4] ^? nearly [] null
Nothing
nearly [] null :: Prism' [a] ()

To comply with the Prism laws the arguments you supply to nearly a p are somewhat constrained.

We assume p x holds iff x ≡ a. Under that assumption then this is a valid Prism.

This is useful when working with a type where you can test equality for only a subset of its values, and the prism selects such a value.

type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t) Source #

A prism embodies one constructor of a sum type (as a lens embodies one part of a product type). See _Just, _Nothing, _Left, and _Right for examples. See Control.Lens.Prism for more explanation.

type Prism' s a = Prism s s a a Source #

A type-restricted prism. See Control.Lens.Prism for more explanation.