Copyright | (c) Joel Burget 2018-2019; Edward Kmett 2012-2016 |
---|---|
License | MIT |
Maintainer | joelburget@gmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell98 |
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
- _Left :: Prism (Either a c) (Either b c) a b
- _Right :: Prism (Either c a) (Either c b) a b
- _Just :: Prism (Maybe a) (Maybe b) a b
- _Nothing :: Prism' (Maybe a) ()
- only :: Eq a => a -> Prism' a ()
- nearly :: a -> (a -> Bool) -> Prism' a ()
- type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
- type Prism' s a = Prism s s a a
Documentation
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.