-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Optics as an abstract interface: core definitions -- -- This package makes it possible to define and use Lenses, Traversals, -- Prisms and other optics, using an abstract interface. -- -- This variant provides core definitions with a minimal dependency -- footprint. See the optics package (and its -- dependencies) for documentation and the "batteries-included" variant. @package optics-core @version 0.3 -- | Classes for co- and contravariant bifunctors. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Bi -- | Class for (covariant) bifunctors. class Bifunctor p bimap :: Bifunctor p => (a -> b) -> (c -> d) -> p i a c -> p i b d first :: Bifunctor p => (a -> b) -> p i a c -> p i b c second :: Bifunctor p => (c -> d) -> p i a c -> p i a d -- | Class for contravariant bifunctors. class Bicontravariant p contrabimap :: Bicontravariant p => (b -> a) -> (d -> c) -> p i a c -> p i b d contrafirst :: Bicontravariant p => (b -> a) -> p i a c -> p i b c contrasecond :: Bicontravariant p => (c -> b) -> p i a b -> p i a c -- | If p is a Profunctor and a Bifunctor then its -- left parameter must be phantom. lphantom :: (Profunctor p, Bifunctor p) => p i a c -> p i b c -- | If p is a Profunctor and Bicontravariant then -- its right parameter must be phantom. rphantom :: (Profunctor p, Bicontravariant p) => p i c a -> p i c b instance Optics.Internal.Bi.Bicontravariant (Data.Profunctor.Indexed.Forget r) instance Optics.Internal.Bi.Bicontravariant (Data.Profunctor.Indexed.ForgetM r) instance Optics.Internal.Bi.Bicontravariant (Data.Profunctor.Indexed.IxForget r) instance Optics.Internal.Bi.Bicontravariant (Data.Profunctor.Indexed.IxForgetM r) instance Optics.Internal.Bi.Bifunctor Data.Profunctor.Indexed.Tagged -- | This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Optic.TypeLevel -- | A list of index types, used for indexed optics. type IxList = [Type] -- | An alias for an empty index-list type NoIx = ('[] :: IxList) -- | Singleton index list type WithIx i = ('[i] :: IxList) -- | Show a type surrounded by quote marks. type family QuoteType (x :: Type) :: ErrorMessage -- | Show a symbol surrounded by quote marks. type family QuoteSymbol (x :: Symbol) :: ErrorMessage type family ShowSymbolWithOrigin symbol origin :: ErrorMessage type family ShowSymbolsWithOrigin (fs :: [(Symbol, Symbol)]) :: ErrorMessage type family ShowOperators (ops :: [Symbol]) :: ErrorMessage type family AppendEliminations a b type family ShowEliminations forms :: ErrorMessage data RepDefined RepDefined :: RepDefined -- | This type family should be called with applications of Rep on -- both sides, and will reduce to RepDefined if at least one of -- them is defined; otherwise it is stuck. type family AnyHasRep (s :: Type -> Type) (t :: Type -> Type) :: RepDefined -- | Curry a type-level list. -- -- In pseudo (dependent-)Haskell: -- --
-- Curry xs y = foldr (->) y xs --type family Curry (xs :: IxList) (y :: Type) :: Type -- | Append two type-level lists together. type family Append (xs :: [k]) (ys :: [k]) :: [k] -- | Class that is inhabited by all type-level lists xs, providing -- the ability to compose a function under Curry xs. class CurryCompose xs -- | Compose a function under Curry xs. This generalises -- (.) (aka fmap for (->)) to work for -- curried functions with one argument for each type in the list. composeN :: CurryCompose xs => (i -> j) -> Curry xs i -> Curry xs j instance Optics.Internal.Optic.TypeLevel.CurryCompose '[] instance Optics.Internal.Optic.TypeLevel.CurryCompose xs => Optics.Internal.Optic.TypeLevel.CurryCompose (x : xs) -- | This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Optic.Types -- | Kind for types used as optic tags, such as A_Lens. type OpticKind = Type -- | Tag for an iso. data An_Iso :: OpticKind -- | Tag for a lens. data A_Lens :: OpticKind -- | Tag for a prism. data A_Prism :: OpticKind -- | Tag for an affine traversal. data An_AffineTraversal :: OpticKind -- | Tag for a traversal. data A_Traversal :: OpticKind -- | Tag for a setter. data A_Setter :: OpticKind -- | Tag for a reversed prism. data A_ReversedPrism :: OpticKind -- | Tag for a getter. data A_Getter :: OpticKind -- | Tag for an affine fold. data An_AffineFold :: OpticKind -- | Tag for a fold. data A_Fold :: OpticKind -- | Tag for a reversed lens. data A_ReversedLens :: OpticKind -- | Tag for a review. data A_Review :: OpticKind -- | Mapping tag types k to constraints on p. -- -- Using this type family we define the constraints that the various -- flavours of optics have to fulfill. type family Constraints (k :: OpticKind) (p :: Type -> Type -> Type -> Type) :: Constraint -- | Instances to implement the subtyping hierarchy between optics. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Optic.Subtyping -- | Subtyping relationship between kinds of optics. -- -- An instance of Is k l means that any Optic -- k can be used as an Optic l. For example, we have -- an Is A_Lens A_Traversal instance, but -- not Is A_Traversal A_Lens. -- -- This class needs instances for all possible combinations of tags. class Is k l -- | Witness of the subtyping relationship. implies :: Is k l => (Constraints k p => r) -> Constraints l p => r type family EliminationForms (k :: OpticKind) type AffineFoldEliminations = '('['("preview", "Optics.AffineFold")], '["(^?)"]) type AffineTraversalEliminations = AffineFoldEliminations `AppendEliminations` SetterEliminations type FoldEliminations = '('['("traverseOf_", "Optics.Fold"), '("foldMapOf", "Optics.Fold"), '("toListOf", "Optics.Fold")], '["(^..)"]) type GetterEliminations = '('['("view", "Optics.Getter")], '["(^.)"]) type IsoEliminations = GetterEliminations `AppendEliminations` ReviewEliminations `AppendEliminations` SetterEliminations type LensEliminations = GetterEliminations `AppendEliminations` SetterEliminations type PrismEliminations = AffineFoldEliminations `AppendEliminations` ReviewEliminations `AppendEliminations` SetterEliminations type ReviewEliminations = '('['("review", "Optics.Review")], '["(#)"]) type SetterEliminations = '('['("over", "Optics.Setter"), '("set", "Optics.Setter")], '["(%~)", "(.~)"]) type TraversalEliminations = '('['("traverseOf", "Optics.Traversal")], '[]) `AppendEliminations` FoldEliminations `AppendEliminations` SetterEliminations -- | Computes the least upper bound of two optics kinds. -- -- Join k l represents the least upper bound of an Optic -- k and an Optic l. This means in particular that -- composition of an Optic k and an Optic k will yield -- an Optic (Join k l). type family Join (k :: OpticKind) (l :: OpticKind) instance (TypeError ...) => Optics.Internal.Optic.Subtyping.Is k l instance Optics.Internal.Optic.Subtyping.Is k k instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.A_ReversedLens instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.A_ReversedPrism instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.A_Prism instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.A_Review instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.A_Lens instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.A_Getter instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.An_AffineTraversal instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.An_AffineFold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.A_Traversal instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.A_Fold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_Iso Optics.Internal.Optic.Types.A_Setter instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_ReversedLens Optics.Internal.Optic.Types.A_Review instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_ReversedPrism Optics.Internal.Optic.Types.A_Getter instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_ReversedPrism Optics.Internal.Optic.Types.An_AffineFold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_ReversedPrism Optics.Internal.Optic.Types.A_Fold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Prism Optics.Internal.Optic.Types.A_Review instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Prism Optics.Internal.Optic.Types.An_AffineTraversal instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Prism Optics.Internal.Optic.Types.An_AffineFold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Prism Optics.Internal.Optic.Types.A_Traversal instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Prism Optics.Internal.Optic.Types.A_Fold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Prism Optics.Internal.Optic.Types.A_Setter instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Lens Optics.Internal.Optic.Types.A_Getter instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Lens Optics.Internal.Optic.Types.An_AffineTraversal instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Lens Optics.Internal.Optic.Types.An_AffineFold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Lens Optics.Internal.Optic.Types.A_Traversal instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Lens Optics.Internal.Optic.Types.A_Fold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Lens Optics.Internal.Optic.Types.A_Setter instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Getter Optics.Internal.Optic.Types.An_AffineFold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Getter Optics.Internal.Optic.Types.A_Fold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_AffineTraversal Optics.Internal.Optic.Types.An_AffineFold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_AffineTraversal Optics.Internal.Optic.Types.A_Traversal instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_AffineTraversal Optics.Internal.Optic.Types.A_Fold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_AffineTraversal Optics.Internal.Optic.Types.A_Setter instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.An_AffineFold Optics.Internal.Optic.Types.A_Fold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Traversal Optics.Internal.Optic.Types.A_Fold instance Optics.Internal.Optic.Subtyping.Is Optics.Internal.Optic.Types.A_Traversal Optics.Internal.Optic.Types.A_Setter -- | Core optic types and subtyping machinery. -- -- This module contains the core Optic types, and the underlying -- machinery that we need in order to implement the subtyping between -- various different flavours of optics. -- -- The composition operator for optics is also defined here. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Optic -- | Wrapper newtype for the whole family of optics. -- -- The first parameter k identifies the particular optic kind -- (e.g. A_Lens or A_Traversal). -- -- The parameter is is a list of types available as indices. -- This will typically be NoIx for unindexed optics, or -- WithIx for optics with a single index. See the "Indexed optics" -- section of the overview documentation in the Optics module of -- the main optics package for more details. -- -- The parameters s and t represent the "big" -- structure, whereas a and b represent the "small" -- structure. newtype Optic (k :: OpticKind) (is :: IxList) s t a b Optic :: (forall p i. Profunctor p => Optic_ k p i (Curry is i) s t a b) -> Optic s t a b [getOptic] :: Optic s t a b -> forall p i. Profunctor p => Optic_ k p i (Curry is i) s t a b -- | Common special case of Optic where source and target types are -- equal. -- -- Here, we need only one "big" and one "small" type. For lenses, this -- means that in the restricted form we cannot do type-changing updates. type Optic' k is s a = Optic k is s s a a -- | Type representing the various kinds of optics. -- -- The tag parameter k is translated into constraints on -- p via the type family Constraints. type Optic_ k p i j s t a b = Constraints k p => Optic__ p i j s t a b -- | Optic internally as a profunctor transformation. type Optic__ p i j s t a b = p i a b -> p j s t -- | Explicit cast from one optic flavour to another. -- -- The resulting optic kind is given in the first type argument, so you -- can use TypeApplications to set it. For example -- --
-- castOptic @A_Lens o ---- -- turns o into a Lens. -- -- This is the identity function, modulo some constraint jiggery-pokery. castOptic :: forall destKind srcKind is s t a b. Is srcKind destKind => Optic srcKind is s t a b -> Optic destKind is s t a b -- | Compose two optics of compatible flavours. -- -- Returns an optic of the appropriate supertype. If either or both -- optics are indexed, the composition preserves all the indices. (%) :: (Is k m, Is l m, m ~ Join k l, ks ~ Append is js) => Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b infixl 9 % -- | Compose two optics of the same flavour. -- -- Normally you can simply use (%) instead, but this may be useful -- to help type inference if the type of one of the optics is otherwise -- under-constrained. (%%) :: forall k is js ks s t u v a b. ks ~ Append is js => Optic k is s t u v -> Optic k js u v a b -> Optic k ks s t a b infixl 9 %% -- | Flipped function application, specialised to optics and binding -- tightly. -- -- Useful for post-composing optics transformations: -- --
-- >>> toListOf (ifolded %& ifiltered (\i s -> length s <= i)) ["", "a","abc"] -- ["","a"] --(%&) :: Optic k is s t a b -> (Optic k is s t a b -> Optic l js s' t' a' b') -> Optic l js s' t' a' b' infixl 9 %& -- | Support for overloaded labels as optics. An overloaded label -- #foo can be used as an optic if there is an instance of -- LabelOptic "foo" k s t a b. -- -- See Optics.Label for examples and further details. class LabelOptic (name :: Symbol) k s t a b | name s -> k a, name t -> k b, name s b -> t, name t a -> s -- | Used to interpret overloaded label syntax. An overloaded label -- #foo corresponds to labelOptic @"foo". labelOptic :: LabelOptic name k s t a b => Optic k NoIx s t a b -- | Type synonym for a type-preserving optic as overloaded label. type LabelOptic' name k s a = LabelOptic name k s s a a -- | Implements fallback behaviour in case there is no explicit -- LabelOptic instance. This has a catch-all incoherent instance -- that merely yields an error message. However, a downstream module can -- give a more specific instance that uses Generic to construct -- an optic automatically. -- -- To support this, the last parameter will be instantiated to -- RepDefined if at least one of s or t has a -- Generic instance. class GeneralLabelOptic (name :: Symbol) k s t a b (repDefined :: RepDefined) -- | Used to interpret overloaded label syntax in the absence of an -- explicit LabelOptic instance. generalLabelOptic :: GeneralLabelOptic name k s t a b repDefined => Optic k NoIx s t a b instance (k Data.Type.Equality.~ Optics.Internal.Optic.Types.An_Iso, a Data.Type.Equality.~ Optics.Internal.Optic.Void0, b Data.Type.Equality.~ Optics.Internal.Optic.Void0) => Optics.Internal.Optic.LabelOptic name k Optics.Internal.Optic.Void0 Optics.Internal.Optic.Void0 a b instance (Optics.Internal.Optic.LabelOptic name k s t a b, Optics.Internal.Optic.GeneralLabelOptic name k s t a b (Optics.Internal.Optic.TypeLevel.AnyHasRep (GHC.Generics.Rep s) (GHC.Generics.Rep t))) => Optics.Internal.Optic.LabelOptic name k s t a b instance (TypeError ...) => Optics.Internal.Optic.GeneralLabelOptic name k s t a b repDefined instance (Optics.Internal.Optic.LabelOptic name k s t a b, is Data.Type.Equality.~ Optics.Internal.Optic.TypeLevel.NoIx) => GHC.OverloadedLabels.IsLabel name (Optics.Internal.Optic.Optic k is s t a b) instance (ys Data.Type.Equality.~ zs) => Optics.Internal.Optic.AppendProof '[] ys zs instance (Optics.Internal.Optic.TypeLevel.Append (x : xs) ys Data.Type.Equality.~ (x : zs), Optics.Internal.Optic.AppendProof xs ys zs) => Optics.Internal.Optic.AppendProof (x : xs) ys (x : zs) -- | Internal implementation details of indexed optics. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Indexed -- | Show useful error message when a function expects optics without -- indices. class is ~ NoIx => AcceptsEmptyIndices (f :: Symbol) (is :: IxList) -- | Check whether a list of indices is not empty and generate sensible -- error message if it's not. class NonEmptyIndices (is :: IxList) -- | Generate sensible error messages in case a user tries to pass either -- an unindexed optic or indexed optic with unflattened indices where -- indexed optic with a single index is expected. class is ~ '[i] => HasSingleIndex (is :: IxList) (i :: Type) type family ShowTypes (types :: [Type]) :: ErrorMessage data IntT f a IntT :: {-# UNPACK #-} !Int -> f a -> IntT f a unIntT :: IntT f a -> f a newtype Indexing f a Indexing :: (Int -> IntT f a) -> Indexing f a [runIndexing] :: Indexing f a -> Int -> IntT f a -- | Index a traversal by position of visited elements. indexing :: ((a -> Indexing f b) -> s -> Indexing f t) -> (Int -> a -> f b) -> s -> f t -- | Construct a conjoined indexed optic that provides a separate code path -- when used without indices. Useful for defining indexed optics that are -- as efficient as their unindexed equivalents when used without indices. -- -- Note: conjoined f g is well-defined if and only -- if f ≡ noIx g. conjoined :: is `HasSingleIndex` i => Optic k NoIx s t a b -> Optic k is s t a b -> Optic k is s t a b instance GHC.Base.Functor f => GHC.Base.Functor (Optics.Internal.Indexed.Indexing f) instance GHC.Base.Applicative f => GHC.Base.Applicative (Optics.Internal.Indexed.Indexing f) instance ((TypeError ...), is Data.Type.Equality.~ '[i1, i2], is Data.Type.Equality.~ '[i]) => Optics.Internal.Indexed.HasSingleIndex '[i1, i2] i instance ((TypeError ...), is Data.Type.Equality.~ '[i1, i2, i3], is Data.Type.Equality.~ '[i]) => Optics.Internal.Indexed.HasSingleIndex '[i1, i2, i3] i instance ((TypeError ...), is Data.Type.Equality.~ '[i1, i2, i3, i4], is Data.Type.Equality.~ '[i]) => Optics.Internal.Indexed.HasSingleIndex '[i1, i2, i3, i4] i instance ((TypeError ...), is Data.Type.Equality.~ '[i1, i2, i3, i4, i5], is Data.Type.Equality.~ '[i]) => Optics.Internal.Indexed.HasSingleIndex '[i1, i2, i3, i4, i5] i instance ((TypeError ...), is Data.Type.Equality.~ (i1 : i2 : i3 : i4 : i5 : i6 : is'), is Data.Type.Equality.~ '[i]) => Optics.Internal.Indexed.HasSingleIndex (i1 : i2 : i3 : i4 : i5 : i6 : is') i instance Optics.Internal.Indexed.HasSingleIndex '[i] i instance ((TypeError ...), '[] Data.Type.Equality.~ '[i]) => Optics.Internal.Indexed.HasSingleIndex '[] i instance (TypeError ...) => Optics.Internal.Indexed.NonEmptyIndices '[] instance Optics.Internal.Indexed.NonEmptyIndices (x : xs) instance ((TypeError ...), (x : xs) Data.Type.Equality.~ Optics.Internal.Optic.TypeLevel.NoIx) => Optics.Internal.Indexed.AcceptsEmptyIndices f (x : xs) instance Optics.Internal.Indexed.AcceptsEmptyIndices f '[] -- | Internal implementation details of folds. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Fold -- | Internal implementation of foldVL. foldVL__ :: (Bicontravariant p, Traversing p) => (forall f. Applicative f => (a -> f u) -> s -> f v) -> Optic__ p i i s t a b -- | Internal implementation of folded. folded__ :: (Bicontravariant p, Traversing p, Foldable f) => Optic__ p i i (f a) (f b) a b -- | Internal implementation of foldring. foldring__ :: (Bicontravariant p, Traversing p) => (forall f. Applicative f => (a -> f u -> f u) -> f v -> s -> f w) -> Optic__ p i i s t a b -- | Used for headOf and iheadOf. data Leftmost a LPure :: Leftmost a LLeaf :: a -> Leftmost a LStep :: Leftmost a -> Leftmost a -- | Extract the Leftmost element. This will fairly eagerly -- determine that it can return Just the moment it sees any -- element at all. getLeftmost :: Leftmost a -> Maybe a -- | Used for lastOf and ilastOf. data Rightmost a RPure :: Rightmost a RLeaf :: a -> Rightmost a RStep :: Rightmost a -> Rightmost a -- | Extract the Rightmost element. This will fairly eagerly -- determine that it can return Just the moment it sees any -- element at all. getRightmost :: Rightmost a -> Maybe a instance GHC.Base.Semigroup (Optics.Internal.Fold.Rightmost a) instance GHC.Base.Monoid (Optics.Internal.Fold.Rightmost a) instance GHC.Base.Semigroup (Optics.Internal.Fold.Leftmost a) instance GHC.Base.Monoid (Optics.Internal.Fold.Leftmost a) -- | A Getter is simply a function considered as an Optic. -- -- Given a function f :: S -> A, we can convert it into a -- Getter S A using to, and convert back to a -- function using view. -- -- This is typically useful not when you have functions/Getters -- alone, but when you are composing multiple Optics to produce a -- Getter. module Optics.Getter -- | Type synonym for a getter. type Getter s a = Optic' A_Getter NoIx s a -- | Build a getter from a function. to :: (s -> a) -> Getter s a -- | View the value pointed to by a getter. -- -- If you want to view a type-modifying optic that is -- insufficiently polymorphic to be type-preserving, use getting. view :: Is k A_Getter => Optic' k is s a -> s -> a -- | View the function of the value pointed to by a getter. views :: Is k A_Getter => Optic' k is s a -> (a -> r) -> s -> r -- | Tag for a getter. data A_Getter :: OpticKind -- | This module defines operations to coerce the type parameters of -- optics to a representationally equal type. For example, if we have -- --
-- newtype MkInt = MkInt Int ---- -- and -- --
-- l :: Lens' S Int ---- -- then -- --
-- coerceA @Int @MkInt l :: Lens' S MkInt --module Optics.Coerce -- | Lift coerce to the s parameter of an optic. coerceS :: Coercible s s' => Optic k is s t a b -> Optic k is s' t a b -- | Lift coerce to the t parameter of an optic. coerceT :: Coercible t t' => Optic k is s t a b -> Optic k is s t' a b -- | Lift coerce to the a parameter of an optic. coerceA :: Coercible a a' => Optic k is s t a b -> Optic k is s t a' b -- | Lift coerce to the b parameter of an optic. coerceB :: Coercible b b' => Optic k is s t a b -> Optic k is s t a b' -- | An AffineTraversal is a Traversal that applies to at -- most one element. -- -- These arise most frequently as the composition of a Lens with a -- Prism. module Optics.AffineTraversal -- | Type synonym for a type-modifying affine traversal. type AffineTraversal s t a b = Optic An_AffineTraversal NoIx s t a b -- | Type synonym for a type-preserving affine traversal. type AffineTraversal' s a = Optic' An_AffineTraversal NoIx s a -- | Build an affine traversal from a matcher and an updater. -- -- If you want to build an AffineTraversal from the van Laarhoven -- representation, use atraversalVL. atraversal :: (s -> Either t a) -> (s -> b -> t) -> AffineTraversal s t a b -- | Retrieve the value targeted by an AffineTraversal or return the -- original value while allowing the type to change if it does not match. -- --
-- preview o ≡ either (const Nothing) id . matching o --matching :: Is k An_AffineTraversal => Optic k is s t a b -> s -> Either t a -- | Filter result(s) of a traversal that don't satisfy a predicate. -- -- Note: This is not a legal Traversal, unless you -- are very careful not to invalidate the predicate on the target. -- -- As a counter example, consider that given evens = -- unsafeFiltered even the second Traversal law -- is violated: -- --
-- over evens succ . over evens succ /= over evens (succ . succ) ---- -- So, in order for this to qualify as a legal Traversal you can -- only use it for actions that preserve the result of the predicate! -- -- For a safe variant see indices (or filtered for -- read-only optics). unsafeFiltered :: (a -> Bool) -> AffineTraversal' a a -- | Work with an affine traversal as a matcher and an updater. withAffineTraversal :: Is k An_AffineTraversal => Optic k is s t a b -> ((s -> Either t a) -> (s -> b -> t) -> r) -> r -- | Tag for an affine traversal. data An_AffineTraversal :: OpticKind -- | Type synonym for a type-modifying van Laarhoven affine traversal. -- -- Note: this isn't exactly van Laarhoven representation as there is no -- Pointed class (which would be a superclass of -- Applicative that contains pure but not -- <*>). You can interpret the first argument as a -- dictionary of Pointed that supplies the point -- function (i.e. the implementation of pure). -- -- A TraversalVL has Applicative available and hence can -- combine the effects arising from multiple elements using -- <*>. In contrast, an AffineTraversalVL has no way -- to combine effects from multiple elements, so it must act on at most -- one element. (It can act on none at all thanks to the availability of -- point.) type AffineTraversalVL s t a b = forall f. Functor f => (forall r. r -> f r) -> (a -> f b) -> s -> f t -- | Type synonym for a type-preserving van Laarhoven affine traversal. type AffineTraversalVL' s a = AffineTraversalVL s s a a -- | Build an affine traversal from the van Laarhoven representation. -- -- Example: -- --
-- >>> :{
-- azSnd = atraversalVL $ \point f ab@(a, b) ->
-- if a >= 'a' && a <= 'z'
-- then (a, ) <$> f b
-- else point ab
-- :}
--
--
--
-- >>> preview azSnd ('a', "Hi")
-- Just "Hi"
--
--
--
-- >>> preview azSnd ('@', "Hi")
-- Nothing
--
--
--
-- >>> over azSnd (++ "!!!") ('f', "Hi")
-- ('f',"Hi!!!")
--
--
--
-- >>> set azSnd "Bye" ('Y', "Hi")
-- ('Y',"Hi")
--
atraversalVL :: AffineTraversalVL s t a b -> AffineTraversal s t a b
-- | Traverse over the target of an AffineTraversal and compute a
-- Functor-based answer.
atraverseOf :: (Is k An_AffineTraversal, Functor f) => Optic k is s t a b -> (forall r. r -> f r) -> (a -> f b) -> s -> f t
module Data.Typeable.Optics
-- | An AffineTraversal' for working with a cast of a
-- Typeable value.
_cast :: (Typeable s, Typeable a) => AffineTraversal' s a
-- | An AffineTraversal' for working with a gcast of a
-- Typeable value.
_gcast :: (Typeable s, Typeable a) => AffineTraversal' (c s) (c a)
-- | An AffineFold is a Fold that contains at most one
-- element, or a Getter where the function may be partial.
module Optics.AffineFold
-- | Type synonym for an affine fold.
type AffineFold s a = Optic' An_AffineFold NoIx s a
-- | Create an AffineFold from a partial function.
--
-- -- >>> preview (afolding listToMaybe) "foo" -- Just 'f' --afolding :: (s -> Maybe a) -> AffineFold s a -- | Retrieve the value targeted by an AffineFold. -- --
-- >>> let _Right = prism Right $ either (Left . Left) Right ---- --
-- >>> preview _Right (Right 'x') -- Just 'x' ---- --
-- >>> preview _Right (Left 'y') -- Nothing --preview :: Is k An_AffineFold => Optic' k is s a -> s -> Maybe a -- | Retrieve a function of the value targeted by an AffineFold. previews :: Is k An_AffineFold => Optic' k is s a -> (a -> r) -> s -> Maybe r -- | Obtain an AffineFold by lifting traverse_ like -- function. -- --
-- afoldVL . atraverseOf_ ≡ id -- atraverseOf_ . afoldVL ≡ id --afoldVL :: (forall f. Functor f => (forall r. r -> f r) -> (a -> f u) -> s -> f v) -> AffineFold s a -- | Filter result(s) of a fold that don't satisfy a predicate. filtered :: (a -> Bool) -> AffineFold a a -- | Traverse over the target of an AffineFold, computing a -- Functor-based answer, but unlike atraverseOf do not -- construct a new structure. atraverseOf_ :: (Is k An_AffineFold, Functor f) => Optic' k is s a -> (forall r. r -> f r) -> (a -> f u) -> s -> f () -- | Check to see if this AffineFold doesn't match. -- --
-- >>> isn't _Just Nothing -- True --isn't :: Is k An_AffineFold => Optic' k is s a -> s -> Bool -- | Try the first AffineFold. If it returns no entry, try the -- second one. -- --
-- >>> preview (ix 1 % re _Left `afailing` ix 2 % re _Right) [0,1,2,3] -- Just (Left 1) ---- --
-- >>> preview (ix 42 % re _Left `afailing` ix 2 % re _Right) [0,1,2,3] -- Just (Right 2) --afailing :: (Is k An_AffineFold, Is l An_AffineFold) => Optic' k is s a -> Optic' l js s a -> AffineFold s a infixl 3 `afailing` -- | Tag for an affine fold. data An_AffineFold :: OpticKind -- | Internal implementation details of setters. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Setter -- | Internal implementation of mapped. mapped__ :: (Mapping p, Functor f) => Optic__ p i i (f a) (f b) a b -- | Internal implementation details of traversals. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Traversal -- | Internal implementation of traversed. traversed__ :: (Traversing p, Traversable f) => Optic__ p i i (f a) (f b) a b -- | This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Utils data Identity' a Identity' :: {-# UNPACK #-} !() -> a -> Identity' a -- | Mark a value for evaluation to whnf. -- -- This allows us to, when applying a setter to a structure, evaluate -- only the parts that we modify. If an optic focuses on multiple -- targets, Applicative instance of Identity' makes sure that we force -- evaluation of all of them, but we leave anything else alone. wrapIdentity' :: a -> Identity' a unwrapIdentity' :: Identity' a -> a -- | Helper for traverseOf_ and the like for better efficiency than -- the foldr-based version. -- -- Note that the argument a of the result should not be used. newtype Traversed f a Traversed :: f a -> Traversed f a runTraversed :: Functor f => Traversed f a -> f () -- | Helper for failing family to visit the first fold only once. data OrT f a OrT :: !Bool -> f a -> OrT f a -- | Wrap the applicative action in OrT so that we know later that -- it was executed. wrapOrT :: f a -> OrT f a -- | Composition operator where the first argument must be an identity -- function up to representational equivalence (e.g. a newtype wrapper or -- unwrapper), and will be ignored at runtime. (#.) :: Coercible b c => (b -> c) -> (a -> b) -> a -> c infixr 9 #. -- | Composition operator where the second argument must be an identity -- function up to representational equivalence (e.g. a newtype wrapper or -- unwrapper), and will be ignored at runtime. (.#) :: Coercible a b => (b -> c) -> (a -> b) -> a -> c infixl 8 .# -- | uncurry with no lazy pattern matching for more efficient code. uncurry' :: (a -> b -> c) -> (a, b) -> c instance GHC.Base.Functor f => GHC.Base.Functor (Optics.Internal.Utils.OrT f) instance GHC.Base.Functor Optics.Internal.Utils.Identity' instance GHC.Base.Applicative f => GHC.Base.Applicative (Optics.Internal.Utils.OrT f) instance GHC.Base.Applicative f => GHC.Base.Semigroup (Optics.Internal.Utils.Traversed f a) instance GHC.Base.Applicative f => GHC.Base.Monoid (Optics.Internal.Utils.Traversed f a) instance GHC.Base.Applicative Optics.Internal.Utils.Identity' instance Data.Profunctor.Indexed.Mapping (Data.Profunctor.Indexed.Star Optics.Internal.Utils.Identity') instance Data.Profunctor.Indexed.Mapping (Data.Profunctor.Indexed.IxStar Optics.Internal.Utils.Identity') -- | Internal implementation details of indexed optics. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.Indexed.Classes -- | Class for Functors that have an additional read-only index -- available. class Functor f => FunctorWithIndex i f | f -> i imap :: FunctorWithIndex i f => (i -> a -> b) -> f a -> f b imap :: (FunctorWithIndex i f, TraversableWithIndex i f) => (i -> a -> b) -> f a -> f b -- | Class for Foldables that have an additional read-only index -- available. class (FunctorWithIndex i f, Foldable f) => FoldableWithIndex i f | f -> i ifoldMap :: (FoldableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m ifoldMap :: (FoldableWithIndex i f, TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m ifoldr :: FoldableWithIndex i f => (i -> a -> b -> b) -> b -> f a -> b ifoldl' :: FoldableWithIndex i f => (i -> b -> a -> b) -> b -> f a -> b -- | Traverse FoldableWithIndex ignoring the results. itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f () -- | Flipped itraverse_. ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f () -- | List of elements of a structure with an index, from left to right. itoList :: FoldableWithIndex i f => f a -> [(i, a)] -- | Class for Traversables that have an additional read-only index -- available. class (FoldableWithIndex i t, Traversable t) => TraversableWithIndex i t | t -> i itraverse :: (TraversableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f (t b) -- | Flipped itraverse ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b) instance Optics.Internal.Indexed.Classes.FunctorWithIndex () Data.Functor.Identity.Identity instance Optics.Internal.Indexed.Classes.FoldableWithIndex () Data.Functor.Identity.Identity instance Optics.Internal.Indexed.Classes.TraversableWithIndex () Data.Functor.Identity.Identity instance Optics.Internal.Indexed.Classes.FunctorWithIndex Data.Void.Void (Data.Functor.Const.Const e) instance Optics.Internal.Indexed.Classes.FoldableWithIndex Data.Void.Void (Data.Functor.Const.Const e) instance Optics.Internal.Indexed.Classes.TraversableWithIndex Data.Void.Void (Data.Functor.Const.Const e) instance Optics.Internal.Indexed.Classes.FunctorWithIndex Data.Void.Void (Data.Functor.Constant.Constant e) instance Optics.Internal.Indexed.Classes.FoldableWithIndex Data.Void.Void (Data.Functor.Constant.Constant e) instance Optics.Internal.Indexed.Classes.TraversableWithIndex Data.Void.Void (Data.Functor.Constant.Constant e) instance Optics.Internal.Indexed.Classes.FunctorWithIndex k ((,) k) instance Optics.Internal.Indexed.Classes.FoldableWithIndex k ((,) k) instance Optics.Internal.Indexed.Classes.TraversableWithIndex k ((,) k) instance Optics.Internal.Indexed.Classes.FunctorWithIndex r ((->) r) instance Optics.Internal.Indexed.Classes.FunctorWithIndex GHC.Types.Int [] instance Optics.Internal.Indexed.Classes.FoldableWithIndex GHC.Types.Int [] instance Optics.Internal.Indexed.Classes.TraversableWithIndex GHC.Types.Int [] instance Optics.Internal.Indexed.Classes.FunctorWithIndex GHC.Types.Int Control.Applicative.ZipList instance Optics.Internal.Indexed.Classes.FoldableWithIndex GHC.Types.Int Control.Applicative.ZipList instance Optics.Internal.Indexed.Classes.TraversableWithIndex GHC.Types.Int Control.Applicative.ZipList instance Optics.Internal.Indexed.Classes.FunctorWithIndex GHC.Types.Int GHC.Base.NonEmpty instance Optics.Internal.Indexed.Classes.FoldableWithIndex GHC.Types.Int GHC.Base.NonEmpty instance Optics.Internal.Indexed.Classes.TraversableWithIndex GHC.Types.Int GHC.Base.NonEmpty instance Optics.Internal.Indexed.Classes.FunctorWithIndex () GHC.Maybe.Maybe instance Optics.Internal.Indexed.Classes.FoldableWithIndex () GHC.Maybe.Maybe instance Optics.Internal.Indexed.Classes.TraversableWithIndex () GHC.Maybe.Maybe instance Optics.Internal.Indexed.Classes.FunctorWithIndex GHC.Types.Int Data.Sequence.Internal.Seq instance Optics.Internal.Indexed.Classes.FoldableWithIndex GHC.Types.Int Data.Sequence.Internal.Seq instance Optics.Internal.Indexed.Classes.TraversableWithIndex GHC.Types.Int Data.Sequence.Internal.Seq instance Optics.Internal.Indexed.Classes.FunctorWithIndex GHC.Types.Int Data.IntMap.Internal.IntMap instance Optics.Internal.Indexed.Classes.FoldableWithIndex GHC.Types.Int Data.IntMap.Internal.IntMap instance Optics.Internal.Indexed.Classes.TraversableWithIndex GHC.Types.Int Data.IntMap.Internal.IntMap instance Optics.Internal.Indexed.Classes.FunctorWithIndex k (Data.Map.Internal.Map k) instance Optics.Internal.Indexed.Classes.FoldableWithIndex k (Data.Map.Internal.Map k) instance Optics.Internal.Indexed.Classes.TraversableWithIndex k (Data.Map.Internal.Map k) instance GHC.Arr.Ix i => Optics.Internal.Indexed.Classes.FunctorWithIndex i (GHC.Arr.Array i) instance GHC.Arr.Ix i => Optics.Internal.Indexed.Classes.FoldableWithIndex i (GHC.Arr.Array i) instance GHC.Arr.Ix i => Optics.Internal.Indexed.Classes.TraversableWithIndex i (GHC.Arr.Array i) instance (Optics.Internal.Indexed.Classes.FunctorWithIndex i f, Optics.Internal.Indexed.Classes.FunctorWithIndex j g) => Optics.Internal.Indexed.Classes.FunctorWithIndex (i, j) (Data.Functor.Compose.Compose f g) instance (Optics.Internal.Indexed.Classes.FoldableWithIndex i f, Optics.Internal.Indexed.Classes.FoldableWithIndex j g) => Optics.Internal.Indexed.Classes.FoldableWithIndex (i, j) (Data.Functor.Compose.Compose f g) instance (Optics.Internal.Indexed.Classes.TraversableWithIndex i f, Optics.Internal.Indexed.Classes.TraversableWithIndex j g) => Optics.Internal.Indexed.Classes.TraversableWithIndex (i, j) (Data.Functor.Compose.Compose f g) instance (Optics.Internal.Indexed.Classes.FunctorWithIndex i f, Optics.Internal.Indexed.Classes.FunctorWithIndex j g) => Optics.Internal.Indexed.Classes.FunctorWithIndex (Data.Either.Either i j) (Data.Functor.Sum.Sum f g) instance (Optics.Internal.Indexed.Classes.FoldableWithIndex i f, Optics.Internal.Indexed.Classes.FoldableWithIndex j g) => Optics.Internal.Indexed.Classes.FoldableWithIndex (Data.Either.Either i j) (Data.Functor.Sum.Sum f g) instance (Optics.Internal.Indexed.Classes.TraversableWithIndex i f, Optics.Internal.Indexed.Classes.TraversableWithIndex j g) => Optics.Internal.Indexed.Classes.TraversableWithIndex (Data.Either.Either i j) (Data.Functor.Sum.Sum f g) instance (Optics.Internal.Indexed.Classes.FunctorWithIndex i f, Optics.Internal.Indexed.Classes.FunctorWithIndex j g) => Optics.Internal.Indexed.Classes.FunctorWithIndex (Data.Either.Either i j) (Data.Functor.Product.Product f g) instance (Optics.Internal.Indexed.Classes.FoldableWithIndex i f, Optics.Internal.Indexed.Classes.FoldableWithIndex j g) => Optics.Internal.Indexed.Classes.FoldableWithIndex (Data.Either.Either i j) (Data.Functor.Product.Product f g) instance (Optics.Internal.Indexed.Classes.TraversableWithIndex i f, Optics.Internal.Indexed.Classes.TraversableWithIndex j g) => Optics.Internal.Indexed.Classes.TraversableWithIndex (Data.Either.Either i j) (Data.Functor.Product.Product f g) instance Optics.Internal.Indexed.Classes.FunctorWithIndex [GHC.Types.Int] Data.Tree.Tree instance Optics.Internal.Indexed.Classes.FoldableWithIndex [GHC.Types.Int] Data.Tree.Tree instance Optics.Internal.Indexed.Classes.TraversableWithIndex [GHC.Types.Int] Data.Tree.Tree instance Optics.Internal.Indexed.Classes.FunctorWithIndex Data.Void.Void Data.Proxy.Proxy instance Optics.Internal.Indexed.Classes.FoldableWithIndex Data.Void.Void Data.Proxy.Proxy instance Optics.Internal.Indexed.Classes.TraversableWithIndex Data.Void.Void Data.Proxy.Proxy instance Optics.Internal.Indexed.Classes.FunctorWithIndex i f => Optics.Internal.Indexed.Classes.FunctorWithIndex i (Control.Applicative.Backwards.Backwards f) instance Optics.Internal.Indexed.Classes.FoldableWithIndex i f => Optics.Internal.Indexed.Classes.FoldableWithIndex i (Control.Applicative.Backwards.Backwards f) instance Optics.Internal.Indexed.Classes.TraversableWithIndex i f => Optics.Internal.Indexed.Classes.TraversableWithIndex i (Control.Applicative.Backwards.Backwards f) instance Optics.Internal.Indexed.Classes.FunctorWithIndex i f => Optics.Internal.Indexed.Classes.FunctorWithIndex i (Data.Functor.Reverse.Reverse f) instance Optics.Internal.Indexed.Classes.FoldableWithIndex i f => Optics.Internal.Indexed.Classes.FoldableWithIndex i (Data.Functor.Reverse.Reverse f) instance Optics.Internal.Indexed.Classes.TraversableWithIndex i f => Optics.Internal.Indexed.Classes.TraversableWithIndex i (Data.Functor.Reverse.Reverse f) instance Optics.Internal.Indexed.Classes.FunctorWithIndex i m => Optics.Internal.Indexed.Classes.FunctorWithIndex i (Control.Monad.Trans.Identity.IdentityT m) instance Optics.Internal.Indexed.Classes.FoldableWithIndex i m => Optics.Internal.Indexed.Classes.FoldableWithIndex i (Control.Monad.Trans.Identity.IdentityT m) instance Optics.Internal.Indexed.Classes.TraversableWithIndex i m => Optics.Internal.Indexed.Classes.TraversableWithIndex i (Control.Monad.Trans.Identity.IdentityT m) instance Optics.Internal.Indexed.Classes.FunctorWithIndex i m => Optics.Internal.Indexed.Classes.FunctorWithIndex (e, i) (Control.Monad.Trans.Reader.ReaderT e m) instance Optics.Internal.Indexed.Classes.FunctorWithIndex Data.Void.Void GHC.Generics.V1 instance Optics.Internal.Indexed.Classes.FoldableWithIndex Data.Void.Void GHC.Generics.V1 instance Optics.Internal.Indexed.Classes.TraversableWithIndex Data.Void.Void GHC.Generics.V1 instance Optics.Internal.Indexed.Classes.FunctorWithIndex Data.Void.Void GHC.Generics.U1 instance Optics.Internal.Indexed.Classes.FoldableWithIndex Data.Void.Void GHC.Generics.U1 instance Optics.Internal.Indexed.Classes.TraversableWithIndex Data.Void.Void GHC.Generics.U1 instance Optics.Internal.Indexed.Classes.FunctorWithIndex () GHC.Generics.Par1 instance Optics.Internal.Indexed.Classes.FoldableWithIndex () GHC.Generics.Par1 instance Optics.Internal.Indexed.Classes.TraversableWithIndex () GHC.Generics.Par1 instance (Optics.Internal.Indexed.Classes.FunctorWithIndex i f, Optics.Internal.Indexed.Classes.FunctorWithIndex j g) => Optics.Internal.Indexed.Classes.FunctorWithIndex (i, j) (f GHC.Generics.:.: g) instance (Optics.Internal.Indexed.Classes.FoldableWithIndex i f, Optics.Internal.Indexed.Classes.FoldableWithIndex j g) => Optics.Internal.Indexed.Classes.FoldableWithIndex (i, j) (f GHC.Generics.:.: g) instance (Optics.Internal.Indexed.Classes.TraversableWithIndex i f, Optics.Internal.Indexed.Classes.TraversableWithIndex j g) => Optics.Internal.Indexed.Classes.TraversableWithIndex (i, j) (f GHC.Generics.:.: g) instance (Optics.Internal.Indexed.Classes.FunctorWithIndex i f, Optics.Internal.Indexed.Classes.FunctorWithIndex j g) => Optics.Internal.Indexed.Classes.FunctorWithIndex (Data.Either.Either i j) (f GHC.Generics.:*: g) instance (Optics.Internal.Indexed.Classes.FoldableWithIndex i f, Optics.Internal.Indexed.Classes.FoldableWithIndex j g) => Optics.Internal.Indexed.Classes.FoldableWithIndex (Data.Either.Either i j) (f GHC.Generics.:*: g) instance (Optics.Internal.Indexed.Classes.TraversableWithIndex i f, Optics.Internal.Indexed.Classes.TraversableWithIndex j g) => Optics.Internal.Indexed.Classes.TraversableWithIndex (Data.Either.Either i j) (f GHC.Generics.:*: g) instance (Optics.Internal.Indexed.Classes.FunctorWithIndex i f, Optics.Internal.Indexed.Classes.FunctorWithIndex j g) => Optics.Internal.Indexed.Classes.FunctorWithIndex (Data.Either.Either i j) (f GHC.Generics.:+: g) instance (Optics.Internal.Indexed.Classes.FoldableWithIndex i f, Optics.Internal.Indexed.Classes.FoldableWithIndex j g) => Optics.Internal.Indexed.Classes.FoldableWithIndex (Data.Either.Either i j) (f GHC.Generics.:+: g) instance (Optics.Internal.Indexed.Classes.TraversableWithIndex i f, Optics.Internal.Indexed.Classes.TraversableWithIndex j g) => Optics.Internal.Indexed.Classes.TraversableWithIndex (Data.Either.Either i j) (f GHC.Generics.:+: g) instance Optics.Internal.Indexed.Classes.FunctorWithIndex i f => Optics.Internal.Indexed.Classes.FunctorWithIndex i (GHC.Generics.Rec1 f) instance Optics.Internal.Indexed.Classes.FoldableWithIndex i f => Optics.Internal.Indexed.Classes.FoldableWithIndex i (GHC.Generics.Rec1 f) instance Optics.Internal.Indexed.Classes.TraversableWithIndex i f => Optics.Internal.Indexed.Classes.TraversableWithIndex i (GHC.Generics.Rec1 f) instance Optics.Internal.Indexed.Classes.FunctorWithIndex Data.Void.Void (GHC.Generics.K1 i c) instance Optics.Internal.Indexed.Classes.FoldableWithIndex Data.Void.Void (GHC.Generics.K1 i c) instance Optics.Internal.Indexed.Classes.TraversableWithIndex Data.Void.Void (GHC.Generics.K1 i c) -- | Internal implementation details of indexed setters. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.IxSetter -- | Internal implementation of imapped. imapped__ :: (Mapping p, FunctorWithIndex i f) => Optic__ p j (i -> j) (f a) (f b) a b -- | Internal implementation details of indexed folds. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.IxFold -- | Internal implementation of ifoldVL. ifoldVL__ :: (Bicontravariant p, Traversing p) => (forall f. Applicative f => (i -> a -> f u) -> s -> f v) -> Optic__ p j (i -> j) s t a b -- | Internal implementation of ifolded. ifolded__ :: (Bicontravariant p, Traversing p, FoldableWithIndex i f) => Optic__ p j (i -> j) (f a) t a b -- | Internal implementation of ifoldring. ifoldring__ :: (Bicontravariant p, Traversing p) => (forall f. Applicative f => (i -> a -> f u -> f u) -> f v -> s -> f w) -> Optic__ p j (i -> j) s t a b -- | Internal implementation details of indexed traversals. -- -- This module is intended for internal use only, and may change without -- warning in subsequent releases. module Optics.Internal.IxTraversal -- | Internal implementation of itraversed. itraversed__ :: (Traversing p, TraversableWithIndex i f) => Optic__ p j (i -> j) (f a) (f b) a b -- | A Fold S A has the ability to extract some number of -- elements of type A from a container of type S. For -- example, toListOf can be used to obtain the contained elements -- as a list. Unlike a Traversal, there is no way to set or update -- elements. -- -- This can be seen as a generalisation of traverse_, where the -- type S does not need to be a type constructor with A -- as the last parameter. -- -- A close relative is the AffineFold, which is a Fold that -- contains at most one element. module Optics.Fold -- | Type synonym for a fold. type Fold s a = Optic' A_Fold NoIx s a -- | Obtain a Fold by lifting traverse_ like function. -- --
-- foldVL . traverseOf_ ≡ id -- traverseOf_ . foldVL ≡ id --foldVL :: (forall f. Applicative f => (a -> f u) -> s -> f v) -> Fold s a -- | Combine the results of a fold using a monoid. foldOf :: (Is k A_Fold, Monoid a) => Optic' k is s a -> s -> a -- | Fold via embedding into a monoid. foldMapOf :: (Is k A_Fold, Monoid m) => Optic' k is s a -> (a -> m) -> s -> m -- | Fold right-associatively. foldrOf :: Is k A_Fold => Optic' k is s a -> (a -> r -> r) -> r -> s -> r -- | Fold left-associatively, and strictly. foldlOf' :: Is k A_Fold => Optic' k is s a -> (r -> a -> r) -> r -> s -> r -- | Fold to a list. -- --
-- >>> toListOf (_1 % folded % _Right) ([Right 'h', Left 5, Right 'i'], "bye") -- "hi" --toListOf :: Is k A_Fold => Optic' k is s a -> s -> [a] -- | Evaluate each action in a structure observed by a Fold from -- left to right, ignoring the results. -- --
-- sequenceA_ ≡ sequenceOf_ folded ---- --
-- >>> sequenceOf_ each (putStrLn "hello",putStrLn "world") -- hello -- world --sequenceOf_ :: (Is k A_Fold, Applicative f) => Optic' k is s (f a) -> s -> f () -- | Traverse over all of the targets of a Fold, computing an -- Applicative-based answer, but unlike traverseOf do not -- construct a new structure. traverseOf_ generalizes -- traverse_ to work over any Fold. -- --
-- >>> traverseOf_ each putStrLn ("hello","world")
-- hello
-- world
--
--
-- -- traverse_ ≡ traverseOf_ folded --traverseOf_ :: (Is k A_Fold, Applicative f) => Optic' k is s a -> (a -> f r) -> s -> f () -- | A version of traverseOf_ with the arguments flipped. forOf_ :: (Is k A_Fold, Applicative f) => Optic' k is s a -> s -> (a -> f r) -> f () -- | Fold via the Foldable class. folded :: Foldable f => Fold (f a) a -- | Obtain a Fold by lifting an operation that returns a -- Foldable result. -- -- This can be useful to lift operations from Data.List and -- elsewhere into a Fold. -- --
-- >>> toListOf (folding tail) [1,2,3,4] -- [2,3,4] --folding :: Foldable f => (s -> f a) -> Fold s a -- | Obtain a Fold by lifting foldr like function. -- --
-- >>> toListOf (foldring foldr) [1,2,3,4] -- [1,2,3,4] --foldring :: (forall f. Applicative f => (a -> f u -> f u) -> f v -> s -> f w) -> Fold s a -- | Build a Fold that unfolds its values from a seed. -- --
-- unfoldr ≡ toListOf . unfolded ---- --
-- >>> toListOf (unfolded $ \b -> if b == 0 then Nothing else Just (b, b - 1)) 10 -- [10,9,8,7,6,5,4,3,2,1] --unfolded :: (s -> Maybe (a, s)) -> Fold s a -- | Check to see if this optic matches 1 or more entries. -- --
-- >>> has _Left (Left 12) -- True ---- --
-- >>> has _Right (Left 12) -- False ---- -- This will always return True for a Lens or -- Getter. -- --
-- >>> has _1 ("hello","world")
-- True
--
has :: Is k A_Fold => Optic' k is s a -> s -> Bool
-- | Check to see if this Fold or Traversal has no matches.
--
-- -- >>> hasn't _Left (Right 12) -- True ---- --
-- >>> hasn't _Left (Left 12) -- False --hasn't :: Is k A_Fold => Optic' k is s a -> s -> Bool -- | Retrieve the first entry of a Fold. -- --
-- >>> headOf folded [1..10] -- Just 1 ---- --
-- >>> headOf each (1,2) -- Just 1 --headOf :: Is k A_Fold => Optic' k is s a -> s -> Maybe a -- | Retrieve the last entry of a Fold. -- --
-- >>> lastOf folded [1..10] -- Just 10 ---- --
-- >>> lastOf each (1,2) -- Just 2 --lastOf :: Is k A_Fold => Optic' k is s a -> s -> Maybe a -- | Returns True if every target of a Fold is True. -- --
-- >>> andOf each (True, False) -- False -- -- >>> andOf each (True, True) -- True ---- --
-- and ≡ andOf folded --andOf :: Is k A_Fold => Optic' k is s Bool -> s -> Bool -- | Returns True if any target of a Fold is True. -- --
-- >>> orOf each (True, False) -- True -- -- >>> orOf each (False, False) -- False ---- --
-- or ≡ orOf folded --orOf :: Is k A_Fold => Optic' k is s Bool -> s -> Bool -- | Returns True if every target of a Fold satisfies a -- predicate. -- --
-- >>> allOf each (>=3) (4,5) -- True -- -- >>> allOf folded (>=2) [1..10] -- False ---- --
-- all ≡ allOf folded --allOf :: Is k A_Fold => Optic' k is s a -> (a -> Bool) -> s -> Bool -- | Returns True if any target of a Fold satisfies a -- predicate. -- --
-- >>> anyOf each (=='x') ('x','y')
-- True
--
anyOf :: Is k A_Fold => Optic' k is s a -> (a -> Bool) -> s -> Bool
-- | Returns True only if no targets of a Fold satisfy a
-- predicate.
--
-- -- >>> noneOf each (not . isn't _Nothing) (Just 3, Just 4, Just 5) -- True -- -- >>> noneOf (folded % folded) (<10) [[13,99,20],[3,71,42]] -- False --noneOf :: Is k A_Fold => Optic' k is s a -> (a -> Bool) -> s -> Bool -- | Calculate the Product of every number targeted by a -- Fold. -- --
-- >>> productOf each (4,5) -- 20 -- -- >>> productOf folded [1,2,3,4,5] -- 120 ---- --
-- product ≡ productOf folded ---- -- This operation may be more strict than you would expect. If you want a -- lazier version use \o -> getProduct . -- foldMapOf o Product. productOf :: (Is k A_Fold, Num a) => Optic' k is s a -> s -> a -- | Calculate the Sum of every number targeted by a Fold. -- --
-- >>> sumOf each (5,6) -- 11 -- -- >>> sumOf folded [1,2,3,4] -- 10 -- -- >>> sumOf (folded % each) [(1,2),(3,4)] -- 10 ---- --
-- sum ≡ sumOf folded ---- -- This operation may be more strict than you would expect. If you want a -- lazier version use \o -> getSum . -- foldMapOf o Sum sumOf :: (Is k A_Fold, Num a) => Optic' k is s a -> s -> a -- | The sum of a collection of actions. -- --
-- >>> asumOf each ("hello","world")
-- "helloworld"
--
--
-- -- >>> asumOf each (Nothing, Just "hello", Nothing) -- Just "hello" ---- --
-- asum ≡ asumOf folded --asumOf :: (Is k A_Fold, Alternative f) => Optic' k is s (f a) -> s -> f a -- | The sum of a collection of actions. -- --
-- >>> msumOf each ("hello","world")
-- "helloworld"
--
--
-- -- >>> msumOf each (Nothing, Just "hello", Nothing) -- Just "hello" ---- --
-- msum ≡ msumOf folded --msumOf :: (Is k A_Fold, MonadPlus m) => Optic' k is s (m a) -> s -> m a -- | Does the element occur anywhere within a given Fold of the -- structure? -- --
-- >>> elemOf each "hello" ("hello","world")
-- True
--
--
-- -- elem ≡ elemOf folded --elemOf :: (Is k A_Fold, Eq a) => Optic' k is s a -> a -> s -> Bool -- | Does the element not occur anywhere within a given Fold of the -- structure? -- --
-- >>> notElemOf each 'd' ('a','b','c')
-- True
--
--
--
-- >>> notElemOf each 'a' ('a','b','c')
-- False
--
--
-- -- notElem ≡ notElemOf folded --notElemOf :: (Is k A_Fold, Eq a) => Optic' k is s a -> a -> s -> Bool -- | Calculate the number of targets there are for a Fold in a given -- container. -- -- Note: This can be rather inefficient for large containers and -- just like length, this will not terminate for infinite folds. -- --
-- length ≡ lengthOf folded ---- --
-- >>> lengthOf _1 ("hello",())
-- 1
--
--
-- -- >>> lengthOf folded [1..10] -- 10 ---- --
-- >>> lengthOf (folded % folded) [[1,2],[3,4],[5,6]] -- 6 --lengthOf :: Is k A_Fold => Optic' k is s a -> s -> Int -- | Obtain the maximum element (if any) targeted by a Fold safely. -- -- Note: maximumOf on a valid Iso, Lens or -- Getter will always return Just a value. -- --
-- >>> maximumOf folded [1..10] -- Just 10 ---- --
-- >>> maximumOf folded [] -- Nothing ---- --
-- >>> maximumOf (folded % filtered even) [1,4,3,6,7,9,2] -- Just 6 ---- --
-- maximum ≡ fromMaybe (error "empty") . maximumOf folded ---- -- In the interest of efficiency, This operation has semantics more -- strict than strictly necessary. \o -> getMax . -- foldMapOf o Max has lazier semantics but could leak -- memory. maximumOf :: (Is k A_Fold, Ord a) => Optic' k is s a -> s -> Maybe a -- | Obtain the minimum element (if any) targeted by a Fold safely. -- -- Note: minimumOf on a valid Iso, Lens or -- Getter will always return Just a value. -- --
-- >>> minimumOf folded [1..10] -- Just 1 ---- --
-- >>> minimumOf folded [] -- Nothing ---- --
-- >>> minimumOf (folded % filtered even) [1,4,3,6,7,9,2] -- Just 2 ---- --
-- minimum ≡ fromMaybe (error "empty") . minimumOf folded ---- -- In the interest of efficiency, This operation has semantics more -- strict than strictly necessary. \o -> getMin . -- foldMapOf o Min has lazier semantics but could leak -- memory. minimumOf :: (Is k A_Fold, Ord a) => Optic' k is s a -> s -> Maybe a -- | Obtain the maximum element (if any) targeted by a Fold -- according to a user supplied Ordering. -- --
-- >>> maximumByOf folded (compare `on` length) ["mustard","relish","ham"] -- Just "mustard" ---- -- In the interest of efficiency, This operation has semantics more -- strict than strictly necessary. -- --
-- maximumBy cmp ≡ fromMaybe (error "empty") . maximumByOf folded cmp --maximumByOf :: Is k A_Fold => Optic' k is s a -> (a -> a -> Ordering) -> s -> Maybe a -- | Obtain the minimum element (if any) targeted by a Fold -- according to a user supplied Ordering. -- -- In the interest of efficiency, This operation has semantics more -- strict than strictly necessary. -- --
-- >>> minimumByOf folded (compare `on` length) ["mustard","relish","ham"] -- Just "ham" ---- --
-- minimumBy cmp ≡ fromMaybe (error "empty") . minimumByOf folded cmp --minimumByOf :: Is k A_Fold => Optic' k is s a -> (a -> a -> Ordering) -> s -> Maybe a -- | The findOf function takes a Fold, a predicate and a -- structure and returns the leftmost element of the structure matching -- the predicate, or Nothing if there is no such element. -- --
-- >>> findOf each even (1,3,4,6) -- Just 4 ---- --
-- >>> findOf folded even [1,3,5,7] -- Nothing ---- --
-- find ≡ findOf folded --findOf :: Is k A_Fold => Optic' k is s a -> (a -> Bool) -> s -> Maybe a -- | The findMOf function takes a Fold, a monadic predicate -- and a structure and returns in the monad the leftmost element of the -- structure matching the predicate, or Nothing if there is no -- such element. -- --
-- >>> findMOf each (\x -> print ("Checking " ++ show x) >> return (even x)) (1,3,4,6)
-- "Checking 1"
-- "Checking 3"
-- "Checking 4"
-- Just 4
--
--
--
-- >>> findMOf each (\x -> print ("Checking " ++ show x) >> return (even x)) (1,3,5,7)
-- "Checking 1"
-- "Checking 3"
-- "Checking 5"
-- "Checking 7"
-- Nothing
--
--
-- -- findMOf folded :: (Monad m, Foldable f) => (a -> m Bool) -> f a -> m (Maybe a) --findMOf :: (Is k A_Fold, Monad m) => Optic' k is s a -> (a -> m Bool) -> s -> m (Maybe a) -- | The lookupOf function takes a Fold, a key, and a -- structure containing key/value pairs. It returns the first value -- corresponding to the given key. This function generalizes -- lookup to work on an arbitrary Fold instead of lists. -- --
-- >>> lookupOf folded 4 [(2, 'a'), (4, 'b'), (4, 'c')] -- Just 'b' ---- --
-- >>> lookupOf folded 2 [(2, 'a'), (4, 'b'), (4, 'c')] -- Just 'a' --lookupOf :: (Is k A_Fold, Eq a) => Optic' k is s (a, v) -> a -> s -> Maybe v -- | Convert a fold to an AffineFold that visits the first element -- of the original fold. -- -- For the traversal version see singular. pre :: Is k A_Fold => Optic' k is s a -> AffineFold s a -- | This allows you to traverse the elements of a Fold in the -- opposite order. backwards_ :: Is k A_Fold => Optic' k is s a -> Fold s a -- | Return entries of the first Fold, then the second one. -- --
-- >>> toListOf (_1 % ix 0 `summing` _2 % ix 1) ([1,2], [4,7,1]) -- [1,7] --summing :: (Is k A_Fold, Is l A_Fold) => Optic' k is s a -> Optic' l js s a -> Fold s a infixr 6 `summing` -- | Try the first Fold. If it returns no entries, try the second -- one. -- --
-- >>> toListOf (ix 1 `failing` ix 0) [4,7] -- [7] -- -- >>> toListOf (ix 1 `failing` ix 0) [4] -- [4] --failing :: (Is k A_Fold, Is l A_Fold) => Optic' k is s a -> Optic' l js s a -> Fold s a infixl 3 `failing` -- | Tag for a fold. data A_Fold :: OpticKind -- | An IxAffineFold is an indexed version of an AffineFold. -- See the "Indexed optics" section of the overview documentation in the -- Optics module of the main optics package for more -- details on indexed optics. module Optics.IxAffineFold -- | Type synonym for an indexed affine fold. type IxAffineFold i s a = Optic' An_AffineFold (WithIx i) s a -- | Create an IxAffineFold from a partial function. iafolding :: (s -> Maybe (i, a)) -> IxAffineFold i s a -- | Retrieve the value along with its index targeted by an -- IxAffineFold. ipreview :: (Is k An_AffineFold, is `HasSingleIndex` i) => Optic' k is s a -> s -> Maybe (i, a) -- | Retrieve a function of the value and its index targeted by an -- IxAffineFold. ipreviews :: (Is k An_AffineFold, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> r) -> s -> Maybe r -- | Obtain an IxAffineFold by lifting itraverse_ like -- function. -- --
-- aifoldVL . iatraverseOf_ ≡ id -- aitraverseOf_ . iafoldVL ≡ id --iafoldVL :: (forall f. Functor f => (forall r. r -> f r) -> (i -> a -> f u) -> s -> f v) -> IxAffineFold i s a -- | Traverse over the target of an IxAffineFold, computing a -- Functor-based answer, but unlike iatraverseOf do not -- construct a new structure. iatraverseOf_ :: (Is k An_AffineFold, Functor f, is `HasSingleIndex` i) => Optic' k is s a -> (forall r. r -> f r) -> (i -> a -> f u) -> s -> f () -- | Obtain a potentially empty IxAffineFold by taking the element -- from another AffineFold and using it as an index. filteredBy :: Is k An_AffineFold => Optic' k is a i -> IxAffineFold i a a -- | Try the first IxAffineFold. If it returns no entry, try the -- second one. iafailing :: (Is k An_AffineFold, Is l An_AffineFold, is1 `HasSingleIndex` i, is2 `HasSingleIndex` i) => Optic' k is1 s a -> Optic' l is2 s a -> IxAffineFold i s a infixl 3 `iafailing` -- | Tag for an affine fold. data An_AffineFold :: OpticKind -- | An IxAffineTraversal is an indexed version of an -- AffineTraversal. See the "Indexed optics" section of the -- overview documentation in the Optics module of the main -- optics package for more details on indexed optics. module Optics.IxAffineTraversal -- | Type synonym for a type-modifying indexed affine traversal. type IxAffineTraversal i s t a b = Optic An_AffineTraversal (WithIx i) s t a b -- | Type synonym for a type-preserving indexed affine traversal. type IxAffineTraversal' i s a = Optic' An_AffineTraversal (WithIx i) s a -- | Build an indexed affine traversal from a matcher and an updater. -- -- If you want to build an IxAffineTraversal from the van -- Laarhoven representation, use iatraversalVL. iatraversal :: (s -> Either t (i, a)) -> (s -> b -> t) -> IxAffineTraversal i s t a b -- | Obtain a potentially empty IxAffineTraversal by taking the -- element from another AffineFold and using it as an index. -- --
-- >>> 6 & ignored %~ absurd -- 6 --ignored :: IxAffineTraversal i s s a b -- | Tag for an affine traversal. data An_AffineTraversal :: OpticKind -- | Type synonym for a type-modifying van Laarhoven indexed affine -- traversal. -- -- Note: this isn't exactly van Laarhoven representation as there is no -- Pointed class (which would be a superclass of -- Applicative that contains pure but not -- <*>). You can interpret the first argument as a -- dictionary of Pointed that supplies the point -- function (i.e. the implementation of pure). type IxAffineTraversalVL i s t a b = forall f. Functor f => (forall r. r -> f r) -> (i -> a -> f b) -> s -> f t -- | Type synonym for a type-preserving van Laarhoven indexed affine -- traversal. type IxAffineTraversalVL' i s a = IxAffineTraversalVL i s s a a -- | Build an indexed affine traversal from the van Laarhoven -- representation. iatraversalVL :: IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b -- | Traverse over the target of an IxAffineTraversal and compute a -- Functor-based answer. iatraverseOf :: (Is k An_AffineTraversal, Functor f, is `HasSingleIndex` i) => Optic k is s t a b -> (forall r. r -> f r) -> (i -> a -> f b) -> s -> f t -- | An IxFold is an indexed version of a Fold. See the -- "Indexed optics" section of the overview documentation in the -- Optics module of the main optics package for more -- details on indexed optics. module Optics.IxFold -- | Type synonym for an indexed fold. type IxFold i s a = Optic' A_Fold (WithIx i) s a -- | Obtain an indexed fold by lifting itraverse_ like function. -- --
-- ifoldVL . itraverseOf_ ≡ id -- itraverseOf_ . ifoldVL ≡ id --ifoldVL :: (forall f. Applicative f => (i -> a -> f u) -> s -> f v) -> IxFold i s a -- | Fold with index via embedding into a monoid. ifoldMapOf :: (Is k A_Fold, Monoid m, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> m) -> s -> m -- | Fold with index right-associatively. ifoldrOf :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> r -> r) -> r -> s -> r -- | Fold with index left-associatively, and strictly. ifoldlOf' :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> (i -> r -> a -> r) -> r -> s -> r -- | Fold with index to a list. -- --
-- >>> itoListOf (folded % ifolded) ["abc", "def"] -- [(0,'a'),(1,'b'),(2,'c'),(0,'d'),(1,'e'),(2,'f')] ---- -- Note: currently indexed optics can be used as non-indexed. -- --
-- >>> toListOf (folded % ifolded) ["abc", "def"] -- "abcdef" --itoListOf :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> s -> [(i, a)] -- | Traverse over all of the targets of an IxFold, computing an -- Applicative-based answer, but unlike itraverseOf do not -- construct a new structure. -- --
-- >>> itraverseOf_ each (curry print) ("hello","world")
-- (0,"hello")
-- (1,"world")
--
itraverseOf_ :: (Is k A_Fold, Applicative f, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> f r) -> s -> f ()
-- | A version of itraverseOf_ with the arguments flipped.
iforOf_ :: (Is k A_Fold, Applicative f, is `HasSingleIndex` i) => Optic' k is s a -> s -> (i -> a -> f r) -> f ()
-- | Indexed fold via FoldableWithIndex class.
ifolded :: FoldableWithIndex i f => IxFold i (f a) a
-- | Obtain an IxFold by lifting an operation that returns a
-- FoldableWithIndex result.
--
-- This can be useful to lift operations from Data.List and
-- elsewhere into an IxFold.
--
-- -- >>> itoListOf (ifolding words) "how are you" -- [(0,"how"),(1,"are"),(2,"you")] --ifolding :: FoldableWithIndex i f => (s -> f a) -> IxFold i s a -- | Obtain an IxFold by lifting ifoldr like function. -- --
-- >>> itoListOf (ifoldring ifoldr) "hello" -- [(0,'h'),(1,'e'),(2,'l'),(3,'l'),(4,'o')] --ifoldring :: (forall f. Applicative f => (i -> a -> f u -> f u) -> f v -> s -> f w) -> IxFold i s a -- | Retrieve the first entry of an IxFold along with its index. -- --
-- >>> iheadOf ifolded [1..10] -- Just (0,1) --iheadOf :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> s -> Maybe (i, a) -- | Retrieve the last entry of an IxFold along with its index. -- --
-- >>> ilastOf ifolded [1..10] -- Just (9,10) --ilastOf :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> s -> Maybe (i, a) -- | Return whether or not any element viewed through an IxFold -- satisfies a predicate, with access to the i. -- -- When you don't need access to the index then anyOf is more -- flexible in what it accepts. -- --
-- anyOf o ≡ ianyOf o . const --ianyOf :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> Bool) -> s -> Bool -- | Return whether or not all elements viewed through an IxFold -- satisfy a predicate, with access to the i. -- -- When you don't need access to the index then allOf is more -- flexible in what it accepts. -- --
-- allOf o ≡ iallOf o . const --iallOf :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> Bool) -> s -> Bool -- | Return whether or not none of the elements viewed through an -- IxFold satisfy a predicate, with access to the i. -- -- When you don't need access to the index then noneOf is more -- flexible in what it accepts. -- --
-- noneOf o ≡ inoneOf o . const --inoneOf :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> Bool) -> s -> Bool -- | The ifindOf function takes an IxFold, a predicate that -- is also supplied the index, a structure and returns the left-most -- element of the structure along with its index matching the predicate, -- or Nothing if there is no such element. -- -- When you don't need access to the index then findOf is more -- flexible in what it accepts. ifindOf :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> Bool) -> s -> Maybe (i, a) -- | The ifindMOf function takes an IxFold, a monadic -- predicate that is also supplied the index, a structure and returns in -- the monad the left-most element of the structure matching the -- predicate, or Nothing if there is no such element. -- -- When you don't need access to the index then findMOf is more -- flexible in what it accepts. ifindMOf :: (Is k A_Fold, Monad m, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> m Bool) -> s -> m (Maybe (i, a)) -- | Convert an indexed fold to an IxAffineFold that visits the -- first element of the original fold. -- -- For the traversal version see isingular. ipre :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> IxAffineFold i s a -- | Filter results of an IxFold that don't satisfy a predicate. -- --
-- >>> toListOf (ifolded %& ifiltered (>)) [3,2,1,0] -- [1,0] --ifiltered :: (Is k A_Fold, is `HasSingleIndex` i) => (i -> a -> Bool) -> Optic' k is s a -> IxFold i s a -- | This allows you to traverse the elements of an IxFold in the -- opposite order. ibackwards_ :: (Is k A_Fold, is `HasSingleIndex` i) => Optic' k is s a -> IxFold i s a -- | Return entries of the first IxFold, then the second one. -- --
-- >>> itoListOf (ifolded `isumming` ibackwards_ ifolded) ["a","b"] -- [(0,"a"),(1,"b"),(1,"b"),(0,"a")] --isumming :: (Is k A_Fold, Is l A_Fold, is1 `HasSingleIndex` i, is2 `HasSingleIndex` i) => Optic' k is1 s a -> Optic' l is2 s a -> IxFold i s a infixr 6 `isumming` -- | Try the first IxFold. If it returns no entries, try the second -- one. -- --
-- >>> itoListOf (_1 % ifolded `ifailing` _2 % ifolded) (["a"], ["b","c"]) -- [(0,"a")] -- -- >>> itoListOf (_1 % ifolded `ifailing` _2 % ifolded) ([], ["b","c"]) -- [(0,"b"),(1,"c")] --ifailing :: (Is k A_Fold, Is l A_Fold, is1 `HasSingleIndex` i, is2 `HasSingleIndex` i) => Optic' k is1 s a -> Optic' l is2 s a -> IxFold i s a infixl 3 `ifailing` -- | Tag for a fold. data A_Fold :: OpticKind -- | Class for Foldables that have an additional read-only index -- available. class (FunctorWithIndex i f, Foldable f) => FoldableWithIndex i f | f -> i ifoldMap :: (FoldableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m ifoldMap :: (FoldableWithIndex i f, TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m ifoldr :: FoldableWithIndex i f => (i -> a -> b -> b) -> b -> f a -> b ifoldl' :: FoldableWithIndex i f => (i -> b -> a -> b) -> b -> f a -> b -- | An IxGetter is an indexed version of a Getter. See the -- "Indexed optics" section of the overview documentation in the -- Optics module of the main optics package for more -- details on indexed optics. module Optics.IxGetter -- | Type synonym for an indexed getter. type IxGetter i s a = Optic' A_Getter (WithIx i) s a -- | Build an indexed getter from a function. -- --
-- >>> iview (ito id) ('i', 'x')
-- ('i','x')
--
ito :: (s -> (i, a)) -> IxGetter i s a
-- | Use a value itself as its own index. This is essentially an indexed
-- version of equality.
selfIndex :: IxGetter a a a
-- | View the value pointed to by an indexed getter.
iview :: (Is k A_Getter, is `HasSingleIndex` i) => Optic' k is s a -> s -> (i, a)
-- | View the function of the value pointed to by an indexed getter.
iviews :: (Is k A_Getter, is `HasSingleIndex` i) => Optic' k is s a -> (i -> a -> r) -> s -> r
-- | Tag for a getter.
data A_Getter :: OpticKind
-- | An IxLens is an indexed version of a Lens. See the
-- "Indexed optics" section of the overview documentation in the
-- Optics module of the main optics package for more
-- details on indexed optics.
module Optics.IxLens
-- | Type synonym for a type-modifying indexed lens.
type IxLens i s t a b = Optic A_Lens (WithIx i) s t a b
-- | Type synonym for a type-preserving indexed lens.
type IxLens' i s a = Optic' A_Lens (WithIx i) s a
-- | Build an indexed lens from a getter and a setter.
--
-- If you want to build an IxLens from the van Laarhoven
-- representation, use ilensVL.
ilens :: (s -> (i, a)) -> (s -> b -> t) -> IxLens i s t a b
-- | There is an indexed field for every type in the Void.
--
-- -- >>> set (mapped % devoid) 1 [] -- [] ---- --
-- >>> over (_Just % devoid) abs Nothing -- Nothing --devoid :: IxLens' i Void a -- | Tag for a lens. data A_Lens :: OpticKind -- | Type synonym for a type-modifying van Laarhoven indexed lens. type IxLensVL i s t a b = forall f. Functor f => (i -> a -> f b) -> s -> f t -- | Type synonym for a type-preserving van Laarhoven indexed lens. type IxLensVL' i s a = IxLensVL i s s a a -- | Build an indexed lens from the van Laarhoven representation. ilensVL :: IxLensVL i s t a b -> IxLens i s t a b -- | Convert an indexed lens to its van Laarhoven representation. toIxLensVL :: (Is k A_Lens, is `HasSingleIndex` i) => Optic k is s t a b -> IxLensVL i s t a b -- | Work with an indexed lens in the van Laarhoven representation. withIxLensVL :: (Is k A_Lens, is `HasSingleIndex` i) => Optic k is s t a b -> (IxLensVL i s t a b -> r) -> r -- | An IxSetter is an indexed version of a Setter. See the -- "Indexed optics" section of the overview documentation in the -- Optics module of the main optics package for more -- details on indexed optics. module Optics.IxSetter -- | Type synonym for a type-modifying indexed setter. type IxSetter i s t a b = Optic A_Setter (WithIx i) s t a b -- | Type synonym for a type-preserving indexed setter. type IxSetter' i s a = Optic' A_Setter (WithIx i) s a -- | Build an indexed setter from a function to modify the element(s). isets :: ((i -> a -> b) -> s -> t) -> IxSetter i s t a b -- | Apply an indexed setter as a modifier. iover :: (Is k A_Setter, is `HasSingleIndex` i) => Optic k is s t a b -> (i -> a -> b) -> s -> t -- | Indexed setter via the FunctorWithIndex class. -- --
-- iover imapped ≡ imap --imapped :: FunctorWithIndex i f => IxSetter i (f a) (f b) a b -- | Apply an indexed setter. -- --
-- iset o f ≡ iover o (i _ -> f i) --iset :: (Is k A_Setter, is `HasSingleIndex` i) => Optic k is s t a b -> (i -> b) -> s -> t -- | Apply an indexed setter, strictly. iset' :: (Is k A_Setter, is `HasSingleIndex` i) => Optic k is s t a b -> (i -> b) -> s -> t -- | Apply an indexed setter as a modifier, strictly. iover' :: (Is k A_Setter, is `HasSingleIndex` i) => Optic k is s t a b -> (i -> a -> b) -> s -> t -- | Tag for a setter. data A_Setter :: OpticKind -- | Class for Functors that have an additional read-only index -- available. class Functor f => FunctorWithIndex i f | f -> i imap :: FunctorWithIndex i f => (i -> a -> b) -> f a -> f b imap :: (FunctorWithIndex i f, TraversableWithIndex i f) => (i -> a -> b) -> f a -> f b -- | Overloaded labels are a solution to Haskell's namespace problem for -- records. The -XOverloadedLabels extension allows a new -- expression syntax for labels, a prefix # sign followed by an -- identifier, e.g. #foo. These expressions can then be given an -- interpretation that depends on the type at which they are used and the -- text of the label. -- -- The following example shows how overloaded labels can be used as -- optics. -- --
-- >>> :set -XDataKinds
--
-- >>> :set -XFlexibleContexts
--
-- >>> :set -XFlexibleInstances
--
-- >>> :set -XMultiParamTypeClasses
--
-- >>> :set -XOverloadedLabels
--
-- >>> :set -XTypeFamilies
--
-- >>> :set -XUndecidableInstances
--
-- >>> :{
-- data Human = Human
-- { humanName :: String
-- , humanAge :: Integer
-- , humanPets :: [Pet]
-- } deriving Show
-- data Pet
-- = Cat { petName :: String, petAge :: Int, petLazy :: Bool }
-- | Fish { petName :: String, petAge :: Int }
-- deriving Show
-- :}
--
--
-- The following instances can be generated by makeFieldLabels
-- from Optics.TH in the optics-th package:
--
--
-- >>> :{
-- instance (k ~ A_Lens, a ~ String, b ~ String) => LabelOptic "name" k Human Human a b where
-- labelOptic = lensVL $ \f s -> (\v -> s { humanName = v }) <$> f (humanName s)
-- instance (k ~ A_Lens, a ~ Integer, b ~ Integer) => LabelOptic "age" k Human Human a b where
-- labelOptic = lensVL $ \f s -> (\v -> s { humanAge = v }) <$> f (humanAge s)
-- instance (k ~ A_Lens, a ~ [Pet], b ~ [Pet]) => LabelOptic "pets" k Human Human a b where
-- labelOptic = lensVL $ \f s -> (\v -> s { humanPets = v }) <$> f (humanPets s)
-- instance (k ~ A_Lens, a ~ String, b ~ String) => LabelOptic "name" k Pet Pet a b where
-- labelOptic = lensVL $ \f s -> (\v -> s { petName = v }) <$> f (petName s)
-- instance (k ~ A_Lens, a ~ Int, b ~ Int) => LabelOptic "age" k Pet Pet a b where
-- labelOptic = lensVL $ \f s -> (\v -> s { petAge = v }) <$> f (petAge s)
-- instance (k ~ An_AffineTraversal, a ~ Bool, b ~ Bool) => LabelOptic "lazy" k Pet Pet a b where
-- labelOptic = atraversalVL $ \point f s -> case s of
-- Cat name age lazy -> (\lazy' -> Cat name age lazy') <$> f lazy
-- _ -> point s
-- :}
--
--
-- Here is some test data:
--
--
-- >>> :{
-- peter :: Human
-- peter = Human "Peter" 13 [ Fish "Goldie" 1
-- , Cat "Loopy" 3 False
-- , Cat "Sparky" 2 True
-- ]
-- :}
--
--
-- Now we can ask for Peter's name:
--
-- -- >>> view #name peter -- "Peter" ---- -- or for names of his pets: -- --
-- >>> toListOf (#pets % folded % #name) peter -- ["Goldie","Loopy","Sparky"] ---- -- We can check whether any of his pets is lazy: -- --
-- >>> orOf (#pets % folded % #lazy) peter -- True ---- -- or how things might be be a year from now: -- --
-- >>> peter & over #age (+1) & over (#pets % mapped % #age) (+1)
-- Human {humanName = "Peter", humanAge = 14, humanPets = [Fish {petName = "Goldie", petAge = 2},Cat {petName = "Loopy", petAge = 4, petLazy = False},Cat {petName = "Sparky", petAge = 3, petLazy = True}]}
--
--
-- Perhaps Peter is going on vacation and needs to leave his pets at
-- home:
--
--
-- >>> peter & set #pets []
-- Human {humanName = "Peter", humanAge = 13, humanPets = []}
--
--
-- -- instance (k ~ A_Lens, a ~ [Pet], b ~ [Pet]) => LabelOptic "pets" k Human Human a b where ---- -- instead of -- --
-- instance LabelOptic "pets" A_Lens Human Human [Pet] [Pet] where ---- -- The reason is that using the first form ensures that it is enough for -- GHC to match on the instance if either s or t is -- known (as type equalities are verified after the instance matches), -- which not only makes type inference better, but also allows it to -- generate better error messages. -- -- For example, if you try to write peter & set #pets [] -- with the appropriate LabelOptic instance in the second form, you get -- the following: -- --
-- interactive:16:1: error: -- • No instance for LabelOptic "pets" ‘A_Lens’ ‘Human’ ‘()’ ‘[Pet]’ ‘[a0]’ -- (maybe you forgot to define it or misspelled a name?) -- • In the first argument of ‘print’, namely ‘it’ -- In a stmt of an interactive GHCi command: print it ---- -- That's because empty list doesn't have type [Pet], it has -- type [r] and GHC doesn't have enough information to match on -- the instance we provided. We'd need to either annotate the list: -- peter & set #pets ([]::[Pet]) or the result type: -- peter & set #pets [] :: Human, which is suboptimal. -- -- Here are more examples of confusing error messages if the instance for -- LabelOptic "age" is written without type equalities: -- --
-- λ> view #age peter :: Char -- -- interactive:28:6: error: -- • No instance for LabelOptic "age" ‘k0’ ‘Human’ ‘Human’ ‘Char’ ‘Char’ -- (maybe you forgot to define it or misspelled a name?) -- • In the first argument of ‘view’, namely ‘#age’ -- In the expression: view #age peter :: Char -- In an equation for ‘it’: it = view #age peter :: Char -- λ> peter & set #age "hi" -- -- interactive:29:1: error: -- • No instance for LabelOptic "age" ‘k’ ‘Human’ ‘b’ ‘a’ ‘[Char]’ -- (maybe you forgot to define it or misspelled a name?) -- • When checking the inferred type -- it :: forall k b a. ((TypeError ...), Is k A_Setter) => b -- -- λ> age = #age :: Iso' Human Int -- -- interactive:7:7: error: -- • No instance for LabelOptic "age" ‘An_Iso’ ‘Human’ ‘Human’ ‘Int’ ‘Int’ -- (maybe you forgot to define it or misspelled a name?) -- • In the expression: #age :: Iso' Human Int -- In an equation for ‘age’: age = #age :: Iso' Human Int ---- -- If we use the first form, error messages become more accurate: -- --
-- λ> view #age peter :: Char -- interactive:31:6: error: -- • Couldn't match type ‘Char’ with ‘Integer’ -- arising from the overloaded label ‘#age’ -- • In the first argument of ‘view’, namely ‘#age’ -- In the expression: view #age peter :: Char -- In an equation for ‘it’: it = view #age peter :: Char -- λ> peter & set #age "hi" -- -- interactive:32:13: error: -- • Couldn't match type ‘[Char]’ with ‘Integer’ -- arising from the overloaded label ‘#age’ -- • In the first argument of ‘set’, namely ‘#age’ -- In the second argument of ‘(&)’, namely ‘set #age "hi"’ -- In the expression: peter & set #age "hi" -- λ> age = #age :: Iso' Human Int -- -- interactive:9:7: error: -- • Couldn't match type ‘An_Iso’ with ‘A_Lens’ -- arising from the overloaded label ‘#age’ -- • In the expression: #age :: Iso' Human Int -- In an equation for ‘age’: age = #age :: Iso' Human Int ---- --
-- >>> data Human = Human { _name :: String, _location :: String } deriving Show
--
-- >>> let human = Human "Bob" "London"
--
--
-- we can make a Lens for _name field:
--
--
-- >>> let name = lens _name $ \s x -> s { _name = x }
--
--
-- which we can use as a Getter:
--
-- -- >>> view name human -- "Bob" ---- -- or a Setter: -- --
-- >>> set name "Robert" human
-- Human {_name = "Robert", _location = "London"}
--
module Optics.Lens
-- | Type synonym for a type-modifying lens.
type Lens s t a b = Optic A_Lens NoIx s t a b
-- | Type synonym for a type-preserving lens.
type Lens' s a = Optic' A_Lens NoIx s a
-- | Build a lens from a getter and a setter, which must respect the
-- well-formedness laws.
--
-- If you want to build a Lens from the van Laarhoven
-- representation, use lensVL.
lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
-- | Strict version of equality.
--
-- Useful for strictifying optics with lazy (irrefutable) pattern
-- matching by precomposition, e.g.
--
-- -- _1' = equality' % _1 --equality' :: Lens a b a b -- | Focus on both sides of an Either. chosen :: Lens (Either a a) (Either b b) a b -- | Make a Lens from two other lenses by executing them on their -- respective halves of a product. -- --
-- >>> (Left 'a', Right 'b') ^. alongside chosen chosen
-- ('a','b')
--
--
--
-- >>> (Left 'a', Right 'b') & alongside chosen chosen .~ ('c','d')
-- (Left 'c',Right 'd')
--
alongside :: (Is k A_Lens, Is l A_Lens) => Optic k is s t a b -> Optic l js s' t' a' b' -> Lens (s, s') (t, t') (a, a') (b, b')
-- | We can always retrieve a () from any type.
--
-- -- >>> view united "hello" -- () ---- --
-- >>> set united () "hello" -- "hello" --united :: Lens' a () -- | Work with a lens as a getter and a setter. -- --
-- withLens (lens f g) k ≡ k f g --withLens :: Is k A_Lens => Optic k is s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r -- | Tag for a lens. data A_Lens :: OpticKind -- | Type synonym for a type-modifying van Laarhoven lens. type LensVL s t a b = forall f. Functor f => (a -> f b) -> s -> f t -- | Type synonym for a type-preserving van Laarhoven lens. type LensVL' s a = LensVL s s a a -- | Build a lens from the van Laarhoven representation. lensVL :: LensVL s t a b -> Lens s t a b -- | Convert a lens to the van Laarhoven representation. toLensVL :: Is k A_Lens => Optic k is s t a b -> LensVL s t a b -- | Work with a lens in the van Laarhoven representation. withLensVL :: Is k A_Lens => Optic k is s t a b -> (LensVL s t a b -> r) -> r -- | This module defines optics for manipulating Trees. module Data.Tree.Optics -- | A Lens that focuses on the root of a Tree. -- --
-- >>> view root $ Node 42 [] -- 42 --root :: Lens' (Tree a) a -- | A Lens returning the direct descendants of the root of a -- Tree -- --
-- view branches ≡ subForest --branches :: Lens' (Tree a) [Tree a] -- | This module provides core definitions: -- --
-- castOptic @A_Lens o ---- -- turns o into a Lens. -- -- This is the identity function, modulo some constraint jiggery-pokery. castOptic :: forall destKind srcKind is s t a b. Is srcKind destKind => Optic srcKind is s t a b -> Optic destKind is s t a b -- | Subtyping relationship between kinds of optics. -- -- An instance of Is k l means that any Optic -- k can be used as an Optic l. For example, we have -- an Is A_Lens A_Traversal instance, but -- not Is A_Traversal A_Lens. -- -- This class needs instances for all possible combinations of tags. class Is k l -- | Computes the least upper bound of two optics kinds. -- -- Join k l represents the least upper bound of an Optic -- k and an Optic l. This means in particular that -- composition of an Optic k and an Optic k will yield -- an Optic (Join k l). type family Join (k :: OpticKind) (l :: OpticKind) -- | Compose two optics of compatible flavours. -- -- Returns an optic of the appropriate supertype. If either or both -- optics are indexed, the composition preserves all the indices. (%) :: (Is k m, Is l m, m ~ Join k l, ks ~ Append is js) => Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b infixl 9 % -- | Compose two optics of the same flavour. -- -- Normally you can simply use (%) instead, but this may be useful -- to help type inference if the type of one of the optics is otherwise -- under-constrained. (%%) :: forall k is js ks s t u v a b. ks ~ Append is js => Optic k is s t u v -> Optic k js u v a b -> Optic k ks s t a b infixl 9 %% -- | Flipped function application, specialised to optics and binding -- tightly. -- -- Useful for post-composing optics transformations: -- --
-- >>> toListOf (ifolded %& ifiltered (\i s -> length s <= i)) ["", "a","abc"] -- ["","a"] --(%&) :: Optic k is s t a b -> (Optic k is s t a b -> Optic l js s' t' a' b') -> Optic l js s' t' a' b' infixl 9 %& -- | A list of index types, used for indexed optics. type IxList = [Type] -- | An alias for an empty index-list type NoIx = ('[] :: IxList) -- | Singleton index list type WithIx i = ('[i] :: IxList) -- | Append two type-level lists together. type family Append (xs :: [k]) (ys :: [k]) :: [k] -- | Check whether a list of indices is not empty and generate sensible -- error message if it's not. class NonEmptyIndices (is :: IxList) -- | Generate sensible error messages in case a user tries to pass either -- an unindexed optic or indexed optic with unflattened indices where -- indexed optic with a single index is expected. class is ~ '[i] => HasSingleIndex (is :: IxList) (i :: Type) -- | Show useful error message when a function expects optics without -- indices. class is ~ NoIx => AcceptsEmptyIndices (f :: Symbol) (is :: IxList) -- | Curry a type-level list. -- -- In pseudo (dependent-)Haskell: -- --
-- Curry xs y = foldr (->) y xs --type family Curry (xs :: IxList) (y :: Type) :: Type -- | Class that is inhabited by all type-level lists xs, providing -- the ability to compose a function under Curry xs. class CurryCompose xs -- | & is a reverse application operator. This provides -- notational convenience. Its precedence is one higher than that of the -- forward application operator $, which allows & to be -- nested in $. -- --
-- >>> 5 & (+1) & show -- "6" --(&) :: () => a -> (a -> b) -> b infixl 1 & -- | Flipped version of <$>. -- --
-- (<&>) = flip fmap ---- --
-- >>> Just 2 <&> (+1) -- Just 3 ---- --
-- >>> [1,2,3] <&> (+1) -- [2,3,4] ---- --
-- >>> Right 3 <&> (+1) -- Right 4 --(<&>) :: Functor f => f a -> (a -> b) -> f b infixl 1 <&> -- | This module exists to provide documentation for lenses for working -- with Map, which might otherwise be obscured by their -- genericity. -- -- Map is an instance of At and provides at as a -- lens on values at keys: -- --
-- >>> Map.fromList [(1, "world")] ^. at 1 -- Just "world" ---- --
-- >>> Map.empty & at 1 .~ Just "world" -- fromList [(1,"world")] ---- --
-- >>> Map.empty & at 0 .~ Just "hello" -- fromList [(0,"hello")] ---- -- We can traverse, fold over, and map over key-value pairs in a -- Map, thanks to indexed traversals, folds and setters. -- --
-- >>> iover imapped const $ Map.fromList [(1, "Venus")] -- fromList [(1,1)] ---- --
-- >>> ifoldMapOf ifolded (\i _ -> Sum i) $ Map.fromList [(2, "Earth"), (3, "Mars")]
-- Sum {getSum = 5}
--
--
-- -- >>> itraverseOf_ ifolded (curry print) $ Map.fromList [(4, "Jupiter")] -- (4,"Jupiter") ---- --
-- >>> itoListOf ifolded $ Map.fromList [(5, "Saturn")] -- [(5,"Saturn")] ---- -- A related class, Ixed, allows us to use ix to traverse a -- value at a particular key. -- --
-- >>> Map.fromList [(2, "Earth")] & ix 2 %~ ("New " ++)
-- fromList [(2,"New Earth")]
--
--
-- -- >>> preview (ix 8) Map.empty -- Nothing --module Data.Map.Optics -- | Construct a map from an IxFold. -- -- The construction is left-biased (see union), i.e. the first -- occurrences of keys in the fold or traversal order are preferred. -- --
-- >>> toMapOf ifolded ["hello", "world"] -- fromList [(0,"hello"),(1,"world")] ---- --
-- >>> toMapOf (folded % ifolded) [('a',"alpha"),('b', "beta")]
-- fromList [('a',"alpha"),('b',"beta")]
--
--
-- -- >>> toMapOf (ifolded <%> ifolded) ["foo", "bar"] -- fromList [((0,0),'f'),((0,1),'o'),((0,2),'o'),((1,0),'b'),((1,1),'a'),((1,2),'r')] ---- --
-- >>> toMapOf (folded % ifolded) [('a', "hello"), ('b', "world"), ('a', "dummy")]
-- fromList [('a',"hello"),('b',"world")]
--
toMapOf :: (Is k A_Fold, is `HasSingleIndex` i, Ord i) => Optic' k is s a -> s -> Map i a
-- | Focus on the largest key smaller than the given one and its
-- corresponding value.
--
--
-- >>> Map.fromList [('a', "hi"), ('b', "there")] & over (lt 'b') (++ "!")
-- fromList [('a',"hi!"),('b',"there")]
--
--
--
-- >>> ipreview (lt 'a') $ Map.fromList [('a', 'x'), ('b', 'y')]
-- Nothing
--
lt :: Ord k => k -> IxAffineTraversal' k (Map k v) v
-- | Focus on the smallest key greater than the given one and its
-- corresponding value.
--
--
-- >>> Map.fromList [('a', "hi"), ('b', "there")] & over (gt 'b') (++ "!")
-- fromList [('a',"hi"),('b',"there")]
--
--
--
-- >>> ipreview (gt 'a') $ Map.fromList [('a', 'x'), ('b', 'y')]
-- Just ('b','y')
--
gt :: Ord k => k -> IxAffineTraversal' k (Map k v) v
-- | Focus on the largest key smaller or equal than the given one and its
-- corresponding value.
--
--
-- >>> Map.fromList [('a', "hi"), ('b', "there")] & over (le 'b') (++ "!")
-- fromList [('a',"hi"),('b',"there!")]
--
--
--
-- >>> ipreview (le 'a') $ Map.fromList [('a', 'x'), ('b', 'y')]
-- Just ('a','x')
--
le :: Ord k => k -> IxAffineTraversal' k (Map k v) v
-- | Focus on the smallest key greater or equal than the given one and its
-- corresponding value.
--
--
-- >>> Map.fromList [('a', "hi"), ('c', "there")] & over (ge 'b') (++ "!")
-- fromList [('a',"hi"),('c',"there!")]
--
--
--
-- >>> ipreview (ge 'b') $ Map.fromList [('a', 'x'), ('c', 'y')]
-- Just ('c','y')
--
ge :: Ord k => k -> IxAffineTraversal' k (Map k v) v
-- | IntMap is an instance of At and provides at as a
-- lens on values at keys:
--
-- -- >>> IntMap.fromList [(1, "world")] ^. at 1 -- Just "world" ---- --
-- >>> IntMap.empty & at 1 .~ Just "world" -- fromList [(1,"world")] ---- --
-- >>> IntMap.empty & at 0 .~ Just "hello" -- fromList [(0,"hello")] ---- -- We can traverse, fold over, and map over key-value pairs in an -- IntMap, thanks to indexed traversals, folds and setters. -- --
-- >>> iover imapped const $ IntMap.fromList [(1, "Venus")] -- fromList [(1,1)] ---- --
-- >>> ifoldMapOf ifolded (\i _ -> Sum i) $ IntMap.fromList [(2, "Earth"), (3, "Mars")]
-- Sum {getSum = 5}
--
--
-- -- >>> itraverseOf_ ifolded (curry print) $ IntMap.fromList [(4, "Jupiter")] -- (4,"Jupiter") ---- --
-- >>> itoListOf ifolded $ IntMap.fromList [(5, "Saturn")] -- [(5,"Saturn")] ---- -- A related class, Ixed, allows us to use ix to traverse a -- value at a particular key. -- --
-- >>> IntMap.fromList [(2, "Earth")] & ix 2 %~ ("New " ++)
-- fromList [(2,"New Earth")]
--
--
-- -- >>> preview (ix 8) IntMap.empty -- Nothing --module Data.IntMap.Optics -- | Construct a map from an IxFold. -- -- The construction is left-biased (see union), i.e. the first -- occurrences of keys in the fold or traversal order are preferred. -- --
-- >>> toMapOf ifolded ["hello", "world"] -- fromList [(0,"hello"),(1,"world")] ---- --
-- >>> toMapOf (folded % ifolded) [(1,"alpha"),(2, "beta")] -- fromList [(1,"alpha"),(2,"beta")] ---- --
-- >>> toMapOf (icompose (\a b -> 10*a+b) $ ifolded % ifolded) ["foo", "bar"] -- fromList [(0,'f'),(1,'o'),(2,'o'),(10,'b'),(11,'a'),(12,'r')] ---- --
-- >>> toMapOf (folded % ifolded) [(1, "hello"), (2, "world"), (1, "dummy")] -- fromList [(1,"hello"),(2,"world")] --toMapOf :: (Is k A_Fold, is `HasSingleIndex` Int) => Optic' k is s a -> s -> IntMap a -- | Focus on the largest key smaller than the given one and its -- corresponding value. -- --
-- >>> IntMap.fromList [(1, "hi"), (2, "there")] & over (lt 2) (++ "!") -- fromList [(1,"hi!"),(2,"there")] ---- --
-- >>> ipreview (lt 1) $ IntMap.fromList [(1, 'x'), (2, 'y')] -- Nothing --lt :: Int -> IxAffineTraversal' Int (IntMap v) v -- | Focus on the smallest key greater than the given one and its -- corresponding value. -- --
-- >>> IntMap.fromList [(1, "hi"), (2, "there")] & over (gt 2) (++ "!") -- fromList [(1,"hi"),(2,"there")] ---- --
-- >>> ipreview (gt 1) $ IntMap.fromList [(1, 'x'), (2, 'y')] -- Just (2,'y') --gt :: Int -> IxAffineTraversal' Int (IntMap v) v -- | Focus on the largest key smaller or equal than the given one and its -- corresponding value. -- --
-- >>> IntMap.fromList [(1, "hi"), (2, "there")] & over (le 2) (++ "!") -- fromList [(1,"hi"),(2,"there!")] ---- --
-- >>> ipreview (le 1) $ IntMap.fromList [(1, 'x'), (2, 'y')] -- Just (1,'x') --le :: Int -> IxAffineTraversal' Int (IntMap v) v -- | Focus on the smallest key greater or equal than the given one and its -- corresponding value. -- --
-- >>> IntMap.fromList [(1, "hi"), (3, "there")] & over (ge 2) (++ "!") -- fromList [(1,"hi"),(3,"there!")] ---- --
-- >>> ipreview (ge 2) $ IntMap.fromList [(1, 'x'), (3, 'y')] -- Just (3,'y') --ge :: Int -> IxAffineTraversal' Int (IntMap v) v -- | A Prism generalises the notion of a constructor (just as a -- Lens generalises the notion of a field). module Optics.Prism -- | Type synonym for a type-modifying prism. type Prism s t a b = Optic A_Prism NoIx s t a b -- | Type synonym for a type-preserving prism. type Prism' s a = Optic' A_Prism NoIx s a -- | Build 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. prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b -- | This is usually used to build a Prism', when you have to use an -- operation like cast which already returns a Maybe. prism' :: (b -> s) -> (s -> Maybe a) -> Prism s s a b -- | This Prism compares for exact equality with a given value. -- --
-- >>> only 4 # () -- 4 ---- --
-- >>> 5 ^? only 4 -- Nothing --only :: Eq a => a -> Prism' a () -- | 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. nearly :: a -> (a -> Bool) -> Prism' a () -- | Work with a Prism as a constructor and a matcher. withPrism :: Is k A_Prism => Optic k is s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r -- | Use a Prism to work over part of a structure. aside :: Is k A_Prism => Optic k is s t a b -> Prism (e, s) (e, t) (e, a) (e, b) -- | Given a pair of prisms, project sums. -- -- Viewing a Prism as a co-Lens, this combinator can be -- seen to be dual to alongside. without :: (Is k A_Prism, Is l A_Prism) => Optic k is s t a b -> Optic l is u v c d -> Prism (Either s u) (Either t v) (Either a c) (Either b d) -- | Lift a Prism through a Traversable functor, giving a -- Prism that matches only if all the elements of the container -- match the Prism. below :: (Is k A_Prism, Traversable f) => Optic' k is s a -> Prism' (f s) (f a) -- | Tag for a prism. data A_Prism :: OpticKind -- | This module defines Prisms for the constructors of the -- Maybe datatype. module Data.Maybe.Optics -- | A Prism that matches on the Nothing constructor of -- Maybe. _Nothing :: Prism' (Maybe a) () -- | A Prism that matches on the Just constructor of -- Maybe. _Just :: Prism (Maybe a) (Maybe b) a b -- | Additional optics for manipulating lists are present more generically -- in this package. -- -- The Ixed class allows traversing the element at a specific list -- index. -- --
-- >>> [0..10] ^? ix 4 -- Just 4 ---- --
-- >>> [0..5] & ix 4 .~ 2 -- [0,1,2,3,2,5] ---- --
-- >>> [0..10] ^? ix 14 -- Nothing ---- --
-- >>> [0..5] & ix 14 .~ 2 -- [0,1,2,3,4,5] ---- -- The Cons and AsEmpty classes provide Prisms for -- list constructors. -- --
-- >>> [1..10] ^? _Cons -- Just (1,[2,3,4,5,6,7,8,9,10]) ---- --
-- >>> [] ^? _Cons -- Nothing ---- --
-- >>> [] ^? _Empty -- Just () ---- --
-- >>> _Cons # (1, _Empty # ()) :: [Int] -- [1] ---- -- Additionally, Snoc provides a Prism for accessing the -- end of a list. Note that this Prism always will need to -- traverse the whole list. -- --
-- >>> [1..5] ^? _Snoc -- Just ([1,2,3,4],5) ---- --
-- >>> _Snoc # ([1,2],5) -- [1,2,5] ---- -- Finally, it's possible to traverse, fold over, and map over -- index-value pairs thanks to instances of TraversableWithIndex, -- FoldableWithIndex, and FunctorWithIndex. -- --
-- >>> imap (,) "Hello" -- [(0,'H'),(1,'e'),(2,'l'),(3,'l'),(4,'o')] ---- --
-- >>> ifoldMap replicate "Hello" -- "ellllloooo" ---- --
-- >>> itraverse_ (curry print) "Hello" -- (0,'H') -- (1,'e') -- (2,'l') -- (3,'l') -- (4,'o') --module Data.List.Optics -- | A Prism stripping a prefix from a list when used as a -- Traversal, or prepending that prefix when run backwards: -- --
-- >>> "preview" ^? prefixed "pre" -- Just "view" ---- --
-- >>> "review" ^? prefixed "pre" -- Nothing ---- --
-- >>> prefixed "pre" # "amble" -- "preamble" --prefixed :: Eq a => [a] -> Prism' [a] [a] -- | A Prism stripping a suffix from a list when used as a -- Traversal, or appending that suffix when run backwards: -- --
-- >>> "review" ^? suffixed "view" -- Just "re" ---- --
-- >>> "review" ^? suffixed "tire" -- Nothing ---- --
-- >>> suffixed ".o" # "hello" -- "hello.o" --suffixed :: Eq a => [a] -> Prism' [a] [a] -- | This module defines Prisms for the constructors of the -- Either datatype. module Data.Either.Optics -- | A Prism that matches on the Left constructor of -- Either. _Left :: Prism (Either a b) (Either c b) a c -- | A Prism that matches on the Right constructor of -- Either. _Right :: Prism (Either a b) (Either a c) b c -- | Some optics can be reversed with re. This is mainly useful to -- invert Isos: -- --
-- >>> let _Identity = iso runIdentity Identity
--
-- >>> view (_1 % re _Identity) ('x', "yz")
-- Identity 'x'
--
--
-- Yet we can use a Lens as a Review too:
--
--
-- >>> review (re _1) ('x', "yz")
-- 'x'
--
--
-- In the following diagram, red arrows illustrate how re
-- transforms optics. The ReversedLens and ReversedPrism
-- optic kinds are backwards versions of Lens and Prism
-- respectively, and are present so that re . re
-- does not change the optic kind.
--
module Optics.Re
-- | Class for optics that can be reversed.
class ReversibleOptic k where {
-- | Injective type family that maps an optic kind to the optic kind
-- produced by reversing it.
--
--
-- ReversedOptic An_Iso = An_Iso
-- ReversedOptic A_Prism = A_ReversedPrism
-- ReversedOptic A_ReversedPrism = A_Prism
-- ReversedOptic A_Lens = A_ReversedLens
-- ReversedOptic A_ReversedLens = A_Lens
-- ReversedOptic A_Getter = A_Review
-- ReversedOptic A_Review = A_Getter
--
type family ReversedOptic k = r | r -> k;
}
-- | Reverses optics, turning around Iso into Iso,
-- Prism into ReversedPrism (and back), Lens into
-- ReversedLens (and back) and Getter into Review
-- (and back).
re :: (ReversibleOptic k, "re" `AcceptsEmptyIndices` is) => Optic k is s t a b -> Optic (ReversedOptic k) is b a t s
instance Data.Profunctor.Indexed.Profunctor p => Data.Profunctor.Indexed.Profunctor (Optics.Re.Re p s t)
instance Optics.Internal.Bi.Bicontravariant p => Optics.Internal.Bi.Bifunctor (Optics.Re.Re p s t)
instance Optics.Internal.Bi.Bifunctor p => Optics.Internal.Bi.Bicontravariant (Optics.Re.Re p s t)
instance Data.Profunctor.Indexed.Strong p => Data.Profunctor.Indexed.Costrong (Optics.Re.Re p s t)
instance Data.Profunctor.Indexed.Costrong p => Data.Profunctor.Indexed.Strong (Optics.Re.Re p s t)
instance Data.Profunctor.Indexed.Choice p => Data.Profunctor.Indexed.Cochoice (Optics.Re.Re p s t)
instance Data.Profunctor.Indexed.Cochoice p => Data.Profunctor.Indexed.Choice (Optics.Re.Re p s t)
instance Optics.Re.ReversibleOptic Optics.Internal.Optic.Types.An_Iso
instance Optics.Re.ReversibleOptic Optics.Internal.Optic.Types.A_Prism
instance Optics.Re.ReversibleOptic Optics.Internal.Optic.Types.A_ReversedPrism
instance Optics.Re.ReversibleOptic Optics.Internal.Optic.Types.A_Lens
instance Optics.Re.ReversibleOptic Optics.Internal.Optic.Types.A_ReversedLens
instance Optics.Re.ReversibleOptic Optics.Internal.Optic.Types.A_Getter
instance Optics.Re.ReversibleOptic Optics.Internal.Optic.Types.A_Review
-- | This module defines getting, which turns a read-write optic
-- into its read-only counterpart.
module Optics.ReadOnly
-- | Class for read-write optics that have their read-only counterparts.
class ToReadOnly k s t a b
-- | Turn read-write optic into its read-only counterpart (or leave
-- read-only optics as-is).
--
-- This is useful when you have an optic :: Optic k is s t a
-- b of read-write kind k such that s, t,
-- a, b are rigid, there is no evidence that s ~
-- t and a ~ b and you want to pass optic to one
-- of the functions that accept read-only optic kinds.
--
-- Example:
--
-- -- >>> let fstIntToChar = _1 :: Lens (Int, r) (Char, r) Int Char ---- --
-- >>> :t view fstIntToChar -- ... -- ...Couldn't match type ‘Char’ with ‘Int’ -- ... ---- --
-- >>> :t view (getting fstIntToChar) -- view (getting fstIntToChar) :: (Int, r) -> Int --getting :: ToReadOnly k s t a b => Optic k is s t a b -> Optic' (Join A_Getter k) is s a instance Optics.ReadOnly.ToReadOnly Optics.Internal.Optic.Types.An_Iso s t a b instance Optics.ReadOnly.ToReadOnly Optics.Internal.Optic.Types.A_Lens s t a b instance Optics.ReadOnly.ToReadOnly Optics.Internal.Optic.Types.A_Prism s t a b instance Optics.ReadOnly.ToReadOnly Optics.Internal.Optic.Types.An_AffineTraversal s t a b instance Optics.ReadOnly.ToReadOnly Optics.Internal.Optic.Types.A_Traversal s t a b instance Optics.ReadOnly.ToReadOnly Optics.Internal.Optic.Types.A_ReversedPrism s t a b instance (s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.ReadOnly.ToReadOnly Optics.Internal.Optic.Types.A_Getter s t a b instance (s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.ReadOnly.ToReadOnly Optics.Internal.Optic.Types.An_AffineFold s t a b instance (s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.ReadOnly.ToReadOnly Optics.Internal.Optic.Types.A_Fold s t a b -- | A ReversedLens is a backwards Lens, i.e. a -- ReversedLens s t a b is equivalent to a -- Lens b a t s. These are typically produced by calling -- re on a Lens. They are distinguished from a -- Review so that re . re on a Lens -- returns a Lens. module Optics.ReversedLens -- | Type synonym for a type-modifying reversed lens. type ReversedLens s t a b = Optic A_ReversedLens NoIx s t a b -- | Type synonym for a type-preserving reversed lens. type ReversedLens' t b = Optic' A_ReversedLens NoIx t b -- | Tag for a reversed lens. data A_ReversedLens :: OpticKind -- | A ReversedPrism is a backwards Prism, i.e. a -- ReversedPrism s t a b is equivalent to a -- Prism b a t s. These are typically produced by calling -- re on a Prism. They are distinguished from a -- Getter so that re . re on a Prism -- returns a Prism. module Optics.ReversedPrism -- | Type synonym for a type-modifying reversed prism. type ReversedPrism s t a b = Optic A_ReversedPrism NoIx s t a b -- | Type synonym for a type-preserving reversed prism. type ReversedPrism' s a = Optic' A_ReversedPrism NoIx s a -- | Tag for a reversed prism. data A_ReversedPrism :: OpticKind -- | A Review is a backwards Getter, i.e. a Review -- T B is just a function B -> T. module Optics.Review -- | Type synonym for a review. type Review t b = Optic' A_Review NoIx t b -- | An analogue of to for reviews. unto :: (b -> t) -> Review t b -- | Retrieve the value targeted by a Review. -- --
-- >>> review _Left "hi" -- Left "hi" --review :: Is k A_Review => Optic' k is t b -> b -> t -- | Tag for a review. data A_Review :: OpticKind -- | An Isomorphism expresses the fact that two types have the same -- structure, and hence can be converted from one to the other in either -- direction. module Optics.Iso -- | Type synonym for a type-modifying iso. type Iso s t a b = Optic An_Iso NoIx s t a b -- | Type synonym for a type-preserving iso. type Iso' s a = Optic' An_Iso NoIx s a -- | Build an iso from a pair of inverse functions. -- -- If you want to build an Iso from the van Laarhoven -- representation, use isoVL from the optics-vl -- package. iso :: (s -> a) -> (b -> t) -> Iso s t a b -- | Capture type constraints as an isomorphism. -- -- Note: This is the identity optic: -- --
-- >>> :t view equality -- view equality :: a -> a --equality :: (s ~ a, t ~ b) => Iso s t a b -- | Proof of reflexivity. simple :: Iso' a a -- | Data types that are representationally equal are isomorphic. -- --
-- >>> view coerced 'x' :: Identity Char -- Identity 'x' --coerced :: (Coercible s a, Coercible t b) => Iso s t a b -- | Type-preserving version of coerced with type parameters -- rearranged for TypeApplications. -- --
-- >>> newtype MkInt = MkInt Int deriving Show ---- --
-- >>> over (coercedTo @Int) (*3) (MkInt 2) -- MkInt 6 --coercedTo :: forall a s. Coercible s a => Iso' s a -- | Special case of coerced for trivial newtype wrappers. -- --
-- >>> over (coerced1 @Identity) (++ "bar") (Identity "foo") -- Identity "foobar" --coerced1 :: forall f s a. (Coercible s (f s), Coercible a (f a)) => Iso (f s) (f a) s a -- | If v is an element of a type a, and a' is -- a sans the element v, then non v is -- an isomorphism from Maybe a' to a. -- --
-- non ≡ non' . only ---- -- Keep in mind this is only a real isomorphism if you treat the domain -- as being Maybe (a sans v). -- -- This is practically quite useful when you want to have a Map -- where all the entries should have non-zero values. -- --
-- >>> Map.fromList [("hello",1)] & at "hello" % non 0 %~ (+2)
-- fromList [("hello",3)]
--
--
--
-- >>> Map.fromList [("hello",1)] & at "hello" % non 0 %~ (subtract 1)
-- fromList []
--
--
--
-- >>> Map.fromList [("hello",1)] ^. at "hello" % non 0
-- 1
--
--
-- -- >>> Map.fromList [] ^. at "hello" % non 0 -- 0 ---- -- This combinator is also particularly useful when working with nested -- maps. -- -- e.g. When you want to create the nested Map when it is -- missing: -- --
-- >>> Map.empty & at "hello" % non Map.empty % at "world" ?~ "!!!"
-- fromList [("hello",fromList [("world","!!!")])]
--
--
-- and when have deleting the last entry from the nested Map mean
-- that we should delete its entry from the surrounding one:
--
--
-- >>> Map.fromList [("hello", Map.fromList [("world","!!!")])] & at "hello" % non Map.empty % at "world" .~ Nothing
-- fromList []
--
--
-- It can also be used in reverse to exclude a given value:
--
-- -- >>> non 0 # rem 10 4 -- Just 2 ---- --
-- >>> non 0 # rem 10 5 -- Nothing --non :: Eq a => a -> Iso' (Maybe a) a -- | non' p generalizes non (p # ()) to -- take any unit Prism -- -- This function generates an isomorphism between Maybe (a | -- isn't p a) and a. -- --
-- >>> Map.singleton "hello" Map.empty & at "hello" % non' _Empty % at "world" ?~ "!!!"
-- fromList [("hello",fromList [("world","!!!")])]
--
--
--
-- >>> Map.fromList [("hello", Map.fromList [("world","!!!")])] & at "hello" % non' _Empty % at "world" .~ Nothing
-- fromList []
--
non' :: Prism' a () -> Iso' (Maybe a) a
-- | anon a p generalizes non a to take any
-- value and a predicate.
--
-- -- anon a ≡ non' . nearly a ---- -- This function assumes that p a holds True and -- generates an isomorphism between Maybe (a | not (p -- a)) and a. -- --
-- >>> Map.empty & at "hello" % anon Map.empty Map.null % at "world" ?~ "!!!"
-- fromList [("hello",fromList [("world","!!!")])]
--
--
--
-- >>> Map.fromList [("hello", Map.fromList [("world","!!!")])] & at "hello" % anon Map.empty Map.null % at "world" .~ Nothing
-- fromList []
--
anon :: a -> (a -> Bool) -> Iso' (Maybe a) a
-- | The canonical isomorphism for currying and uncurrying a function.
--
-- -- curried = iso curry uncurry ---- --
-- >>> view curried fst 3 4 -- 3 --curried :: Iso ((a, b) -> c) ((d, e) -> f) (a -> b -> c) (d -> e -> f) -- | The canonical isomorphism for uncurrying and currying a function. -- --
-- uncurried = iso uncurry curry ---- --
-- uncurried = re curried ---- --
-- >>> (view uncurried (+)) (1,2) -- 3 --uncurried :: Iso (a -> b -> c) (d -> e -> f) ((a, b) -> c) ((d, e) -> f) -- | The isomorphism for flipping a function. -- --
-- >>> (view flipped (,)) 1 2 -- (2,1) --flipped :: Iso (a -> b -> c) (a' -> b' -> c') (b -> a -> c) (b' -> a' -> c') -- | Given a function that is its own inverse, this gives you an Iso -- using it in both directions. -- --
-- involuted ≡ join iso ---- --
-- >>> "live" ^. involuted reverse -- "evil" ---- --
-- >>> "live" & involuted reverse %~ ('d':)
-- "lived"
--
involuted :: (a -> a) -> Iso' a a
-- | This class provides for symmetric bifunctors.
class Bifunctor p => Swapped p
-- | -- swapped . swapped ≡ id -- first f . swapped = swapped . second f -- second g . swapped = swapped . first g -- bimap f g . swapped = swapped . bimap g f ---- --
-- >>> view swapped (1,2) -- (2,1) --swapped :: Swapped p => Iso (p a b) (p c d) (p b a) (p d c) -- | Extract the two components of an isomorphism. withIso :: Iso s t a b -> ((s -> a) -> (b -> t) -> r) -> r -- | Based on ala from Conor McBride's work on Epigram. -- -- This version is generalized to accept any Iso, not just a -- newtype. -- --
-- >>> au (coerced1 @Sum) foldMap [1,2,3,4] -- 10 ---- -- You may want to think of this combinator as having the following, -- simpler type: -- --
-- au :: Iso s t a b -> ((b -> t) -> e -> s) -> e -> a --au :: Functor f => Iso s t a b -> ((b -> t) -> f s) -> f a -- | The opposite of working over a Setter is working -- under an isomorphism. -- --
-- under ≡ over . re --under :: Iso s t a b -> (t -> s) -> b -> a -- | Tag for an iso. data An_Iso :: OpticKind instance Optics.Iso.Swapped (,) instance Optics.Iso.Swapped Data.Either.Either -- | This module defines mapping, which turns an Optic' k -- NoIx s a into an Optic' (MappedOptic k) -- NoIx (f s) (f a), in other words optic operating on values -- in a Functor. module Optics.Mapping -- | Class for optics supporting mapping through a Functor. class MappingOptic k f g s t a b where { -- | Type family that maps an optic to the optic kind produced by -- mapping using it. type family MappedOptic k; } -- | The mapping can be used to lift optic through a Functor. -- --
-- mapping :: Iso s t a b -> Iso (f s) (g t) (f a) (g b) -- mapping :: Lens s a -> Getter (f s) (f a) -- mapping :: Getter s a -> Getter (f s) (f a) -- mapping :: Prism t b -> Review (g t) (g b) -- mapping :: Review t b -> Review (g t) (g b) --mapping :: (MappingOptic k f g s t a b, "mapping" `AcceptsEmptyIndices` is) => Optic k is s t a b -> Optic (MappedOptic k) is (f s) (g t) (f a) (g b) instance (GHC.Base.Functor f, GHC.Base.Functor g) => Optics.Mapping.MappingOptic Optics.Internal.Optic.Types.An_Iso f g s t a b instance (GHC.Base.Functor f, f Data.Type.Equality.~ g, s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.Mapping.MappingOptic Optics.Internal.Optic.Types.A_Getter f g s t a b instance (GHC.Base.Functor f, f Data.Type.Equality.~ g, s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.Mapping.MappingOptic Optics.Internal.Optic.Types.A_ReversedPrism f g s t a b instance (GHC.Base.Functor f, f Data.Type.Equality.~ g, s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.Mapping.MappingOptic Optics.Internal.Optic.Types.A_Lens f g s t a b instance (GHC.Base.Functor f, f Data.Type.Equality.~ g, s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.Mapping.MappingOptic Optics.Internal.Optic.Types.A_Review f g s t a b instance (GHC.Base.Functor f, f Data.Type.Equality.~ g, s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.Mapping.MappingOptic Optics.Internal.Optic.Types.A_Prism f g s t a b instance (GHC.Base.Functor f, f Data.Type.Equality.~ g, s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.Mapping.MappingOptic Optics.Internal.Optic.Types.A_ReversedLens f g s t a b -- | Note: GHC.Generics exports a number of names that collide with -- Optics (at least to). -- -- You can use hiding or imports to mitigate this to an extent, and the -- following imports, represent a fair compromise for user code: -- --
-- import Optics -- import GHC.Generics hiding (to) -- import GHC.Generics.Optics ---- -- You can use generic to replace from and to from -- GHC.Generics. module GHC.Generics.Optics -- | Convert from the data type to its representation (or back) -- --
-- >>> view (generic % re generic) "hello" :: String -- "hello" --generic :: (Generic a, Generic b) => Iso a b (Rep a c) (Rep b c) -- | Convert from the data type to its representation (or back) generic1 :: (Generic1 f, Generic1 g) => Iso (f a) (g b) (Rep1 f a) (Rep1 g b) _V1 :: Lens (V1 s) (V1 t) a b _U1 :: Iso (U1 p) (U1 q) () () _Par1 :: Iso (Par1 p) (Par1 q) p q _Rec1 :: Iso (Rec1 f p) (Rec1 g q) (f p) (g q) _K1 :: Iso (K1 i c p) (K1 j d q) c d _M1 :: Iso (M1 i c f p) (M1 j d g q) (f p) (g q) _L1 :: Prism ((a :+: c) t) ((b :+: c) t) (a t) (b t) _R1 :: Prism ((c :+: a) t) ((c :+: b) t) (a t) (b t) -- | This module defines Lenses for the fields of tuple types. These -- are overloaded using the Field1 to Field9 typeclasses, -- so that _1 can be used as a Lens for the first field of -- a tuple with any number of fields (up to the maximum supported tuple -- size, which is currently 9). For example: -- --
-- >>> view _1 ('a','b','c')
-- 'a'
--
--
--
-- >>> set _3 True ('a','b','c')
-- ('a','b',True)
--
--
-- If a single-constructor datatype has a Generic instance, the
-- corresponding FieldN instances can be defined using their
-- default methods:
--
-- -- >>> :set -XDeriveGeneric -- -- >>> data T a = MkT Int a deriving (Generic, Show) -- -- >>> instance Field1 (T a) (T a) Int Int -- -- >>> instance Field2 (T a) (T b) a b ---- --
-- >>> set _2 'x' (MkT 1 False) -- MkT 1 'x' --module Data.Tuple.Optics -- | Provides access to 1st field of a tuple. class Field1 s t a b | s -> a, t -> b, s b -> t, t a -> s -- | Access the 1st field of a tuple (and possibly change its type). -- --
-- >>> (1,2) ^. _1 -- 1 ---- --
-- >>> (1,2) & _1 .~ "hello"
-- ("hello",2)
--
--
--
-- >>> traverseOf _1 putStrLn ("hello","world")
-- hello
-- ((),"world")
--
--
-- This can also be used on larger tuples as well:
--
-- -- >>> (1,2,3,4,5) & _1 %~ (+41) -- (42,2,3,4,5) --_1 :: Field1 s t a b => Lens s t a b -- | Access the 1st field of a tuple (and possibly change its type). -- --
-- >>> (1,2) ^. _1 -- 1 ---- --
-- >>> (1,2) & _1 .~ "hello"
-- ("hello",2)
--
--
--
-- >>> traverseOf _1 putStrLn ("hello","world")
-- hello
-- ((),"world")
--
--
-- This can also be used on larger tuples as well:
--
-- -- >>> (1,2,3,4,5) & _1 %~ (+41) -- (42,2,3,4,5) --_1 :: (Field1 s t a b, Generic s, Generic t, GIxed N0 (Rep s) (Rep t) a b) => Lens s t a b -- | Provides access to the 2nd field of a tuple. class Field2 s t a b | s -> a, t -> b, s b -> t, t a -> s -- | Access the 2nd field of a tuple. -- --
-- >>> _2 .~ "hello" $ (1,(),3,4) -- (1,"hello",3,4) ---- --
-- >>> (1,2,3,4) & _2 %~ (*3) -- (1,6,3,4) ---- --
-- >>> traverseOf _2 print (1,2) -- 2 -- (1,()) --_2 :: Field2 s t a b => Lens s t a b -- | Access the 2nd field of a tuple. -- --
-- >>> _2 .~ "hello" $ (1,(),3,4) -- (1,"hello",3,4) ---- --
-- >>> (1,2,3,4) & _2 %~ (*3) -- (1,6,3,4) ---- --
-- >>> traverseOf _2 print (1,2) -- 2 -- (1,()) --_2 :: (Field2 s t a b, Generic s, Generic t, GIxed N1 (Rep s) (Rep t) a b) => Lens s t a b -- | Provides access to the 3rd field of a tuple. class Field3 s t a b | s -> a, t -> b, s b -> t, t a -> s -- | Access the 3rd field of a tuple. _3 :: Field3 s t a b => Lens s t a b -- | Access the 3rd field of a tuple. _3 :: (Field3 s t a b, Generic s, Generic t, GIxed N2 (Rep s) (Rep t) a b) => Lens s t a b -- | Provide access to the 4th field of a tuple. class Field4 s t a b | s -> a, t -> b, s b -> t, t a -> s -- | Access the 4th field of a tuple. _4 :: Field4 s t a b => Lens s t a b -- | Access the 4th field of a tuple. _4 :: (Field4 s t a b, Generic s, Generic t, GIxed N3 (Rep s) (Rep t) a b) => Lens s t a b -- | Provides access to the 5th field of a tuple. class Field5 s t a b | s -> a, t -> b, s b -> t, t a -> s -- | Access the 5th field of a tuple. _5 :: Field5 s t a b => Lens s t a b -- | Access the 5th field of a tuple. _5 :: (Field5 s t a b, Generic s, Generic t, GIxed N4 (Rep s) (Rep t) a b) => Lens s t a b -- | Provides access to the 6th element of a tuple. class Field6 s t a b | s -> a, t -> b, s b -> t, t a -> s -- | Access the 6th field of a tuple. _6 :: Field6 s t a b => Lens s t a b -- | Access the 6th field of a tuple. _6 :: (Field6 s t a b, Generic s, Generic t, GIxed N5 (Rep s) (Rep t) a b) => Lens s t a b -- | Provide access to the 7th field of a tuple. class Field7 s t a b | s -> a, t -> b, s b -> t, t a -> s -- | Access the 7th field of a tuple. _7 :: Field7 s t a b => Lens s t a b -- | Access the 7th field of a tuple. _7 :: (Field7 s t a b, Generic s, Generic t, GIxed N6 (Rep s) (Rep t) a b) => Lens s t a b -- | Provide access to the 8th field of a tuple. class Field8 s t a b | s -> a, t -> b, s b -> t, t a -> s -- | Access the 8th field of a tuple. _8 :: Field8 s t a b => Lens s t a b -- | Access the 8th field of a tuple. _8 :: (Field8 s t a b, Generic s, Generic t, GIxed N7 (Rep s) (Rep t) a b) => Lens s t a b -- | Provides access to the 9th field of a tuple. class Field9 s t a b | s -> a, t -> b, s b -> t, t a -> s -- | Access the 9th field of a tuple. _9 :: Field9 s t a b => Lens s t a b -- | Access the 9th field of a tuple. _9 :: (Field9 s t a b, Generic s, Generic t, GIxed N8 (Rep s) (Rep t) a b) => Lens s t a b -- | Strict version of _1 _1' :: Field1 s t a b => Lens s t a b -- | Strict version of _2 _2' :: Field2 s t a b => Lens s t a b -- | Strict version of _3 _3' :: Field3 s t a b => Lens s t a b -- | Strict version of _4 _4' :: Field4 s t a b => Lens s t a b -- | Strict version of _5 _5' :: Field5 s t a b => Lens s t a b -- | Strict version of _6 _6' :: Field6 s t a b => Lens s t a b -- | Strict version of _7 _7' :: Field7 s t a b => Lens s t a b -- | Strict version of _8 _8' :: Field8 s t a b => Lens s t a b -- | Strict version of _9 _9' :: Field9 s t a b => Lens s t a b instance Data.Tuple.Optics.Field9 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i') i i' instance Data.Tuple.Optics.Field8 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h') h h' instance Data.Tuple.Optics.Field8 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h', i) h h' instance Data.Tuple.Optics.Field7 (a, b, c, d, e, f, g) (a, b, c, d, e, f, g') g g' instance Data.Tuple.Optics.Field7 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g', h) g g' instance Data.Tuple.Optics.Field7 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g', h, i) g g' instance Data.Tuple.Optics.Field6 (a, b, c, d, e, f) (a, b, c, d, e, f') f f' instance Data.Tuple.Optics.Field6 (a, b, c, d, e, f, g) (a, b, c, d, e, f', g) f f' instance Data.Tuple.Optics.Field6 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f', g, h) f f' instance Data.Tuple.Optics.Field6 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f', g, h, i) f f' instance Data.Tuple.Optics.Field5 (a, b, c, d, e) (a, b, c, d, e') e e' instance Data.Tuple.Optics.Field5 (a, b, c, d, e, f) (a, b, c, d, e', f) e e' instance Data.Tuple.Optics.Field5 (a, b, c, d, e, f, g) (a, b, c, d, e', f, g) e e' instance Data.Tuple.Optics.Field5 (a, b, c, d, e, f, g, h) (a, b, c, d, e', f, g, h) e e' instance Data.Tuple.Optics.Field5 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e', f, g, h, i) e e' instance Data.Tuple.Optics.Field4 (a, b, c, d) (a, b, c, d') d d' instance Data.Tuple.Optics.Field4 (a, b, c, d, e) (a, b, c, d', e) d d' instance Data.Tuple.Optics.Field4 (a, b, c, d, e, f) (a, b, c, d', e, f) d d' instance Data.Tuple.Optics.Field4 (a, b, c, d, e, f, g) (a, b, c, d', e, f, g) d d' instance Data.Tuple.Optics.Field4 (a, b, c, d, e, f, g, h) (a, b, c, d', e, f, g, h) d d' instance Data.Tuple.Optics.Field4 (a, b, c, d, e, f, g, h, i) (a, b, c, d', e, f, g, h, i) d d' instance Data.Tuple.Optics.Field3 (a, b, c) (a, b, c') c c' instance Data.Tuple.Optics.Field3 (a, b, c, d) (a, b, c', d) c c' instance Data.Tuple.Optics.Field3 (a, b, c, d, e) (a, b, c', d, e) c c' instance Data.Tuple.Optics.Field3 (a, b, c, d, e, f) (a, b, c', d, e, f) c c' instance Data.Tuple.Optics.Field3 (a, b, c, d, e, f, g) (a, b, c', d, e, f, g) c c' instance Data.Tuple.Optics.Field3 (a, b, c, d, e, f, g, h) (a, b, c', d, e, f, g, h) c c' instance Data.Tuple.Optics.Field3 (a, b, c, d, e, f, g, h, i) (a, b, c', d, e, f, g, h, i) c c' instance Data.Tuple.Optics.Field2 (Data.Functor.Product.Product f g a) (Data.Functor.Product.Product f g' a) (g a) (g' a) instance Data.Tuple.Optics.Field2 ((GHC.Generics.:*:) f g p) ((GHC.Generics.:*:) f g' p) (g p) (g' p) instance Data.Tuple.Optics.Field2 (a, b) (a, b') b b' instance Data.Tuple.Optics.Field2 (a, b, c) (a, b', c) b b' instance Data.Tuple.Optics.Field2 (a, b, c, d) (a, b', c, d) b b' instance Data.Tuple.Optics.Field2 (a, b, c, d, e) (a, b', c, d, e) b b' instance Data.Tuple.Optics.Field2 (a, b, c, d, e, f) (a, b', c, d, e, f) b b' instance Data.Tuple.Optics.Field2 (a, b, c, d, e, f, g) (a, b', c, d, e, f, g) b b' instance Data.Tuple.Optics.Field2 (a, b, c, d, e, f, g, h) (a, b', c, d, e, f, g, h) b b' instance Data.Tuple.Optics.Field2 (a, b, c, d, e, f, g, h, i) (a, b', c, d, e, f, g, h, i) b b' instance (Data.Tuple.Optics.GT (Data.Tuple.Optics.GSize s) n Data.Type.Equality.~ Data.Tuple.Optics.F, n' Data.Type.Equality.~ Data.Tuple.Optics.Subtract (Data.Tuple.Optics.GSize s) n, Data.Tuple.Optics.GIxed n' s' t' a b) => Data.Tuple.Optics.GIxed' Data.Tuple.Optics.F n s s' s t' a b instance Data.Tuple.Optics.Field1 (Data.Functor.Identity.Identity a) (Data.Functor.Identity.Identity b) a b instance Data.Tuple.Optics.Field1 (Data.Functor.Product.Product f g a) (Data.Functor.Product.Product f' g a) (f a) (f' a) instance Data.Tuple.Optics.Field1 ((GHC.Generics.:*:) f g p) ((GHC.Generics.:*:) f' g p) (f p) (f' p) instance Data.Tuple.Optics.Field1 (a, b) (a', b) a a' instance Data.Tuple.Optics.Field1 (a, b, c) (a', b, c) a a' instance Data.Tuple.Optics.Field1 (a, b, c, d) (a', b, c, d) a a' instance Data.Tuple.Optics.Field1 (a, b, c, d, e) (a', b, c, d, e) a a' instance Data.Tuple.Optics.Field1 (a, b, c, d, e, f) (a', b, c, d, e, f) a a' instance Data.Tuple.Optics.Field1 (a, b, c, d, e, f, g) (a', b, c, d, e, f, g) a a' instance Data.Tuple.Optics.Field1 (a, b, c, d, e, f, g, h) (a', b, c, d, e, f, g, h) a a' instance Data.Tuple.Optics.Field1 (a, b, c, d, e, f, g, h, i) (a', b, c, d, e, f, g, h, i) a a' instance (Data.Tuple.Optics.GT (Data.Tuple.Optics.GSize s) n Data.Type.Equality.~ Data.Tuple.Optics.T, Data.Tuple.Optics.GT (Data.Tuple.Optics.GSize t) n Data.Type.Equality.~ Data.Tuple.Optics.T, Data.Tuple.Optics.GIxed n s t a b) => Data.Tuple.Optics.GIxed' Data.Tuple.Optics.T n s s' t s' a b instance Data.Tuple.Optics.GIxed Data.Tuple.Optics.N0 (GHC.Generics.K1 i a) (GHC.Generics.K1 i b) a b instance (p Data.Type.Equality.~ Data.Tuple.Optics.GT (Data.Tuple.Optics.GSize s) n, p Data.Type.Equality.~ Data.Tuple.Optics.GT (Data.Tuple.Optics.GSize t) n, Data.Tuple.Optics.GIxed' p n s s' t t' a b) => Data.Tuple.Optics.GIxed n (s GHC.Generics.:*: s') (t GHC.Generics.:*: t') a b instance Data.Tuple.Optics.GIxed n s t a b => Data.Tuple.Optics.GIxed n (GHC.Generics.M1 i c s) (GHC.Generics.M1 i c t) a b -- | This module defines the AsEmpty class, which provides a -- Prism for a type that may be _Empty. -- -- Note that orphan instances for this class are defined in the -- Optics.Empty module from optics-extra, so if you are -- not simply depending on optics you may wish to import that -- module instead. -- --
-- >>> isn't _Empty [1,2,3] -- True ---- --
-- >>> case Nothing of { Empty -> True; _ -> False }
-- True
--
module Optics.Empty.Core
-- | Class for types that may be _Empty.
class AsEmpty a
-- | -- >>> isn't _Empty [1,2,3] -- True --_Empty :: AsEmpty a => Prism' a () -- |
-- >>> isn't _Empty [1,2,3] -- True --_Empty :: (AsEmpty a, Monoid a, Eq a) => Prism' a () -- | Pattern synonym for matching on any type with an AsEmpty -- instance. -- --
-- >>> case Nothing of { Empty -> True; _ -> False }
-- True
--
pattern Empty :: forall a. AsEmpty a => a
instance Optics.Empty.Core.AsEmpty GHC.Types.Ordering
instance Optics.Empty.Core.AsEmpty ()
instance Optics.Empty.Core.AsEmpty Data.Semigroup.Internal.Any
instance Optics.Empty.Core.AsEmpty Data.Semigroup.Internal.All
instance Optics.Empty.Core.AsEmpty GHC.Event.Internal.Event
instance (GHC.Classes.Eq a, GHC.Num.Num a) => Optics.Empty.Core.AsEmpty (Data.Semigroup.Internal.Product a)
instance (GHC.Classes.Eq a, GHC.Num.Num a) => Optics.Empty.Core.AsEmpty (Data.Semigroup.Internal.Sum a)
instance Optics.Empty.Core.AsEmpty (GHC.Maybe.Maybe a)
instance Optics.Empty.Core.AsEmpty (Data.Monoid.Last a)
instance Optics.Empty.Core.AsEmpty (Data.Monoid.First a)
instance Optics.Empty.Core.AsEmpty a => Optics.Empty.Core.AsEmpty (Data.Semigroup.Internal.Dual a)
instance (Optics.Empty.Core.AsEmpty a, Optics.Empty.Core.AsEmpty b) => Optics.Empty.Core.AsEmpty (a, b)
instance (Optics.Empty.Core.AsEmpty a, Optics.Empty.Core.AsEmpty b, Optics.Empty.Core.AsEmpty c) => Optics.Empty.Core.AsEmpty (a, b, c)
instance Optics.Empty.Core.AsEmpty [a]
instance Optics.Empty.Core.AsEmpty (Control.Applicative.ZipList a)
instance Optics.Empty.Core.AsEmpty (Data.Map.Internal.Map k a)
instance Optics.Empty.Core.AsEmpty (Data.IntMap.Internal.IntMap a)
instance Optics.Empty.Core.AsEmpty (Data.Set.Internal.Set a)
instance Optics.Empty.Core.AsEmpty Data.IntSet.Internal.IntSet
instance Optics.Empty.Core.AsEmpty (Data.Sequence.Internal.Seq a)
-- | This module defines the Cons and Snoc classes, which
-- provide Prisms for the leftmost and rightmost elements of a
-- container, respectively.
--
-- Note that orphan instances for these classes are defined in the
-- Optics.Cons module from optics-extra, so if you are
-- not simply depending on optics you may wish to import that
-- module instead.
module Optics.Cons.Core
-- | This class provides a way to attach or detach elements on the left
-- side of a structure in a flexible manner.
class Cons s t a b | s -> a, t -> b, s b -> t, t a -> s
-- | -- _Cons :: Prism [a] [b] (a, [a]) (b, [b]) -- _Cons :: Prism (Seq a) (Seq b) (a, Seq a) (b, Seq b) -- _Cons :: Prism (Vector a) (Vector b) (a, Vector a) (b, Vector b) -- _Cons :: Prism' String (Char, String) -- _Cons :: Prism' Text (Char, Text) -- _Cons :: Prism' ByteString (Word8, ByteString) --_Cons :: Cons s t a b => Prism s t (a, s) (b, t) -- | cons an element onto a container. -- -- This is an infix alias for cons. -- --
-- >>> 1 <| [] -- [1] ---- --
-- >>> 'a' <| "bc" -- "abc" ---- --
-- >>> 1 <| [] -- [1] ---- --
-- >>> 1 <| [2, 3] -- [1,2,3] --(<|) :: Cons s s a a => a -> s -> s infixr 5 <| -- | cons an element onto a container. -- --
-- >>> cons 'a' "" -- "a" ---- --
-- >>> cons 'a' "bc" -- "abc" --cons :: Cons s s a a => a -> s -> s infixr 5 `cons` -- | Attempt to extract the left-most element from a container, and a -- version of the container without that element. -- --
-- >>> uncons [] -- Nothing ---- --
-- >>> uncons [1, 2, 3] -- Just (1,[2,3]) --uncons :: Cons s s a a => s -> Maybe (a, s) -- | An AffineTraversal reading and writing to the head of a -- non-empty container. -- --
-- >>> "abc" ^? _head -- Just 'a' ---- --
-- >>> "abc" & _head .~ 'd' -- "dbc" ---- --
-- >>> [1,2,3] & _head %~ (*10) -- [10,2,3] ---- --
-- >>> [] & _head %~ absurd -- [] ---- --
-- >>> [1,2,3] ^? _head -- Just 1 ---- --
-- >>> [] ^? _head -- Nothing ---- --
-- >>> [1,2] ^? _head -- Just 1 ---- --
-- >>> [] & _head .~ 1 -- [] ---- --
-- >>> [0] & _head .~ 2 -- [2] ---- --
-- >>> [0,1] & _head .~ 2 -- [2,1] --_head :: Cons s s a a => AffineTraversal' s a -- | An AffineTraversal reading and writing to the tail of a -- non-empty container. -- --
-- >>> "ab" & _tail .~ "cde" -- "acde" ---- --
-- >>> [] & _tail .~ [1,2] -- [] ---- --
-- >>> [1,2,3,4,5] & _tail % traversed %~ (*10) -- [1,20,30,40,50] ---- --
-- >>> [1,2] & _tail .~ [3,4,5] -- [1,3,4,5] ---- --
-- >>> [] & _tail .~ [1,2] -- [] ---- --
-- >>> "abc" ^? _tail -- Just "bc" ---- --
-- >>> "hello" ^? _tail -- Just "ello" ---- --
-- >>> "" ^? _tail -- Nothing --_tail :: Cons s s a a => AffineTraversal' s s -- | Pattern synonym for matching on the leftmost element of a structure. -- --
-- >>> case ['a','b','c'] of (x :< _) -> x -- 'a' --pattern (:<) :: forall s a. Cons s s a a => a -> s -> s infixr 5 :< -- | This class provides a way to attach or detach elements on the right -- side of a structure in a flexible manner. class Snoc s t a b | s -> a, t -> b, s b -> t, t a -> s _Snoc :: Snoc s t a b => Prism s t (s, a) (t, b) -- | snoc an element onto the end of a container. -- -- This is an infix alias for snoc. -- --
-- >>> "" |> 'a' -- "a" ---- --
-- >>> "bc" |> 'a' -- "bca" --(|>) :: Snoc s s a a => s -> a -> s infixl 5 |> -- | snoc an element onto the end of a container. -- --
-- >>> snoc "hello" '!' -- "hello!" --snoc :: Snoc s s a a => s -> a -> s infixl 5 `snoc` -- | Attempt to extract the right-most element from a container, and a -- version of the container without that element. -- --
-- >>> unsnoc "hello!"
-- Just ("hello",'!')
--
--
-- -- >>> unsnoc "" -- Nothing --unsnoc :: Snoc s s a a => s -> Maybe (s, a) -- | An AffineTraversal reading and replacing all but the a last -- element of a non-empty container. -- --
-- >>> "abcd" ^? _init -- Just "abc" ---- --
-- >>> "" ^? _init -- Nothing ---- --
-- >>> "ab" & _init .~ "cde" -- "cdeb" ---- --
-- >>> [] & _init .~ [1,2] -- [] ---- --
-- >>> [1,2,3,4] & _init % traversed %~ (*10) -- [10,20,30,4] ---- --
-- >>> [1,2,3] ^? _init -- Just [1,2] ---- --
-- >>> "hello" ^? _init -- Just "hell" ---- --
-- >>> [] ^? _init -- Nothing --_init :: Snoc s s a a => AffineTraversal' s s -- | An AffineTraversal reading and writing to the last element of a -- non-empty container. -- --
-- >>> "abc" ^? _last -- Just 'c' ---- --
-- >>> "" ^? _last -- Nothing ---- --
-- >>> [1,2,3] & _last %~ (+1) -- [1,2,4] ---- --
-- >>> [1,2] ^? _last -- Just 2 ---- --
-- >>> [] & _last .~ 1 -- [] ---- --
-- >>> [0] & _last .~ 2 -- [2] ---- --
-- >>> [0,1] & _last .~ 2 -- [0,2] --_last :: Snoc s s a a => AffineTraversal' s a -- | Pattern synonym for matching on the rightmost element of a structure. -- --
-- >>> case ['a','b','c'] of (_ :> x) -> x -- 'c' --pattern (:>) :: forall s a. Snoc s s a a => s -> a -> s infixl 5 :> instance Optics.Cons.Core.Snoc [a] [b] a b instance Optics.Cons.Core.Snoc (Control.Applicative.ZipList a) (Control.Applicative.ZipList b) a b instance Optics.Cons.Core.Snoc (Data.Sequence.Internal.Seq a) (Data.Sequence.Internal.Seq b) a b instance Optics.Cons.Core.Cons [a] [b] a b instance Optics.Cons.Core.Cons (Control.Applicative.ZipList a) (Control.Applicative.ZipList b) a b instance Optics.Cons.Core.Cons (Data.Sequence.Internal.Seq a) (Data.Sequence.Internal.Seq b) a b -- | A Setter S T A B has the ability to lift a function of -- type A -> B over a function of type S -> -- T, applying the function to update all the As contained -- in S. This can be used to set all the As to a -- single value (by lifting a constant function). -- -- This can be seen as a generalisation of fmap, where the type -- S does not need to be a type constructor with A as -- its last parameter. module Optics.Setter -- | Type synonym for a type-modifying setter. type Setter s t a b = Optic A_Setter NoIx s t a b -- | Type synonym for a type-preserving setter. type Setter' s a = Optic' A_Setter NoIx s a -- | Build a setter from a function to modify the element(s), which must -- respect the well-formedness laws. sets :: ((a -> b) -> s -> t) -> Setter s t a b -- | Apply a setter as a modifier. over :: Is k A_Setter => Optic k is s t a b -> (a -> b) -> s -> t -- | Create a Setter for a Functor. -- --
-- over mapped ≡ fmap --mapped :: Functor f => Setter (f a) (f b) a b -- | Apply a setter. -- --
-- set o v ≡ over o (const v) ---- --
-- >>> set _1 'x' ('y', 'z')
-- ('x','z')
--
set :: Is k A_Setter => Optic k is s t a b -> b -> s -> t
-- | Apply a setter, strictly.
--
-- TODO DOC: what exactly is the strictness property?
set' :: Is k A_Setter => Optic k is s t a b -> b -> s -> t
-- | Apply a setter as a modifier, strictly.
--
-- TODO DOC: what exactly is the strictness property?
--
-- Example:
--
-- -- f :: Int -> (Int, a) -> (Int, a) -- f k acc -- | k > 0 = f (k - 1) $ over' _1 (+1) acc -- | otherwise = acc ---- -- runs in constant space, but would result in a space leak if used with -- over. -- -- Note that replacing $ with $! or _1 with -- _1' (which amount to the same thing) doesn't help when -- over is used, because the first coordinate of a pair is never -- forced. over' :: Is k A_Setter => Optic k is s t a b -> (a -> b) -> s -> t -- | Tag for a setter. data A_Setter :: OpticKind -- | Defines some infix operators for optics operations. This is a -- deliberately small collection. -- -- If you like operators, you may also wish to import -- Optics.State.Operators from the optics-extra -- package. module Optics.Operators -- | Flipped infix version of view. (^.) :: Is k A_Getter => s -> Optic' k is s a -> a infixl 8 ^. -- | Flipped infix version of toListOf. (^..) :: Is k A_Fold => s -> Optic' k is s a -> [a] infixl 8 ^.. -- | Flipped infix version of preview. (^?) :: Is k An_AffineFold => s -> Optic' k is s a -> Maybe a infixl 8 ^? -- | Infix version of review. (#) :: Is k A_Review => Optic' k is t b -> b -> t infixr 8 # -- | Infix version of over. (%~) :: Is k A_Setter => Optic k is s t a b -> (a -> b) -> s -> t infixr 4 %~ -- | Infix version of over'. (%!~) :: Is k A_Setter => Optic k is s t a b -> (a -> b) -> s -> t infixr 4 %!~ -- | Infix version of set. (.~) :: Is k A_Setter => Optic k is s t a b -> b -> s -> t infixr 4 .~ -- | Infix version of set'. (!~) :: Is k A_Setter => Optic k is s t a b -> b -> s -> t infixr 4 !~ -- | Set the target of a Setter to Just a value. -- --
-- o ?~ b ≡ set o (Just b) ---- --
-- >>> Nothing & equality ?~ 'x' -- Just 'x' ---- --
-- >>> Map.empty & at 3 ?~ 'x' -- fromList [(3,'x')] --(?~) :: Is k A_Setter => Optic k is s t a (Maybe b) -> b -> s -> t infixr 4 ?~ -- | Strict version of (?~). (?!~) :: Is k A_Setter => Optic k is s t a (Maybe b) -> b -> s -> t infixr 4 ?!~ module Optics.Operators.Unsafe -- | Perform an *UNSAFE* head of an affine fold assuming that it is -- there. -- --
-- >>> Left 4 ^?! _Left -- 4 ---- --
-- >>> "world" ^?! ix 3 -- 'l' ---- --
-- >>> [] ^?! _head -- *** Exception: (^?!): empty affine fold -- ... --(^?!) :: (HasCallStack, Is k An_AffineFold) => s -> Optic' k is s a -> a infixl 8 ^?! -- | This module provides optics for Map and Set-like -- containers, including an AffineTraversal to traverse a key in a -- map or an element of a sequence: -- --
-- >>> preview (ix 1) ['a','b','c'] -- Just 'b' ---- -- a Lens to get, set or delete a key in a map: -- --
-- >>> set (at 0) (Just 'b') (Map.fromList [(0, 'a')]) -- fromList [(0,'b')] ---- -- and a Lens to insert or remove an element of a set: -- --
-- >>> IntSet.fromList [1,2,3,4] & contains 3 .~ False -- fromList [1,2,4] ---- -- The Optics.At module from optics-extra provides -- additional instances of the classes defined here. module Optics.At.Core -- | Type family that takes a key-value container type and returns the type -- of keys (indices) into the container, for example Index -- (Map k a) ~ k. This is shared by Ixed, At -- and Contains. type family Index (s :: Type) :: Type -- | Type family that takes a key-value container type and returns the type -- of values stored in the container, for example IxValue -- (Map k a) ~ a. This is shared by both Ixed and -- At. type family IxValue (m :: Type) :: Type -- | Provides a simple AffineTraversal lets you traverse the value -- at a given key in a Map or element at an ordinal position in a -- list or Seq. class Ixed m where { -- | Type family that takes a key-value container type and returns the kind -- of optic to index into it. For most containers, it's -- An_AffineTraversal, Representable (Naperian) -- containers it is A_Lens, and multi-maps would have -- A_Traversal. type family IxKind (m :: Type) :: OpticKind; type IxKind m = An_AffineTraversal; } -- | NB: Setting the value of this AffineTraversal will only -- set the value in at if it is already present. -- -- If you want to be able to insert missing values, you want -- at. -- --
-- >>> [1,2,3,4] & ix 2 %~ (*10) -- [1,2,30,4] ---- --
-- >>> "abcd" & ix 2 .~ 'e' -- "abed" ---- --
-- >>> "abcd" ^? ix 2 -- Just 'c' ---- --
-- >>> [] ^? ix 2 -- Nothing --ix :: Ixed m => Index m -> Optic' (IxKind m) NoIx m (IxValue m) -- | NB: Setting the value of this AffineTraversal will only -- set the value in at if it is already present. -- -- If you want to be able to insert missing values, you want -- at. -- --
-- >>> [1,2,3,4] & ix 2 %~ (*10) -- [1,2,30,4] ---- --
-- >>> "abcd" & ix 2 .~ 'e' -- "abed" ---- --
-- >>> "abcd" ^? ix 2 -- Just 'c' ---- --
-- >>> [] ^? ix 2 -- Nothing --ix :: (Ixed m, At m, IxKind m ~ An_AffineTraversal) => Index m -> Optic' (IxKind m) NoIx m (IxValue m) -- | A definition of ix for types with an At instance. This -- is the default if you don't specify a definition for ix. ixAt :: At m => Index m -> AffineTraversal' m (IxValue m) -- | At provides a Lens that can be used to read, write or -- delete the value associated with a key in a Map-like container -- on an ad hoc basis. -- -- An instance of At should satisfy: -- --
-- ix k ≡ at k % _Just --class (Ixed m, IxKind m ~ An_AffineTraversal) => At m -- |
-- >>> Map.fromList [(1,"world")] ^. at 1 -- Just "world" ---- --
-- >>> at 1 ?~ "hello" $ Map.empty -- fromList [(1,"hello")] ---- -- Note: Usage of this function might introduce space leaks if -- you're not careful to make sure that values put inside the Just -- constructor are evaluated. To force the values and avoid such leaks, -- use at' instead. -- -- Note: Map-like containers form a reasonable instance, -- but not Array-like ones, where you cannot satisfy the -- Lens laws. at :: At m => Index m -> Lens' m (Maybe (IxValue m)) -- | Version of at strict in the value inside the Just -- constructor. -- -- Example: -- --
-- >>> (at () .~ Just (error "oops") $ Nothing) `seq` () -- () ---- --
-- >>> (at' () .~ Just (error "oops") $ Nothing) `seq` () -- *** Exception: oops -- ... ---- --
-- >>> view (at ()) (Just $ error "oops") `seq` () -- () ---- --
-- >>> view (at' ()) (Just $ error "oops") `seq` () -- *** Exception: oops -- ... ---- -- It also works as expected for other data structures: -- --
-- >>> (at 1 .~ Just (error "oops") $ Map.empty) `seq` () -- () ---- --
-- >>> (at' 1 .~ Just (error "oops") $ Map.empty) `seq` () -- *** Exception: oops -- ... --at' :: At m => Index m -> Lens' m (Maybe (IxValue m)) -- | Delete the value associated with a key in a Map-like container -- --
-- sans k = at k .~ Nothing --sans :: At m => Index m -> m -> m -- | This class provides a simple Lens that lets you view (and -- modify) information about whether or not a container contains a given -- Index. Instances are provided for Set-like containers -- only. class Contains m -- |
-- >>> IntSet.fromList [1,2,3,4] ^. contains 3 -- True ---- --
-- >>> IntSet.fromList [1,2,3,4] ^. contains 5 -- False ---- --
-- >>> IntSet.fromList [1,2,3,4] & contains 3 .~ False -- fromList [1,2,4] --contains :: Contains m => Index m -> Lens' m Bool instance GHC.Classes.Eq e => Optics.At.Core.Ixed (e -> a) instance Optics.At.Core.Ixed (GHC.Maybe.Maybe a) instance Optics.At.Core.Ixed [a] instance Optics.At.Core.Ixed (GHC.Base.NonEmpty a) instance Optics.At.Core.Ixed (Data.Functor.Identity.Identity a) instance Optics.At.Core.Ixed (Data.Tree.Tree a) instance Optics.At.Core.Ixed (Data.Sequence.Internal.Seq a) instance Optics.At.Core.Ixed (Data.IntMap.Internal.IntMap a) instance GHC.Classes.Ord k => Optics.At.Core.Ixed (Data.Map.Internal.Map k a) instance GHC.Classes.Ord k => Optics.At.Core.Ixed (Data.Set.Internal.Set k) instance Optics.At.Core.Ixed Data.IntSet.Internal.IntSet instance GHC.Arr.Ix i => Optics.At.Core.Ixed (GHC.Arr.Array i e) instance (Data.Array.Base.IArray Data.Array.Base.UArray e, GHC.Arr.Ix i) => Optics.At.Core.Ixed (Data.Array.Base.UArray i e) instance (a0 Data.Type.Equality.~ a1) => Optics.At.Core.Ixed (a0, a1) instance (a0 Data.Type.Equality.~ a1, a0 Data.Type.Equality.~ a2) => Optics.At.Core.Ixed (a0, a1, a2) instance (a0 Data.Type.Equality.~ a1, a0 Data.Type.Equality.~ a2, a0 Data.Type.Equality.~ a3) => Optics.At.Core.Ixed (a0, a1, a2, a3) instance (a0 Data.Type.Equality.~ a1, a0 Data.Type.Equality.~ a2, a0 Data.Type.Equality.~ a3, a0 Data.Type.Equality.~ a4) => Optics.At.Core.Ixed (a0, a1, a2, a3, a4) instance (a0 Data.Type.Equality.~ a1, a0 Data.Type.Equality.~ a2, a0 Data.Type.Equality.~ a3, a0 Data.Type.Equality.~ a4, a0 Data.Type.Equality.~ a5) => Optics.At.Core.Ixed (a0, a1, a2, a3, a4, a5) instance (a0 Data.Type.Equality.~ a1, a0 Data.Type.Equality.~ a2, a0 Data.Type.Equality.~ a3, a0 Data.Type.Equality.~ a4, a0 Data.Type.Equality.~ a5, a0 Data.Type.Equality.~ a6) => Optics.At.Core.Ixed (a0, a1, a2, a3, a4, a5, a6) instance (a0 Data.Type.Equality.~ a1, a0 Data.Type.Equality.~ a2, a0 Data.Type.Equality.~ a3, a0 Data.Type.Equality.~ a4, a0 Data.Type.Equality.~ a5, a0 Data.Type.Equality.~ a6, a0 Data.Type.Equality.~ a7) => Optics.At.Core.Ixed (a0, a1, a2, a3, a4, a5, a6, a7) instance (a0 Data.Type.Equality.~ a1, a0 Data.Type.Equality.~ a2, a0 Data.Type.Equality.~ a3, a0 Data.Type.Equality.~ a4, a0 Data.Type.Equality.~ a5, a0 Data.Type.Equality.~ a6, a0 Data.Type.Equality.~ a7, a0 Data.Type.Equality.~ a8) => Optics.At.Core.Ixed (a0, a1, a2, a3, a4, a5, a6, a7, a8) instance Optics.At.Core.At (GHC.Maybe.Maybe a) instance Optics.At.Core.At (Data.IntMap.Internal.IntMap a) instance GHC.Classes.Ord k => Optics.At.Core.At (Data.Map.Internal.Map k a) instance Optics.At.Core.At Data.IntSet.Internal.IntSet instance GHC.Classes.Ord k => Optics.At.Core.At (Data.Set.Internal.Set k) instance Optics.At.Core.Contains Data.IntSet.Internal.IntSet instance GHC.Classes.Ord a => Optics.At.Core.Contains (Data.Set.Internal.Set a) module Optics.Arrow class Arrow arr => ArrowOptic k arr -- | Turn an optic into an arrow transformer. overA :: ArrowOptic k arr => Optic k is s t a b -> arr a b -> arr s t -- | Run an arrow command and use the output to set all the targets of an -- optic to the result. -- --
-- runKleisli action ((), (), ()) where -- action = assignA _1 (Kleisli (const getVal1)) -- >>> assignA _2 (Kleisli (const getVal2)) -- >>> assignA _3 (Kleisli (const getVal3)) -- getVal1 :: Either String Int -- getVal1 = ... -- getVal2 :: Either String Bool -- getVal2 = ... -- getVal3 :: Either String Char -- getVal3 = ... ---- -- has the type Either String (Int, Bool, -- Char) assignA :: (Is k A_Setter, Arrow arr) => Optic k is s t a b -> arr s b -> arr s t instance Control.Arrow.Arrow arr => Optics.Arrow.ArrowOptic Optics.Internal.Optic.Types.An_Iso arr instance Control.Arrow.Arrow arr => Optics.Arrow.ArrowOptic Optics.Internal.Optic.Types.A_Lens arr instance Control.Arrow.ArrowChoice arr => Optics.Arrow.ArrowOptic Optics.Internal.Optic.Types.A_Prism arr instance Control.Arrow.ArrowChoice arr => Optics.Arrow.ArrowOptic Optics.Internal.Optic.Types.An_AffineTraversal arr instance Control.Category.Category p => Control.Category.Category (Optics.Arrow.WrappedArrow p i) instance Control.Arrow.Arrow p => Control.Arrow.Arrow (Optics.Arrow.WrappedArrow p i) instance Control.Arrow.Arrow p => Data.Profunctor.Indexed.Profunctor (Optics.Arrow.WrappedArrow p) instance Control.Arrow.Arrow p => Data.Profunctor.Indexed.Strong (Optics.Arrow.WrappedArrow p) instance Control.Arrow.ArrowChoice p => Data.Profunctor.Indexed.Choice (Optics.Arrow.WrappedArrow p) instance Control.Arrow.ArrowChoice p => Data.Profunctor.Indexed.Visiting (Optics.Arrow.WrappedArrow p) module Numeric.Optics -- | A prism that shows and reads integers in base-2 through base-36 -- -- Note: This is an improper prism, since leading 0s are stripped when -- reading. -- --
-- >>> "100" ^? base 16 -- Just 256 ---- --
-- >>> 1767707668033969 ^. re (base 36) -- "helloworld" --base :: (HasCallStack, Integral a) => Int -> Prism' String a -- | This Prism can be used to model the fact that every -- Integral type is a subset of Integer. -- -- Embedding through the Prism only succeeds if the Integer -- would pass through unmodified when re-extracted. integral :: (Integral a, Integral b) => Prism Integer Integer a b -- |
-- binary = base 2 --binary :: Integral a => Prism' String a -- |
-- octal = base 8 --octal :: Integral a => Prism' String a -- |
-- decimal = base 10 --decimal :: Integral a => Prism' String a -- |
-- hex = base 16 --hex :: Integral a => Prism' String a -- |
-- adding n = iso (+n) (subtract n) ---- --
-- >>> [1..3] ^.. traversed % adding 1000 -- [1001,1002,1003] --adding :: Num a => a -> Iso' a a -- |
-- subtracting n = iso (subtract n) ((+n) -- subtracting n = re (adding n) --subtracting :: Num a => a -> Iso' a a -- |
-- multiplying n = iso (*n) (/n) ---- -- Note: This errors for n = 0 -- --
-- >>> 5 & multiplying 1000 %~ (+3) -- 5.003 ---- --
-- >>> let fahrenheit = multiplying (9/5) % adding 32 in 230 ^. re fahrenheit -- 110.0 --multiplying :: (Fractional a, Eq a) => a -> Iso' a a -- |
-- dividing n = iso (/n) (*n) -- dividing n = re (multiplying n) ---- -- Note: This errors for n = 0 dividing :: (Fractional a, Eq a) => a -> Iso' a a -- |
-- exponentiating n = iso (**n) (**recip n) ---- -- Note: This errors for n = 0 -- --
-- >>> au (coerced1 @Sum % re (exponentiating 2)) (foldMapOf each) (3,4) == 5 -- True --exponentiating :: (Floating a, Eq a) => a -> Iso' a a -- |
-- negated = iso negate negate ---- --
-- >>> au (coerced1 @Sum % negated) (foldMapOf each) (3,4) == 7 -- True ---- --
-- >>> au (coerced1 @Sum) (foldMapOf (each % negated)) (3,4) == -7 -- True --negated :: Num a => Iso' a a -- | Pattern synonym that can be used to construct or pattern match on an -- Integer as if it were of any Integral type. pattern Integral :: forall a. Integral a => a -> Integer -- | This module defines optics for constructing and manipulating finite -- Sets. module Data.Set.Optics -- | This Setter can be used to change the type of a Set by -- mapping the elements to new values. -- -- Sadly, you can't create a valid Traversal for a Set, but -- you can manipulate it by reading using folded and reindexing it -- via setmapped. -- --
-- >>> over setmapped (+1) (fromList [1,2,3,4]) -- fromList [2,3,4,5] --setmapped :: Ord b => Setter (Set a) (Set b) a b -- | Construct a set from a fold. -- --
-- >>> setOf folded ["hello","world"] -- fromList ["hello","world"] ---- --
-- >>> setOf (folded % _2) [("hello",1),("world",2),("!!!",3)]
-- fromList [1,2,3]
--
setOf :: (Is k A_Fold, Ord a) => Optic' k is s a -> s -> Set a
-- | This module defines optics for constructing and manipulating finite
-- IntSets.
module Data.IntSet.Optics
-- | IntSet isn't Foldable, but this Fold can be used to access the
-- members of an IntSet.
--
-- -- >>> sumOf members $ setOf folded [1,2,3,4] -- 10 --members :: Fold IntSet Int -- | This Setter can be used to change the type of a IntSet -- by mapping the elements to new values. -- -- Sadly, you can't create a valid Traversal for an IntSet, -- but you can manipulate it by reading using folded and -- reindexing it via setmapped. -- --
-- >>> over setmapped (+1) (fromList [1,2,3,4]) -- fromList [2,3,4,5] --setmapped :: Setter' IntSet Int -- | Construct an IntSet from a fold. -- --
-- >>> setOf folded [1,2,3,4] -- fromList [1,2,3,4] ---- --
-- >>> setOf (folded % _2) [("hello",1),("world",2),("!!!",3)]
-- fromList [1,2,3]
--
setOf :: Is k A_Fold => Optic' k is s Int -> s -> IntSet
-- | A Traversal lifts an effectful operation on elements to act on
-- structures containing those elements.
--
-- That is, given a function op :: A -> F B where F
-- is Applicative, a Traversal S T A B can produce
-- a function S -> F T that applies op to all the
-- As contained in the S.
--
-- This can be seen as a generalisation of traverse, where the
-- type S does not need to be a type constructor with A
-- as the last parameter.
--
-- A Lens is a Traversal that acts on a single value.
--
-- A close relative is the AffineTraversal, which is a
-- Traversal that acts on at most one value.
module Optics.Traversal
-- | Type synonym for a type-modifying traversal.
type Traversal s t a b = Optic A_Traversal NoIx s t a b
-- | Type synonym for a type-preserving traversal.
type Traversal' s a = Optic' A_Traversal NoIx s a
-- | Build a traversal from the van Laarhoven representation.
--
-- -- traversalVL . traverseOf ≡ id -- traverseOf . traversalVL ≡ id --traversalVL :: TraversalVL s t a b -> Traversal s t a b -- | Map each element of a structure targeted by a Traversal, -- evaluate these actions from left to right, and collect the results. traverseOf :: (Is k A_Traversal, Applicative f) => Optic k is s t a b -> (a -> f b) -> s -> f t -- | Construct a Traversal via the Traversable class. -- --
-- traverseOf traversed = traverse --traversed :: Traversable t => Traversal (t a) (t b) a b -- | A version of traverseOf with the arguments flipped. forOf :: (Is k A_Traversal, Applicative f) => Optic k is s t a b -> s -> (a -> f b) -> f t -- | Evaluate each action in the structure from left to right, and collect -- the results. -- --
-- >>> sequenceOf each ([1,2],[3,4]) -- [(1,3),(1,4),(2,3),(2,4)] ---- --
-- sequence ≡ sequenceOf traversed ≡ traverse id -- sequenceOf o ≡ traverseOf o id --sequenceOf :: (Is k A_Traversal, Applicative f) => Optic k is s t (f b) b -> s -> f t -- | This generalizes transpose to an arbitrary Traversal. -- -- Note: transpose handles ragged inputs more intelligently, but -- for non-ragged inputs: -- --
-- >>> transposeOf traversed [[1,2,3],[4,5,6]] -- [[1,4],[2,5],[3,6]] ---- --
-- transpose ≡ transposeOf traverse --transposeOf :: Is k A_Traversal => Optic k is s t [a] a -> s -> [t] -- | This generalizes mapAccumR to an arbitrary Traversal. -- --
-- mapAccumR ≡ mapAccumROf traversed ---- -- mapAccumROf accumulates State from right to left. mapAccumROf :: Is k A_Traversal => Optic k is s t a b -> (acc -> a -> (b, acc)) -> acc -> s -> (t, acc) -- | This generalizes mapAccumL to an arbitrary Traversal. -- --
-- mapAccumL ≡ mapAccumLOf traverse ---- -- mapAccumLOf accumulates State from left to right. mapAccumLOf :: Is k A_Traversal => Optic k is s t a b -> (acc -> a -> (b, acc)) -> acc -> s -> (t, acc) -- | This permits the use of scanr1 over an arbitrary -- Traversal. -- --
-- scanr1 ≡ scanr1Of traversed --scanr1Of :: Is k A_Traversal => Optic k is s t a a -> (a -> a -> a) -> s -> t -- | This permits the use of scanl1 over an arbitrary -- Traversal. -- --
-- scanl1 ≡ scanl1Of traversed --scanl1Of :: Is k A_Traversal => Optic k is s t a a -> (a -> a -> a) -> s -> t -- | Try to map a function over this Traversal, returning Nothing if -- the traversal has no targets. -- --
-- >>> failover (element 3) (*2) [1,2] -- Nothing ---- --
-- >>> failover _Left (*2) (Right 4) -- Nothing ---- --
-- >>> failover _Right (*2) (Right 4) -- Just (Right 8) --failover :: Is k A_Traversal => Optic k is s t a b -> (a -> b) -> s -> Maybe t -- | Version of failover strict in the application of f. failover' :: Is k A_Traversal => Optic k is s t a b -> (a -> b) -> s -> Maybe t -- | This allows you to traverse the elements of a traversal in the -- opposite order. backwards :: Is k A_Traversal => Optic k is s t a b -> Traversal s t a b -- | partsOf turns a Traversal into a Lens. -- -- Note: You should really try to maintain the invariant of the -- number of children in the list. -- --
-- >>> ('a','b','c') & partsOf each .~ ['x','y','z']
-- ('x','y','z')
--
--
-- Any extras will be lost. If you do not supply enough, then the
-- remainder will come from the original structure.
--
--
-- >>> ('a','b','c') & partsOf each .~ ['w','x','y','z']
-- ('w','x','y')
--
--
--
-- >>> ('a','b','c') & partsOf each .~ ['x','y']
-- ('x','y','c')
--
--
--
-- >>> ('b', 'a', 'd', 'c') & partsOf each %~ sort
-- ('a','b','c','d')
--
--
-- So technically, this is only a Lens if you do not change the
-- number of results it returns.
partsOf :: forall k is s t a. Is k A_Traversal => Optic k is s t a a -> Lens s t [a] [a]
-- | Convert a traversal to an AffineTraversal that visits the first
-- element of the original traversal.
--
-- For the fold version see pre.
--
-- -- >>> "foo" & singular traversed .~ 'z' -- "zoo" --singular :: forall k is s a. Is k A_Traversal => Optic' k is s a -> AffineTraversal' s a -- | Tag for a traversal. data A_Traversal :: OpticKind -- | Type synonym for a type-modifying van Laarhoven traversal. type TraversalVL s t a b = forall f. Applicative f => (a -> f b) -> s -> f t -- | Type synonym for a type-preserving van Laarhoven traversal. type TraversalVL' s a = TraversalVL s s a a -- | An IxTraversal is an indexed version of a Traversal. See -- the "Indexed optics" section of the overview documentation in the -- Optics module of the main optics package for more -- details on indexed optics. module Optics.IxTraversal -- | Type synonym for a type-modifying indexed traversal. type IxTraversal i s t a b = Optic A_Traversal (WithIx i) s t a b -- | Type synonym for a type-preserving indexed traversal. type IxTraversal' i s a = Optic' A_Traversal (WithIx i) s a -- | Build an indexed traversal from the van Laarhoven representation. -- --
-- itraversalVL . itraverseOf ≡ id -- itraverseOf . itraversalVL ≡ id --itraversalVL :: IxTraversalVL i s t a b -> IxTraversal i s t a b -- | Map each element of a structure targeted by an IxTraversal -- (supplying the index), evaluate these actions from left to right, and -- collect the results. -- -- This yields the van Laarhoven representation of an indexed traversal. itraverseOf :: (Is k A_Traversal, Applicative f, is `HasSingleIndex` i) => Optic k is s t a b -> (i -> a -> f b) -> s -> f t -- | Indexed traversal via the TraversableWithIndex class. -- --
-- itraverseOf itraversed ≡ itraverse ---- --
-- >>> iover (itraversed <%> itraversed) (,) ["ab", "cd"] -- [[((0,0),'a'),((0,1),'b')],[((1,0),'c'),((1,1),'d')]] --itraversed :: TraversableWithIndex i f => IxTraversal i (f a) (f b) a b -- | This is the trivial empty IxAffineTraversal, i.e. the optic -- that targets no substructures. -- -- This is the identity element when a Fold, AffineFold, -- IxFold or IxAffineFold is viewed as a monoid. -- --
-- >>> 6 & ignored %~ absurd -- 6 --ignored :: IxAffineTraversal i s s a b -- | Traverse selected elements of a Traversal where their ordinal -- positions match a predicate. elementsOf :: Is k A_Traversal => Optic k is s t a a -> (Int -> Bool) -> IxTraversal Int s t a a -- | Traverse elements of a Traversable container where their -- ordinal positions match a predicate. -- --
-- elements ≡ elementsOf traverse --elements :: Traversable f => (Int -> Bool) -> IxTraversal' Int (f a) a -- | Traverse the nth element of a Traversal if it exists. elementOf :: Is k A_Traversal => Optic' k is s a -> Int -> IxAffineTraversal' Int s a -- | Traverse the nth element of a Traversable container. -- --
-- element ≡ elementOf traversed --element :: Traversable f => Int -> IxAffineTraversal' Int (f a) a -- | A version of itraverseOf with the arguments flipped. iforOf :: (Is k A_Traversal, Applicative f, is `HasSingleIndex` i) => Optic k is s t a b -> s -> (i -> a -> f b) -> f t -- | Generalizes mapAccumL to an arbitrary IxTraversal. -- -- imapAccumLOf accumulates state from left to right. -- --
-- mapAccumLOf o ≡ imapAccumLOf o . const --imapAccumLOf :: (Is k A_Traversal, is `HasSingleIndex` i) => Optic k is s t a b -> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc) -- | Generalizes mapAccumR to an arbitrary IxTraversal. -- -- imapAccumROf accumulates state from right to left. -- --
-- mapAccumROf o ≡ imapAccumROf o . const --imapAccumROf :: (Is k A_Traversal, is `HasSingleIndex` i) => Optic k is s t a b -> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc) -- | This permits the use of scanl1 over an arbitrary -- IxTraversal. iscanl1Of :: (Is k A_Traversal, is `HasSingleIndex` i) => Optic k is s t a a -> (i -> a -> a -> a) -> s -> t -- | This permits the use of scanr1 over an arbitrary -- IxTraversal. iscanr1Of :: (Is k A_Traversal, is `HasSingleIndex` i) => Optic k is s t a a -> (i -> a -> a -> a) -> s -> t -- | Try to map a function which uses the index over this -- IxTraversal, returning Nothing if the IxTraversal -- has no targets. ifailover :: (Is k A_Traversal, is `HasSingleIndex` i) => Optic k is s t a b -> (i -> a -> b) -> s -> Maybe t -- | Version of ifailover strict in the application of the function. ifailover' :: (Is k A_Traversal, is `HasSingleIndex` i) => Optic k is s t a b -> (i -> a -> b) -> s -> Maybe t -- | Filter results of an IxTraversal that don't satisfy a predicate -- on the indices. -- --
-- >>> toListOf (itraversed %& indices even) "foobar" -- "foa" --indices :: (Is k A_Traversal, is `HasSingleIndex` i) => (i -> Bool) -> Optic k is s t a a -> IxTraversal i s t a a -- | This allows you to traverse the elements of an indexed -- traversal in the opposite order. ibackwards :: (Is k A_Traversal, is `HasSingleIndex` i) => Optic k is s t a b -> IxTraversal i s t a b -- | An indexed version of partsOf that receives the entire list of -- indices as its indices. ipartsOf :: forall k is i s t a. (Is k A_Traversal, is `HasSingleIndex` i) => Optic k is s t a a -> IxLens [i] s t [a] [a] -- | Convert an indexed traversal to an IxAffineTraversal that -- visits the first element of the original traversal. -- -- For the fold version see ipre. -- --
-- >>> [1,2,3] & iover (isingular itraversed) (-) -- [-1,2,3] --isingular :: forall k is i s a. (Is k A_Traversal, is `HasSingleIndex` i) => Optic' k is s a -> IxAffineTraversal' i s a -- | Tag for a traversal. data A_Traversal :: OpticKind -- | Type synonym for a type-modifying van Laarhoven indexed traversal. type IxTraversalVL i s t a b = forall f. Applicative f => (i -> a -> f b) -> s -> f t -- | Type synonym for a type-preserving van Laarhoven indexed traversal. type IxTraversalVL' i s a = IxTraversalVL i s s a a -- | Class for Traversables that have an additional read-only index -- available. class (FoldableWithIndex i t, Traversable t) => TraversableWithIndex i t | t -> i itraverse :: (TraversableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f (t b) -- | This module defines the Each class, which provides an -- IxTraversal that extracts each element of a (potentially -- monomorphic) container. -- -- Note that orphan instances for this class are defined in the -- Optics.Each module from optics-extra, so if you are -- not simply depending on optics you may wish to import that -- module instead. module Optics.Each.Core -- | Extract each element of a (potentially monomorphic) container. -- --
-- >>> over each (*10) (1,2,3) -- (10,20,30) ---- --
-- >>> iover each (\i a -> a*10 + succ i) (1,2,3) -- (11,22,33) --class Each i s t a b | s -> i a, t -> i b, s b -> t, t a -> s each :: Each i s t a b => IxTraversal i s t a b each :: (Each i s t a b, TraversableWithIndex i g, s ~ g a, t ~ g b) => IxTraversal i s t a b instance (a Data.Type.Equality.~ a1, b Data.Type.Equality.~ b1) => Optics.Each.Core.Each GHC.Types.Int (a, a1) (b, b1) a b instance (a Data.Type.Equality.~ a1, a Data.Type.Equality.~ a2, b Data.Type.Equality.~ b1, b Data.Type.Equality.~ b2) => Optics.Each.Core.Each GHC.Types.Int (a, a1, a2) (b, b1, b2) a b instance (a Data.Type.Equality.~ a1, a Data.Type.Equality.~ a2, a Data.Type.Equality.~ a3, b Data.Type.Equality.~ b1, b Data.Type.Equality.~ b2, b Data.Type.Equality.~ b3) => Optics.Each.Core.Each GHC.Types.Int (a, a1, a2, a3) (b, b1, b2, b3) a b instance (a Data.Type.Equality.~ a1, a Data.Type.Equality.~ a2, a Data.Type.Equality.~ a3, a Data.Type.Equality.~ a4, b Data.Type.Equality.~ b1, b Data.Type.Equality.~ b2, b Data.Type.Equality.~ b3, b Data.Type.Equality.~ b4) => Optics.Each.Core.Each GHC.Types.Int (a, a1, a2, a3, a4) (b, b1, b2, b3, b4) a b instance (a Data.Type.Equality.~ a1, a Data.Type.Equality.~ a2, a Data.Type.Equality.~ a3, a Data.Type.Equality.~ a4, a Data.Type.Equality.~ a5, b Data.Type.Equality.~ b1, b Data.Type.Equality.~ b2, b Data.Type.Equality.~ b3, b Data.Type.Equality.~ b4, b Data.Type.Equality.~ b5) => Optics.Each.Core.Each GHC.Types.Int (a, a1, a2, a3, a4, a5) (b, b1, b2, b3, b4, b5) a b instance (a Data.Type.Equality.~ a1, a Data.Type.Equality.~ a2, a Data.Type.Equality.~ a3, a Data.Type.Equality.~ a4, a Data.Type.Equality.~ a5, a Data.Type.Equality.~ a6, b Data.Type.Equality.~ b1, b Data.Type.Equality.~ b2, b Data.Type.Equality.~ b3, b Data.Type.Equality.~ b4, b Data.Type.Equality.~ b5, b Data.Type.Equality.~ b6) => Optics.Each.Core.Each GHC.Types.Int (a, a1, a2, a3, a4, a5, a6) (b, b1, b2, b3, b4, b5, b6) a b instance (a Data.Type.Equality.~ a1, a Data.Type.Equality.~ a2, a Data.Type.Equality.~ a3, a Data.Type.Equality.~ a4, a Data.Type.Equality.~ a5, a Data.Type.Equality.~ a6, a Data.Type.Equality.~ a7, b Data.Type.Equality.~ b1, b Data.Type.Equality.~ b2, b Data.Type.Equality.~ b3, b Data.Type.Equality.~ b4, b Data.Type.Equality.~ b5, b Data.Type.Equality.~ b6, b Data.Type.Equality.~ b7) => Optics.Each.Core.Each GHC.Types.Int (a, a1, a2, a3, a4, a5, a6, a7) (b, b1, b2, b3, b4, b5, b6, b7) a b instance (a Data.Type.Equality.~ a1, a Data.Type.Equality.~ a2, a Data.Type.Equality.~ a3, a Data.Type.Equality.~ a4, a Data.Type.Equality.~ a5, a Data.Type.Equality.~ a6, a Data.Type.Equality.~ a7, a Data.Type.Equality.~ a8, b Data.Type.Equality.~ b1, b Data.Type.Equality.~ b2, b Data.Type.Equality.~ b3, b Data.Type.Equality.~ b4, b Data.Type.Equality.~ b5, b Data.Type.Equality.~ b6, b Data.Type.Equality.~ b7, b Data.Type.Equality.~ b8) => Optics.Each.Core.Each GHC.Types.Int (a, a1, a2, a3, a4, a5, a6, a7, a8) (b, b1, b2, b3, b4, b5, b6, b7, b8) a b instance (a Data.Type.Equality.~ a1, a Data.Type.Equality.~ a2, a Data.Type.Equality.~ a3, a Data.Type.Equality.~ a4, a Data.Type.Equality.~ a5, a Data.Type.Equality.~ a6, a Data.Type.Equality.~ a7, a Data.Type.Equality.~ a8, a Data.Type.Equality.~ a9, b Data.Type.Equality.~ b1, b Data.Type.Equality.~ b2, b Data.Type.Equality.~ b3, b Data.Type.Equality.~ b4, b Data.Type.Equality.~ b5, b Data.Type.Equality.~ b6, b Data.Type.Equality.~ b7, b Data.Type.Equality.~ b8, b Data.Type.Equality.~ b9) => Optics.Each.Core.Each GHC.Types.Int (a, a1, a2, a3, a4, a5, a6, a7, a8, a9) (b, b1, b2, b3, b4, b5, b6, b7, b8, b9) a b instance (a Data.Type.Equality.~ a', b Data.Type.Equality.~ b') => Optics.Each.Core.Each (Data.Either.Either () ()) (Data.Either.Either a a') (Data.Either.Either b b') a b instance Optics.Each.Core.Each (Data.Either.Either () ()) (Data.Complex.Complex a) (Data.Complex.Complex b) a b instance (k Data.Type.Equality.~ k') => Optics.Each.Core.Each k (Data.Map.Internal.Map k a) (Data.Map.Internal.Map k' b) a b instance Optics.Each.Core.Each GHC.Types.Int (Data.IntMap.Internal.IntMap a) (Data.IntMap.Internal.IntMap b) a b instance Optics.Each.Core.Each GHC.Types.Int [a] [b] a b instance Optics.Each.Core.Each GHC.Types.Int (GHC.Base.NonEmpty a) (GHC.Base.NonEmpty b) a b instance Optics.Each.Core.Each () (Data.Functor.Identity.Identity a) (Data.Functor.Identity.Identity b) a b instance Optics.Each.Core.Each () (GHC.Maybe.Maybe a) (GHC.Maybe.Maybe b) a b instance Optics.Each.Core.Each GHC.Types.Int (Data.Sequence.Internal.Seq a) (Data.Sequence.Internal.Seq b) a b instance Optics.Each.Core.Each [GHC.Types.Int] (Data.Tree.Tree a) (Data.Tree.Tree b) a b instance (GHC.Arr.Ix i, i Data.Type.Equality.~ j) => Optics.Each.Core.Each i (GHC.Arr.Array i a) (GHC.Arr.Array j b) a b -- | This module defines basic functionality for indexed optics. See the -- "Indexed optics" section of the overview documentation in the -- Optics module of the main optics package for more -- details. module Optics.Indexed.Core -- | Class for optic kinds that can have indices. class IxOptic k s t a b -- | Convert an indexed optic to its unindexed equivalent. noIx :: (IxOptic k s t a b, NonEmptyIndices is) => Optic k is s t a b -> Optic k NoIx s t a b -- | Construct a conjoined indexed optic that provides a separate code path -- when used without indices. Useful for defining indexed optics that are -- as efficient as their unindexed equivalents when used without indices. -- -- Note: conjoined f g is well-defined if and only -- if f ≡ noIx g. conjoined :: is `HasSingleIndex` i => Optic k NoIx s t a b -> Optic k is s t a b -> Optic k is s t a b -- | Compose two optics of compatible flavours. -- -- Returns an optic of the appropriate supertype. If either or both -- optics are indexed, the composition preserves all the indices. (%) :: (Is k m, Is l m, m ~ Join k l, ks ~ Append is js) => Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b infixl 9 % -- | Compose two indexed optics. Their indices are composed as a pair. -- --
-- >>> itoListOf (ifolded <%> ifolded) ["foo", "bar"] -- [((0,0),'f'),((0,1),'o'),((0,2),'o'),((1,0),'b'),((1,1),'a'),((1,2),'r')] --(<%>) :: (m ~ Join k l, Is k m, Is l m, IxOptic m s t a b, is `HasSingleIndex` i, js `HasSingleIndex` j) => Optic k is s t u v -> Optic l js u v a b -> Optic m (WithIx (i, j)) s t a b infixl 9 <%> -- | Compose two indexed optics and drop indices of the left one. (If you -- want to compose a non-indexed and an indexed optic, you can just use -- (%).) -- --
-- >>> itoListOf (ifolded %> ifolded) ["foo", "bar"] -- [(0,'f'),(1,'o'),(2,'o'),(0,'b'),(1,'a'),(2,'r')] --(%>) :: (m ~ Join k l, Is k m, Is l m, IxOptic k s t u v, NonEmptyIndices is) => Optic k is s t u v -> Optic l js u v a b -> Optic m js s t a b infixl 9 %> -- | Compose two indexed optics and drop indices of the right one. (If you -- want to compose an indexed and a non-indexed optic, you can just use -- (%).) -- --
-- >>> itoListOf (ifolded <% ifolded) ["foo", "bar"] -- [(0,'f'),(0,'o'),(0,'o'),(1,'b'),(1,'a'),(1,'r')] --(<%) :: (m ~ Join k l, Is l m, Is k m, IxOptic l u v a b, NonEmptyIndices js) => Optic k is s t u v -> Optic l js u v a b -> Optic m is s t a b infixl 9 <% -- | Remap the index. -- --
-- >>> itoListOf (reindexed succ ifolded) "foo" -- [(1,'f'),(2,'o'),(3,'o')] ---- --
-- >>> itoListOf (ifolded %& reindexed succ) "foo" -- [(1,'f'),(2,'o'),(3,'o')] --reindexed :: is `HasSingleIndex` i => (i -> j) -> Optic k is s t a b -> Optic k (WithIx j) s t a b -- | Flatten indices obtained from two indexed optics. -- --
-- >>> itoListOf (ifolded % ifolded %& icompose (,)) ["foo","bar"] -- [((0,0),'f'),((0,1),'o'),((0,2),'o'),((1,0),'b'),((1,1),'a'),((1,2),'r')] --icompose :: (i -> j -> ix) -> Optic k '[i, j] s t a b -> Optic k (WithIx ix) s t a b -- | Flatten indices obtained from three indexed optics. -- --
-- >>> itoListOf (ifolded % ifolded % ifolded %& icompose3 (,,)) [["foo","bar"],["xyz"]] -- [((0,0,0),'f'),((0,0,1),'o'),((0,0,2),'o'),((0,1,0),'b'),((0,1,1),'a'),((0,1,2),'r'),((1,0,0),'x'),((1,0,1),'y'),((1,0,2),'z')] --icompose3 :: (i1 -> i2 -> i3 -> ix) -> Optic k '[i1, i2, i3] s t a b -> Optic k (WithIx ix) s t a b -- | Flatten indices obtained from four indexed optics. icompose4 :: (i1 -> i2 -> i3 -> i4 -> ix) -> Optic k '[i1, i2, i3, i4] s t a b -> Optic k (WithIx ix) s t a b -- | Flatten indices obtained from five indexed optics. icompose5 :: (i1 -> i2 -> i3 -> i4 -> i5 -> ix) -> Optic k '[i1, i2, i3, i4, i5] s t a b -> Optic k (WithIx ix) s t a b -- | Flatten indices obtained from arbitrary number of indexed optics. icomposeN :: forall k i is s t a b. (CurryCompose is, NonEmptyIndices is) => Curry is i -> Optic k is s t a b -> Optic k (WithIx i) s t a b -- | Class for Functors that have an additional read-only index -- available. class Functor f => FunctorWithIndex i f | f -> i imap :: FunctorWithIndex i f => (i -> a -> b) -> f a -> f b imap :: (FunctorWithIndex i f, TraversableWithIndex i f) => (i -> a -> b) -> f a -> f b -- | Class for Foldables that have an additional read-only index -- available. class (FunctorWithIndex i f, Foldable f) => FoldableWithIndex i f | f -> i ifoldMap :: (FoldableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m ifoldMap :: (FoldableWithIndex i f, TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m ifoldr :: FoldableWithIndex i f => (i -> a -> b -> b) -> b -> f a -> b ifoldl' :: FoldableWithIndex i f => (i -> b -> a -> b) -> b -> f a -> b -- | Traverse FoldableWithIndex ignoring the results. itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f () -- | Flipped itraverse_. ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f () -- | List of elements of a structure with an index, from left to right. itoList :: FoldableWithIndex i f => f a -> [(i, a)] -- | Class for Traversables that have an additional read-only index -- available. class (FoldableWithIndex i t, Traversable t) => TraversableWithIndex i t | t -> i itraverse :: (TraversableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f (t b) -- | Flipped itraverse ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b) instance (s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.Indexed.Core.IxOptic Optics.Internal.Optic.Types.A_Getter s t a b instance Optics.Indexed.Core.IxOptic Optics.Internal.Optic.Types.A_Lens s t a b instance Optics.Indexed.Core.IxOptic Optics.Internal.Optic.Types.An_AffineTraversal s t a b instance (s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.Indexed.Core.IxOptic Optics.Internal.Optic.Types.An_AffineFold s t a b instance Optics.Indexed.Core.IxOptic Optics.Internal.Optic.Types.A_Traversal s t a b instance (s Data.Type.Equality.~ t, a Data.Type.Equality.~ b) => Optics.Indexed.Core.IxOptic Optics.Internal.Optic.Types.A_Fold s t a b instance Optics.Indexed.Core.IxOptic Optics.Internal.Optic.Types.A_Setter s t a b -- | See the Optics module in the main optics package for -- overview documentation. module Optics.Core -- | This module defines optics for constructing and manipulating finite -- Seqs. module Data.Sequence.Optics -- | A Seq is isomorphic to a ViewL -- --
-- viewl m ≡ m ^. viewL ---- --
-- >>> Seq.fromList [1,2,3] ^. viewL -- 1 :< fromList [2,3] ---- --
-- >>> Seq.empty ^. viewL -- EmptyL ---- --
-- >>> EmptyL ^. re viewL -- fromList [] ---- --
-- >>> review viewL $ 1 Seq.:< fromList [2,3] -- fromList [1,2,3] --viewL :: Iso (Seq a) (Seq b) (ViewL a) (ViewL b) -- | A Seq is isomorphic to a ViewR -- --
-- viewr m ≡ m ^. viewR ---- --
-- >>> Seq.fromList [1,2,3] ^. viewR -- fromList [1,2] :> 3 ---- --
-- >>> Seq.empty ^. viewR -- EmptyR ---- --
-- >>> EmptyR ^. re viewR -- fromList [] ---- --
-- >>> review viewR $ fromList [1,2] Seq.:> 3 -- fromList [1,2,3] --viewR :: Iso (Seq a) (Seq b) (ViewR a) (ViewR b) -- | Traverse all the elements numbered from i to j of a -- Seq -- --
-- >>> fromList [1,2,3,4,5] & sliced 1 3 %~ (*10) -- fromList [1,20,30,4,5] ---- --
-- >>> fromList [1,2,3,4,5] ^.. sliced 1 3 -- [2,3] ---- --
-- >>> fromList [1,2,3,4,5] & sliced 1 3 .~ 0 -- fromList [1,0,0,4,5] --sliced :: Int -> Int -> IxTraversal' Int (Seq a) a -- | Traverse the first n elements of a Seq -- --
-- >>> fromList [1,2,3,4,5] ^.. slicedTo 2 -- [1,2] ---- --
-- >>> fromList [1,2,3,4,5] & slicedTo 2 %~ (*10) -- fromList [10,20,3,4,5] ---- --
-- >>> fromList [1,2,4,5,6] & slicedTo 10 .~ 0 -- fromList [0,0,0,0,0] --slicedTo :: Int -> IxTraversal' Int (Seq a) a -- | Traverse all but the first n elements of a Seq -- --
-- >>> fromList [1,2,3,4,5] ^.. slicedFrom 2 -- [3,4,5] ---- --
-- >>> fromList [1,2,3,4,5] & slicedFrom 2 %~ (*10) -- fromList [1,2,30,40,50] ---- --
-- >>> fromList [1,2,3,4,5] & slicedFrom 10 .~ 0 -- fromList [1,2,3,4,5] --slicedFrom :: Int -> IxTraversal' Int (Seq a) a -- | Construct a Seq from a fold. -- --
-- >>> seqOf folded ["hello","world"] -- fromList ["hello","world"] ---- --
-- >>> seqOf (folded % _2) [("hello",1),("world",2),("!!!",3)]
-- fromList [1,2,3]
--
seqOf :: Is k A_Fold => Optic' k is s a -> s -> Seq a