Type synonym for a type-modifying prism.
Moduleoptics-core-0.4.1.1Haskell2010
Optics.Prism
- 3 types
- 8 values
- Packageoptics-core-0.4.1.1
- Exports11
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourcePrism.hs
Formation
2 declarationsType synonym for a type-preserving prism.
Introduction
1 declarationBuild a prism from a constructor and a matcher, which must respect the well-formedness laws.
If you want to build a Prism from the van Laarhoven representation, use
prismVL from the optics-vl package.
Elimination
0 declarationsA Prism is in particular an AffineFold, an AffineTraversal, a Review and a Setter, therefore you can specialise types to obtain:
preview :: Prism' s a -> s -> Maybe a
review :: Prism' s a -> a -> s
over :: Prism s t a b -> (a -> b) -> s -> t
set :: Prism s t a b -> b -> s -> t
matching :: Prism s t a b -> s -> Either t a
If you want to preview a type-modifying Prism that is insufficiently polymorphic to be used as a type-preserving Prism', use getting:
preview . getting :: Prism s t a b -> s -> Maybe a
Computation
0 declarationsWell-formedness
0 declarationsAdditional introduction forms
3 declarationsSee Data.Maybe.Optics and Data.Either.Optics for Prisms for the corresponding types, and _Cons, _Snoc and _Empty for Prisms for container types.
This Prism compares for exact equality with a given value.
only 4 # ()4
5 ^? only 4Nothing
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 Optics.Empty._Empty with the
Optics.Empty.AsEmpty list instance):
nearly [] null # ()[][1,2,3,4] ^? nearly [] nullNothing
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.
Additional elimination forms
1 declarationWork with a Prism as a constructor and a matcher.
Combinators
3 declarationsUse a Prism to work over part of a structure.
Lift a Prism through a Traversable functor, giving a Prism that matches only if all the elements of the container match the Prism.
Subtyping
1 declarationTag for a prism.
Instances38ReversibleOptic, Is, ArrowOptic, JoinKinds, ToReadOnly, MappingOptic, …
ReversibleOptic A_PrismDefined in optics-core-0.4.1.1 · Optics.ReIs A_Prism A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Prism A_ReviewDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Prism A_SetterDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Prism A_TraversalDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Prism An_AffineFoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Prism An_AffineTraversalDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs An_Iso A_PrismDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingArrowChoice arr => ArrowOptic A_Prism arrDefined in optics-core-0.4.1.1 · Optics.Arrowk ~ A_Fold => JoinKinds A_Fold A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Prism A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Prism => JoinKinds A_Prism A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Prism => JoinKinds A_Prism An_Iso kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Prism => JoinKinds An_Iso A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Review => JoinKinds A_Prism A_ReversedLens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Review => JoinKinds A_Prism A_Review kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Review => JoinKinds A_ReversedLens A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Review => JoinKinds A_Review A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Prism A_Setter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Setter A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Traversal => JoinKinds A_Prism A_Traversal kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Traversal => JoinKinds A_Traversal A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineFold => JoinKinds A_Getter A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineFold => JoinKinds A_Prism A_Getter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineFold => JoinKinds A_Prism A_ReversedPrism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineFold => JoinKinds A_Prism An_AffineFold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineFold => JoinKinds A_ReversedPrism A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineFold => JoinKinds An_AffineFold A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineTraversal => JoinKinds A_Lens A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineTraversal => JoinKinds A_Prism A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineTraversal => JoinKinds A_Prism An_AffineTraversal kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineTraversal => JoinKinds An_AffineTraversal A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingToReadOnly A_Prism s t a bDefined in optics-core-0.4.1.1 · Optics.ReadOnly(Functor f, f ~ g, s ~ t, a ~ b) => MappingOptic A_Prism f g s t a bDefined in optics-core-0.4.1.1 · Optics.Mapping(GConstructorImpl repDefined name s t a b, _name ~ AppendSymbolDefined in optics-core-0.4.1.1 · Optics.Label"_"
name) => GenericOptic repDefined _name A_Prism s t a btype MappedOptic A_Prism = A_ReviewDefined in optics-core-0.4.1.1 · Optics.Mappingtype ReversedOptic A_Prism = A_ReversedPrismDefined in optics-core-0.4.1.1 · Optics.Retype ReadOnlyOptic A_Prism = An_AffineFoldDefined in optics-core-0.4.1.1 · Optics.ReadOnly