| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Mikan.Utils.Lens
Description
Lenses and other optic-related functions.
Synopsis
- type LensGet o i = o -> i
- type LensSet o i = i -> o -> o
- type LensMap o i = (i -> i) -> o -> o
- set' :: ASetter s t a b -> b -> s -> t
- over' :: ASetter s t a b -> (a -> b) -> s -> t
- (%~!) :: ASetter s t a b -> (a -> b) -> s -> t
- (.=!) :: MonadState s m => ASetter s s a b -> b -> m ()
- (%=!) :: MonadState s m => ASetter s s a b -> (a -> b) -> m ()
- (%==) :: MonadState s m => Lens' s a -> (a -> m a) -> m ()
- (%==!) :: MonadState s m => Lens' s a -> (a -> m a) -> m ()
- (%%=!) :: MonadState o m => Lens' o i -> (i -> m (i, r)) -> m r
- locallyState :: MonadState o m => Lens' o i -> (i -> i) -> m r -> m r
- key :: Ord k => k -> Lens' (Map k v) (Maybe v)
- beside :: (Representable q, Applicative (Rep q), Applicative f, Bitraversable r) => Optical p q f s t a b -> Optical p q f s' t' a b -> Optical p q f (r s s') (r t t') a b
- both :: forall (r :: Type -> Type -> Type) a b. Bitraversable r => Traversal (r a a) (r b b) a b
- both1 :: forall (r :: Type -> Type -> Type) a b. Bitraversable1 r => Traversal1 (r a a) (r b b) a b
- cloneIndexPreservingTraversal :: ATraversal s t a b -> IndexPreservingTraversal s t a b
- cloneIndexPreservingTraversal1 :: ATraversal1 s t a b -> IndexPreservingTraversal1 s t a b
- cloneIndexedTraversal :: AnIndexedTraversal i s t a b -> IndexedTraversal i s t a b
- cloneIndexedTraversal1 :: AnIndexedTraversal1 i s t a b -> IndexedTraversal1 i s t a b
- cloneTraversal :: ATraversal s t a b -> Traversal s t a b
- cloneTraversal1 :: ATraversal1 s t a b -> Traversal1 s t a b
- confusing :: Applicative f => LensLike (Curried (Yoneda f) (Yoneda f)) s t a b -> LensLike f s t a b
- deepOf :: (Conjoined p, Applicative f) => LensLike f s t s t -> Traversing p f s t a b -> Over p f s t a b
- dropping :: (Conjoined p, Applicative f) => Int -> Over p (Indexing f) s t a a -> Over p f s t a a
- element :: forall (t :: Type -> Type) a. Traversable t => Int -> IndexedTraversal' Int (t a) a
- elementOf :: forall (f :: Type -> Type) s t a. Applicative f => LensLike (Indexing f) s t a a -> Int -> IndexedLensLike Int f s t a a
- elementsOf :: forall (f :: Type -> Type) s t a. Applicative f => LensLike (Indexing f) s t a a -> (Int -> Bool) -> IndexedLensLike Int f s t a a
- failing :: (Conjoined p, Applicative f) => Traversing p f s t a b -> Over p f s t a b -> Over p f s t a b
- failover :: Alternative m => LensLike ((,) Any) s t a b -> (a -> b) -> s -> m t
- forMOf :: LensLike (WrappedMonad m) s t a b -> s -> (a -> m b) -> m t
- forOf :: LensLike f s t a b -> s -> (a -> f b) -> f t
- holes1Of :: Conjoined p => Over p (Bazaar1 p a a) s t a a -> s -> NonEmpty (Pretext p a a t)
- holesOf :: Conjoined p => Over p (Bazaar p a a) s t a a -> s -> [Pretext p a a t]
- ifailover :: Alternative m => Over (Indexed i) ((,) Any) s t a b -> (i -> a -> b) -> s -> m t
- iforMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t) -> s -> (i -> a -> m b) -> m t
- iforOf :: (Indexed i a (f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t
- ignored :: Applicative f => pafb -> s -> f s
- iloci :: forall i a c s b p f. (Indexable i p, Applicative f) => p a (f b) -> Bazaar (Indexed i) a c s -> f (Bazaar (Indexed i) b c s)
- imapAccumLOf :: Over (Indexed i) (State acc) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
- imapAccumROf :: Over (Indexed i) (Backwards (State acc)) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
- imapMOf :: Over (Indexed i) (WrappedMonad m) s t a b -> (i -> a -> m b) -> s -> m t
- ipartsOf :: (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a a -> Over p f s t [a] [a]
- ipartsOf' :: forall i p f s t a. (Indexable [i] p, Functor f) => Over (Indexed i) (Bazaar' (Indexed i) a) s t a a -> Over p f s t [a] [a]
- itraverseOf :: (Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t
- iunsafePartsOf :: (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a b -> Over p f s t [a] [b]
- iunsafePartsOf' :: forall i s t a b. Over (Indexed i) (Bazaar (Indexed i) a b) s t a b -> IndexedLens [i] s t [a] [b]
- loci :: forall a c s b f. Applicative f => (a -> f b) -> Bazaar (->) a c s -> f (Bazaar (->) b c s)
- mapAccumLOf :: LensLike (State acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
- mapAccumROf :: LensLike (Backwards (State acc)) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
- mapMOf :: LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t
- partsOf :: Functor f => Traversing (->) f s t a a -> LensLike f s t [a] [a]
- partsOf' :: ATraversal s t a a -> Lens s t [a] [a]
- scanl1Of :: LensLike (State (Maybe a)) s t a a -> (a -> a -> a) -> s -> t
- scanr1Of :: LensLike (Backwards (State (Maybe a))) s t a a -> (a -> a -> a) -> s -> t
- sequenceAOf :: LensLike f s t (f b) b -> s -> f t
- sequenceByOf :: Traversal s t (f b) b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> s -> f t
- sequenceOf :: LensLike (WrappedMonad m) s t (m b) b -> s -> m t
- singular :: (HasCallStack, Conjoined p, Functor f) => Traversing p f s t a a -> Over p f s t a a
- taking :: (Conjoined p, Applicative f) => Int -> Traversing p f s t a a -> Over p f s t a a
- transposeOf :: LensLike ZipList s t [a] a -> s -> [t]
- traversal :: ((a -> f b) -> s -> f t) -> LensLike f s t a b
- traverseByOf :: Traversal s t a b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (a -> f b) -> s -> f t
- traverseOf :: LensLike f s t a b -> (a -> f b) -> s -> f t
- traversed :: forall (f :: Type -> Type) a b. Traversable f => IndexedTraversal Int (f a) (f b) a b
- traversed1 :: forall (f :: Type -> Type) a b. Traversable1 f => IndexedTraversal1 Int (f a) (f b) a b
- traversed64 :: forall (f :: Type -> Type) a b. Traversable f => IndexedTraversal Int64 (f a) (f b) a b
- unsafePartsOf :: Functor f => Traversing (->) f s t a b -> LensLike f s t [a] [b]
- unsafePartsOf' :: ATraversal s t a b -> Lens s t [a] [b]
- unsafeSingular :: (HasCallStack, Conjoined p, Functor f) => Traversing p f s t a b -> Over p f s t a b
- sequenceBy :: Traversable t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> t (f a) -> f (t a)
- traverseBy :: Traversable t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (a -> f b) -> t a -> f (t b)
- class (Functor t, Foldable t) => Traversable (t :: Type -> Type) where
- traverse :: Applicative f => (a -> f b) -> t a -> f (t b)
- newtype Bazaar (p :: Type -> Type -> Type) a b t = Bazaar {
- runBazaar :: forall (f :: Type -> Type). Applicative f => p a (f b) -> f t
- type Bazaar' (p :: Type -> Type -> Type) a = Bazaar p a a
- newtype Bazaar1 (p :: Type -> Type -> Type) a b t = Bazaar1 {
- runBazaar1 :: forall (f :: Type -> Type). Apply f => p a (f b) -> f t
- type Bazaar1' (p :: Type -> Type -> Type) a = Bazaar1 p a a
- type ATraversal s t a b = LensLike (Bazaar (->) a b) s t a b
- type ATraversal' s a = ATraversal s s a a
- type ATraversal1 s t a b = LensLike (Bazaar1 (->) a b) s t a b
- type ATraversal1' s a = ATraversal1 s s a a
- type AnIndexedTraversal i s t a b = Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
- type AnIndexedTraversal' i s a = AnIndexedTraversal i s s a a
- type AnIndexedTraversal1 i s t a b = Over (Indexed i) (Bazaar1 (Indexed i) a b) s t a b
- type AnIndexedTraversal1' i s a = AnIndexedTraversal1 i s s a a
- class Ord k => TraverseMax k (m :: Type -> Type) | m -> k where
- traverseMax :: IndexedTraversal' k (m v) v
- class Ord k => TraverseMin k (m :: Type -> Type) | m -> k where
- traverseMin :: IndexedTraversal' k (m v) v
- type Traversing (p :: Type -> Type -> Type) (f :: Type -> Type) s t a b = Over p (BazaarT p f a b) s t a b
- type Traversing' (p :: Type -> Type -> Type) (f :: Type -> Type) s a = Traversing p f s s a a
- type Traversing1 (p :: Type -> Type -> Type) (f :: Type -> Type) s t a b = Over p (BazaarT1 p f a b) s t a b
- type Traversing1' (p :: Type -> Type -> Type) (f :: Type -> Type) s a = Traversing1 p f s s a a
- type IndexedTraversal i s t a b = forall (p :: Type -> Type -> Type) (f :: Type -> Type). (Indexable i p, Applicative f) => p a (f b) -> s -> f t
- type IndexedTraversal' i s a = IndexedTraversal i s s a a
- type IndexedTraversal1 i s t a b = forall (p :: Type -> Type -> Type) (f :: Type -> Type). (Indexable i p, Apply f) => p a (f b) -> s -> f t
- type IndexedTraversal1' i s a = IndexedTraversal1 i s s a a
- type Traversal s t a b = forall (f :: Type -> Type). Applicative f => (a -> f b) -> s -> f t
- type Traversal' s a = Traversal s s a a
- type Traversal1 s t a b = forall (f :: Type -> Type). Apply f => (a -> f b) -> s -> f t
- type Traversal1' s a = Traversal1 s s a a
- class (Foldable1 t, Traversable t) => Traversable1 (t :: Type -> Type) where
- module Control.Lens.Getter
- (%=) :: MonadState s m => ASetter s s a b -> (a -> b) -> m ()
- (%@=) :: MonadState s m => AnIndexedSetter i s s a b -> (i -> a -> b) -> m ()
- (%@~) :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t
- (%~) :: ASetter s t a b -> (a -> b) -> s -> t
- (&&=) :: MonadState s m => ASetter' s Bool -> Bool -> m ()
- (&&~) :: ASetter s t Bool Bool -> Bool -> s -> t
- (**=) :: (MonadState s m, Floating a) => ASetter' s a -> a -> m ()
- (**~) :: Floating a => ASetter s t a a -> a -> s -> t
- (*=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
- (*~) :: Num a => ASetter s t a a -> a -> s -> t
- (+=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
- (+~) :: Num a => ASetter s t a a -> a -> s -> t
- (-=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
- (-~) :: Num a => ASetter s t a a -> a -> s -> t
- (.=) :: MonadState s m => ASetter s s a b -> b -> m ()
- (.@=) :: MonadState s m => AnIndexedSetter i s s a b -> (i -> b) -> m ()
- (.@~) :: AnIndexedSetter i s t a b -> (i -> b) -> s -> t
- (.~) :: ASetter s t a b -> b -> s -> t
- (//=) :: (MonadState s m, Fractional a) => ASetter' s a -> a -> m ()
- (//~) :: Fractional a => ASetter s t a a -> a -> s -> t
- (<.=) :: MonadState s m => ASetter s s a b -> b -> m b
- (<.~) :: ASetter s t a b -> b -> s -> (b, t)
- (<>:=) :: (MonadState s m, Semigroup a) => ASetter' s a -> a -> m ()
- (<>:~) :: Semigroup b => ASetter s t b b -> b -> s -> t
- (<>=) :: (MonadState s m, Semigroup a) => ASetter' s a -> a -> m ()
- (<>~) :: Semigroup a => ASetter s t a a -> a -> s -> t
- (<?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m b
- (<?~) :: ASetter s t a (Maybe b) -> b -> s -> (b, t)
- (<~) :: MonadState s m => ASetter s s a b -> m b -> m ()
- (?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m ()
- (?~) :: ASetter s t a (Maybe b) -> b -> s -> t
- (^=) :: (MonadState s m, Num a, Integral e) => ASetter' s a -> e -> m ()
- (^^=) :: (MonadState s m, Fractional a, Integral e) => ASetter' s a -> e -> m ()
- (^^~) :: (Fractional a, Integral e) => ASetter s t a a -> e -> s -> t
- (^~) :: (Num a, Integral e) => ASetter s t a a -> e -> s -> t
- argument :: forall (p :: Type -> Type -> Type) b r a. Profunctor p => Setter (p b r) (p a r) a b
- assignA :: Arrow p => ASetter s t a b -> p s b -> p s t
- censoring :: MonadWriter w m => Setter w w u v -> (u -> v) -> m a -> m a
- cloneIndexPreservingSetter :: ASetter s t a b -> IndexPreservingSetter s t a b
- cloneIndexedSetter :: AnIndexedSetter i s t a b -> IndexedSetter i s t a b
- cloneSetter :: ASetter s t a b -> Setter s t a b
- contramapped :: forall (f :: Type -> Type) b a. Contravariant f => Setter (f b) (f a) a b
- icensoring :: MonadWriter w m => IndexedSetter i w w u v -> (i -> u -> v) -> m a -> m a
- ilocally :: MonadReader s m => AnIndexedSetter i s s a b -> (i -> a -> b) -> m r -> m r
- imapOf :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t
- imodifying :: MonadState s m => AnIndexedSetter i s s a b -> (i -> a -> b) -> m ()
- iover :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t
- ipassing :: MonadWriter w m => IndexedSetter i w w u v -> m (a, i -> u -> v) -> m a
- iset :: AnIndexedSetter i s t a b -> (i -> b) -> s -> t
- isets :: ((i -> a -> b) -> s -> t) -> IndexedSetter i s t a b
- lifted :: forall (m :: Type -> Type) a b. Monad m => Setter (m a) (m b) a b
- locally :: MonadReader s m => ASetter s s a b -> (a -> b) -> m r -> m r
- mapOf :: ASetter s t a b -> (a -> b) -> s -> t
- mapped :: forall (f :: Type -> Type) a b. Functor f => Setter (f a) (f b) a b
- modifying :: MonadState s m => ASetter s s a b -> (a -> b) -> m ()
- over :: ASetter s t a b -> (a -> b) -> s -> t
- passing :: MonadWriter w m => Setter w w u v -> m (a, u -> v) -> m a
- scribe :: (MonadWriter t m, Monoid s) => ASetter s t a b -> b -> m ()
- set :: ASetter s t a b -> b -> s -> t
- sets :: (Profunctor p, Profunctor q, Settable f) => (p a b -> q s t) -> Optical p q f s t a b
- setting :: ((a -> b) -> s -> t) -> IndexPreservingSetter s t a b
- (||=) :: MonadState s m => ASetter' s Bool -> Bool -> m ()
- (||~) :: ASetter s t Bool Bool -> Bool -> s -> t
- newtype Identity a = Identity {
- runIdentity :: a
- class (Applicative f, Distributive f, Traversable f) => Settable (f :: Type -> Type)
- type ASetter s t a b = (a -> Identity b) -> s -> Identity t
- type ASetter' s a = ASetter s s a a
- type AnIndexedSetter i s t a b = Indexed i a (Identity b) -> s -> Identity t
- type AnIndexedSetter' i s a = AnIndexedSetter i s s a a
- type Setting (p :: Type -> Type -> Type) s t a b = p a (Identity b) -> s -> Identity t
- type Setting' (p :: Type -> Type -> Type) s a = Setting p s s a a
- type IndexedSetter i s t a b = forall (f :: Type -> Type) (p :: Type -> Type -> Type). (Indexable i p, Settable f) => p a (f b) -> s -> f t
- type IndexedSetter' i s a = IndexedSetter i s s a a
- type Setter s t a b = forall (f :: Type -> Type). Settable f => (a -> f b) -> s -> f t
- type Setter' s a = Setter s s a a
- module Control.Lens.Tuple
- (&) :: a -> (a -> b) -> b
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- (#%%=) :: MonadState s m => ALens s s a b -> (a -> (r, b)) -> m r
- (#%%~) :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t
- (#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m ()
- (#%~) :: ALens s t a b -> (a -> b) -> s -> t
- (#=) :: MonadState s m => ALens s s a b -> b -> m ()
- (#~) :: ALens s t a b -> b -> s -> t
- (%%=) :: forall {k} s m p r (a :: k) b. MonadState s m => Over p ((,) r) s s a b -> p a (r, b) -> m r
- (%%@=) :: MonadState s m => Over (Indexed i) ((,) r) s s a b -> (i -> a -> (r, b)) -> m r
- (%%@~) :: forall {k1} i f s (t :: k1) a (b :: k1). Over (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t
- (%%~) :: forall {k} f s (t :: k) a (b :: k). LensLike f s t a b -> (a -> f b) -> s -> f t
- (&~) :: s -> State s a -> s
- (<#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m b
- (<#%~) :: ALens s t a b -> (a -> b) -> s -> (b, t)
- (<#=) :: MonadState s m => ALens s s a b -> b -> m b
- (<#~) :: ALens s t a b -> b -> s -> (b, t)
- (<%=) :: MonadState s m => LensLike ((,) b) s s a b -> (a -> b) -> m b
- (<%@=) :: MonadState s m => Over (Indexed i) ((,) b) s s a b -> (i -> a -> b) -> m b
- (<%@~) :: Over (Indexed i) ((,) b) s t a b -> (i -> a -> b) -> s -> (b, t)
- (<%~) :: LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
- (<&&=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
- (<&&~) :: LensLike ((,) Bool) s t Bool Bool -> Bool -> s -> (Bool, t)
- (<**=) :: (MonadState s m, Floating a) => LensLike' ((,) a) s a -> a -> m a
- (<**~) :: Floating a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- (<*=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
- (<*~) :: Num a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- (<+=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
- (<+~) :: Num a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- (<-=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
- (<-~) :: Num a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- (<//=) :: (MonadState s m, Fractional a) => LensLike' ((,) a) s a -> a -> m a
- (<//~) :: Fractional a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- (<<%=) :: (Strong p, MonadState s m) => Over p ((,) a) s s a b -> p a b -> m a
- (<<%@=) :: MonadState s m => Over (Indexed i) ((,) a) s s a b -> (i -> a -> b) -> m a
- (<<%@~) :: Over (Indexed i) ((,) a) s t a b -> (i -> a -> b) -> s -> (a, t)
- (<<%~) :: LensLike ((,) a) s t a b -> (a -> b) -> s -> (a, t)
- (<<&&=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
- (<<&&~) :: LensLike' ((,) Bool) s Bool -> Bool -> s -> (Bool, s)
- (<<**=) :: (MonadState s m, Floating a) => LensLike' ((,) a) s a -> a -> m a
- (<<**~) :: Floating a => LensLike' ((,) a) s a -> a -> s -> (a, s)
- (<<*=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
- (<<*~) :: Num a => LensLike' ((,) a) s a -> a -> s -> (a, s)
- (<<+=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
- (<<+~) :: Num a => LensLike' ((,) a) s a -> a -> s -> (a, s)
- (<<-=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
- (<<-~) :: Num a => LensLike' ((,) a) s a -> a -> s -> (a, s)
- (<<.=) :: MonadState s m => LensLike ((,) a) s s a b -> b -> m a
- (<<.~) :: LensLike ((,) a) s t a b -> b -> s -> (a, t)
- (<<//=) :: (MonadState s m, Fractional a) => LensLike' ((,) a) s a -> a -> m a
- (<<//~) :: Fractional a => LensLike' ((,) a) s a -> a -> s -> (a, s)
- (<<<>:=) :: (MonadState s m, Semigroup r) => LensLike' ((,) r) s r -> r -> m r
- (<<<>:~) :: Semigroup m => LensLike' ((,) m) s m -> m -> s -> (m, s)
- (<<<>=) :: (MonadState s m, Semigroup r) => LensLike' ((,) r) s r -> r -> m r
- (<<<>~) :: Semigroup r => LensLike' ((,) r) s r -> r -> s -> (r, s)
- (<<>:=) :: (MonadState s m, Semigroup r) => LensLike' ((,) r) s r -> r -> m r
- (<<>:~) :: Semigroup m => LensLike ((,) m) s t m m -> m -> s -> (m, t)
- (<<>=) :: (MonadState s m, Semigroup r) => LensLike' ((,) r) s r -> r -> m r
- (<<>~) :: Semigroup m => LensLike ((,) m) s t m m -> m -> s -> (m, t)
- (<<?=) :: MonadState s m => LensLike ((,) a) s s a (Maybe b) -> b -> m a
- (<<?~) :: LensLike ((,) a) s t a (Maybe b) -> b -> s -> (a, t)
- (<<^=) :: (MonadState s m, Num a, Integral e) => LensLike' ((,) a) s a -> e -> m a
- (<<^^=) :: (MonadState s m, Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> m a
- (<<^^~) :: (Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> s -> (a, s)
- (<<^~) :: (Num a, Integral e) => LensLike' ((,) a) s a -> e -> s -> (a, s)
- (<<||=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
- (<<||~) :: LensLike' ((,) Bool) s Bool -> Bool -> s -> (Bool, s)
- (<<~) :: MonadState s m => ALens s s a b -> m b -> m b
- (<^=) :: (MonadState s m, Num a, Integral e) => LensLike' ((,) a) s a -> e -> m a
- (<^^=) :: (MonadState s m, Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> m a
- (<^^~) :: (Fractional a, Integral e) => LensLike ((,) a) s t a a -> e -> s -> (a, t)
- (<^~) :: (Num a, Integral e) => LensLike ((,) a) s t a a -> e -> s -> (a, t)
- (<||=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
- (<||~) :: LensLike ((,) Bool) s t Bool Bool -> Bool -> s -> (Bool, t)
- (??) :: Functor f => f (a -> b) -> a -> f b
- (^#) :: s -> ALens s t a b -> a
- alongside :: LensLike (AlongsideLeft f b') s t a b -> LensLike (AlongsideRight f t) s' t' a' b' -> LensLike f (s, s') (t, t') (a, a') (b, b')
- choosing :: Functor f => LensLike f s t a b -> LensLike f s' t' a b -> LensLike f (Either s s') (Either t t') a b
- chosen :: forall a b p f. (Conjoined p, Functor f) => p a (f b) -> p (Either a a) (f (Either b b))
- cloneIndexPreservingLens :: ALens s t a b -> IndexPreservingLens s t a b
- cloneIndexedLens :: AnIndexedLens i s t a b -> IndexedLens i s t a b
- cloneLens :: ALens s t a b -> Lens s t a b
- devoid :: forall {k} p f (a :: k) b. Over p f Void Void a b
- fusing :: Functor f => LensLike (Yoneda f) s t a b -> LensLike f s t a b
- head1 :: forall (t :: Type -> Type) a. Traversable1 t => Lens' (t a) a
- ilens :: (s -> (i, a)) -> (s -> b -> t) -> IndexedLens i s t a b
- inside :: forall (p :: Type -> Type -> Type) s t a b e. Corepresentable p => ALens s t a b -> Lens (p e s) (p e t) (p e a) (p e b)
- iplens :: (s -> a) -> (s -> b -> t) -> IndexPreservingLens s t a b
- lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
- locus :: forall (p :: Type -> Type -> Type -> Type) a c s b. IndexedComonadStore p => Lens (p a c s) (p b c s) a b
- overA :: Arrow ar => LensLike (Context a b) s t a b -> ar a b -> ar s t
- storing :: ALens s t a b -> b -> s -> t
- united :: forall a f. Functor f => (() -> f ()) -> a -> f a
- withLens :: ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r
- type ALens s t a b = LensLike (Pretext (->) a b) s t a b
- type ALens' s a = ALens s s a a
- type AnIndexedLens i s t a b = Optical (Indexed i) (->) (Pretext (Indexed i) a b) s t a b
- type AnIndexedLens' i s a = AnIndexedLens i s s a a
- type IndexedLens i s t a b = forall (f :: Type -> Type) (p :: Type -> Type -> Type). (Indexable i p, Functor f) => p a (f b) -> s -> f t
- type IndexedLens' i s a = IndexedLens i s s a a
- type Lens s t a b = forall (f :: Type -> Type). Functor f => (a -> f b) -> s -> f t
- type Lens' s a = Lens s s a a
- module Control.Lens.Iso
- module Control.Lens.At
- (&&&) :: Arrow a => a b c -> a b c' -> a b (c, c')
- lensProduct :: ALens' s a -> ALens' s b -> Lens' s (a, b)
Documentation
type LensGet o i = o -> i Source #
Van Laarhoven style homogeneous lenses.
Mnemonic: "Lens outer inner", same type argument order as get :: o -> i.
Elementary lens operations
set' :: ASetter s t a b -> b -> s -> t Source #
Strictly set inner part i of structure o as designated by Lens' o i.
over' :: ASetter s t a b -> (a -> b) -> s -> t Source #
Strictly modify inner part i of structure o using a function i -> i.
Reader/State accessors and modifiers
(.=!) :: MonadState s m => ASetter s s a b -> b -> m () infix 4 Source #
Strictly write a part of the state.
(%=!) :: MonadState s m => ASetter s s a b -> (a -> b) -> m () infix 4 Source #
Strictly modify a part of the state.
(%==) :: MonadState s m => Lens' s a -> (a -> m a) -> m () infix 4 Source #
Modify a part of the state monadically.
(%==!) :: MonadState s m => Lens' s a -> (a -> m a) -> m () infix 4 Source #
Strictly modify a part of the state monadically.
(%%=!) :: MonadState o m => Lens' o i -> (i -> m (i, r)) -> m r infix 4 Source #
Strictly modify a part of the state monadically, and return some result.
locallyState :: MonadState o m => Lens' o i -> (i -> i) -> m r -> m r Source #
Modify a part of the state locally.
Lenses for collections
Re-exports
beside :: (Representable q, Applicative (Rep q), Applicative f, Bitraversable r) => Optical p q f s t a b -> Optical p q f s' t' a b -> Optical p q f (r s s') (r t t') a b #
Apply a different Traversal or Fold to each side of a Bitraversable container.
beside::Traversals t a b ->Traversals' t' a b ->Traversal(r s s') (r t t') a bbeside::IndexedTraversali s t a b ->IndexedTraversali s' t' a b ->IndexedTraversali (r s s') (r t t') a bbeside::IndexPreservingTraversals t a b ->IndexPreservingTraversals' t' a b ->IndexPreservingTraversal(r s s') (r t t') a b
beside::Traversals t a b ->Traversals' t' a b ->Traversal(s,s') (t,t') a bbeside::Lenss t a b ->Lenss' t' a b ->Traversal(s,s') (t,t') a bbeside::Folds a ->Folds' a ->Fold(s,s') abeside::Getters a ->Getters' a ->Fold(s,s') a
beside::IndexedTraversali s t a b ->IndexedTraversali s' t' a b ->IndexedTraversali (s,s') (t,t') a bbeside::IndexedLensi s t a b ->IndexedLensi s' t' a b ->IndexedTraversali (s,s') (t,t') a bbeside::IndexedFoldi s a ->IndexedFoldi s' a ->IndexedFoldi (s,s') abeside::IndexedGetteri s a ->IndexedGetteri s' a ->IndexedFoldi (s,s') a
beside::IndexPreservingTraversals t a b ->IndexPreservingTraversals' t' a b ->IndexPreservingTraversal(s,s') (t,t') a bbeside::IndexPreservingLenss t a b ->IndexPreservingLenss' t' a b ->IndexPreservingTraversal(s,s') (t,t') a bbeside::IndexPreservingFolds a ->IndexPreservingFolds' a ->IndexPreservingFold(s,s') abeside::IndexPreservingGetters a ->IndexPreservingGetters' a ->IndexPreservingFold(s,s') a
>>>("hello",["world","!!!"])^..beside id traverse["hello","world","!!!"]
both :: forall (r :: Type -> Type -> Type) a b. Bitraversable r => Traversal (r a a) (r b b) a b #
Traverse both parts of a Bitraversable container with matching types.
Usually that type will be a pair. Use each to traverse
the elements of arbitrary homogeneous tuples.
>>>(1,2) & both *~ 10(10,20)
>>>over both length ("hello","world")(5,5)
>>>("hello","world")^.both"helloworld"
both::Traversal(a, a) (b, b) a bboth::Traversal(Eithera a) (Eitherb b) a b
both1 :: forall (r :: Type -> Type -> Type) a b. Bitraversable1 r => Traversal1 (r a a) (r b b) a b #
Traverse both parts of a Bitraversable1 container with matching types.
Usually that type will be a pair.
both1::Traversal1(a, a) (b, b) a bboth1::Traversal1(Eithera a) (Eitherb b) a b
cloneIndexPreservingTraversal :: ATraversal s t a b -> IndexPreservingTraversal s t a b #
Clone a Traversal yielding an IndexPreservingTraversal that passes through
whatever index it is composed with.
cloneIndexPreservingTraversal1 :: ATraversal1 s t a b -> IndexPreservingTraversal1 s t a b #
Clone a Traversal1 yielding an IndexPreservingTraversal1 that passes through
whatever index it is composed with.
cloneIndexedTraversal :: AnIndexedTraversal i s t a b -> IndexedTraversal i s t a b #
Clone an IndexedTraversal yielding an IndexedTraversal with the same index.
cloneIndexedTraversal1 :: AnIndexedTraversal1 i s t a b -> IndexedTraversal1 i s t a b #
Clone an IndexedTraversal1 yielding an IndexedTraversal1 with the same index.
cloneTraversal :: ATraversal s t a b -> Traversal s t a b #
A Traversal is completely characterized by its behavior on a Bazaar.
Cloning a Traversal is one way to make sure you aren't given
something weaker, such as a Fold and can be
used as a way to pass around traversals that have to be monomorphic in f.
Note: This only accepts a proper Traversal (or Lens). To clone a Lens
as such, use cloneLens.
Note: It is usually better to use ReifiedTraversal and
runTraversal than to cloneTraversal. The
former can execute at full speed, while the latter needs to round trip through
the Bazaar.
>>>let foo l a = (view (getting (cloneTraversal l)) a, set (cloneTraversal l) 10 a)>>>foo both ("hello","world")("helloworld",(10,10))
cloneTraversal::LensLike(Bazaar(->) a b) s t a b ->Traversals t a b
cloneTraversal1 :: ATraversal1 s t a b -> Traversal1 s t a b #
A Traversal1 is completely characterized by its behavior on a Bazaar1.
confusing :: Applicative f => LensLike (Curried (Yoneda f) (Yoneda f)) s t a b -> LensLike f s t a b #
Fuse a Traversal by reassociating all of the ( operations to the
left and fusing all of the <*>)fmap calls into one. This is particularly
useful when constructing a Traversal using operations from GHC.Generics.
Given a pair of Traversals foo and bar,
confusing (foo.bar) = foo.bar
However, foo and bar are each going to use the Applicative they are given.
confusing exploits the Yoneda lemma to merge their separate uses of fmap into a single fmap.
and it further exploits an interesting property of the right Kan lift (or Curried) to left associate
all of the uses of ( to make it possible to fuse together more fmaps.<*>)
This is particularly effective when the choice of functor f is unknown at compile
time or when the Traversal foo.bar in the above description is recursive or complex
enough to prevent inlining.
fusing is a version of this combinator suitable for fusing lenses.
confusing::Traversals t a b ->Traversals t a b
deepOf :: (Conjoined p, Applicative f) => LensLike f s t s t -> Traversing p f s t a b -> Over p f s t a b #
Try the second traversal. If it returns no entries, try again with all entries from the first traversal, recursively.
deepOf::Folds s ->Folds a ->Folds adeepOf::Traversal's s ->Traversal's a ->Traversal's adeepOf::Traversals t s t ->Traversals t a b ->Traversals t a bdeepOf::Folds s ->IndexedFoldi s a ->IndexedFoldi s adeepOf::Traversals t s t ->IndexedTraversali s t a b ->IndexedTraversali s t a b
dropping :: (Conjoined p, Applicative f) => Int -> Over p (Indexing f) s t a a -> Over p f s t a a #
Visit all but the first n targets of a Traversal, Fold, Getter or Lens.
>>>("hello","world") ^? dropping 1 bothJust "world"
Dropping works on infinite traversals as well:
>>>[1..] ^? dropping 1 foldedJust 2
dropping::Int->Traversal's a ->Traversal's adropping::Int->Lens's a ->Traversal's adropping::Int->Iso's a ->Traversal's adropping::Int->Prism's a ->Traversal's adropping::Int->Getters a ->Folds adropping::Int->Folds a ->Folds adropping::Int->IndexedTraversal'i s a ->IndexedTraversal'i s adropping::Int->IndexedLens'i s a ->IndexedTraversal'i s adropping::Int->IndexedGetteri s a ->IndexedFoldi s adropping::Int->IndexedFoldi s a ->IndexedFoldi s a
element :: forall (t :: Type -> Type) a. Traversable t => Int -> IndexedTraversal' Int (t a) a #
Traverse the nth element of a Traversable container.
element≡elementOftraverse
elementOf :: forall (f :: Type -> Type) s t a. Applicative f => LensLike (Indexing f) s t a a -> Int -> IndexedLensLike Int f s t a a #
Traverse the nth elementOf a Traversal, Lens or
Iso if it exists.
>>>[[1],[3,4]] & elementOf (traverse.traverse) 1 .~ 5[[1],[5,4]]
>>>[[1],[3,4]] ^? elementOf (folded.folded) 1Just 3
>>>timingOut $ ['a'..] ^?! elementOf folded 5'f'
>>>timingOut $ take 10 $ elementOf traverse 3 .~ 16 $ [0..][0,1,2,16,4,5,6,7,8,9]
elementOf::Traversal's a ->Int->IndexedTraversal'Ints aelementOf::Folds a ->Int->IndexedFoldInts a
elementsOf :: forall (f :: Type -> Type) s t a. Applicative f => LensLike (Indexing f) s t a a -> (Int -> Bool) -> IndexedLensLike Int f s t a a #
Traverse (or fold) selected elements of a Traversal (or Fold) where their ordinal positions match a predicate.
elementsOf::Traversal's a -> (Int->Bool) ->IndexedTraversal'Ints aelementsOf::Folds a -> (Int->Bool) ->IndexedFoldInts a
failing :: (Conjoined p, Applicative f) => Traversing p f s t a b -> Over p f s t a b -> Over p f s t a b infixl 5 #
Try the first Traversal (or Fold), falling back on the second Traversal (or Fold) if it returns no entries.
This is only a valid Traversal if the second Traversal is disjoint from the result of the first or returns
exactly the same results. These conditions are trivially met when given a Lens, Iso, Getter, Prism or "affine" Traversal -- one that
has 0 or 1 target.
Mutatis mutandis for Fold.
>>>[0,1,2,3] ^? failing (ix 1) (ix 2)Just 1
>>>[0,1,2,3] ^? failing (ix 42) (ix 2)Just 2
failing::Traversals t a b ->Traversals t a b ->Traversals t a bfailing::Prisms t a b ->Prisms t a b ->Traversals t a bfailing::Folds a ->Folds a ->Folds a
These cases are also supported, trivially, but are boring, because the left hand side always succeeds.
failing::Lenss t a b ->Traversals t a b ->Traversals t a bfailing::Isos t a b ->Traversals t a b ->Traversals t a bfailing::Equalitys t a b ->Traversals t a b ->Traversals t a bfailing::Getters a ->Folds a ->Folds a
If both of the inputs are indexed, the result is also indexed, so you can apply this to a pair of indexed traversals or indexed folds, obtaining an indexed traversal or indexed fold.
failing::IndexedTraversali s t a b ->IndexedTraversali s t a b ->IndexedTraversali s t a bfailing::IndexedFoldi s a ->IndexedFoldi s a ->IndexedFoldi s a
These cases are also supported, trivially, but are boring, because the left hand side always succeeds.
failing::IndexedLensi s t a b ->IndexedTraversali s t a b ->IndexedTraversali s t a bfailing::IndexedGetteri s a ->IndexedGetteri s a ->IndexedFoldi s a
failover :: Alternative m => LensLike ((,) Any) s t a b -> (a -> b) -> s -> m t #
Try to map a function over this Traversal, failing if the Traversal has no targets.
>>>failover (element 3) (*2) [1,2] :: Maybe [Int]Nothing
>>>failover _Left (*2) (Right 4) :: Maybe (Either Int Int)Nothing
>>>failover _Right (*2) (Right 4) :: Maybe (Either Int Int)Just (Right 8)
failover :: Alternative m => Traversal s t a b -> (a -> b) -> s -> m t
forMOf :: LensLike (WrappedMonad m) s t a b -> s -> (a -> m b) -> m t #
forMOf is a flipped version of mapMOf, consistent with the definition of forM.
>>>forMOf both (1,3) $ \x -> [x, x + 1][(1,3),(1,4),(2,3),(2,4)]
forM≡forMOftraverseforMOfl ≡flip(mapMOfl)iforMOfl s ≡forMl s.Indexed
forMOf::Monadm =>Isos t a b -> s -> (a -> m b) -> m tforMOf::Monadm =>Lenss t a b -> s -> (a -> m b) -> m tforMOf::Monadm =>Traversals t a b -> s -> (a -> m b) -> m t
forOf :: LensLike f s t a b -> s -> (a -> f b) -> f t #
A version of traverseOf with the arguments flipped, such that:
>>>forOf each (1,2,3) print1 2 3 ((),(),())
This function is only provided for consistency, flip is strictly more general.
forOf≡flipforOf≡flip.traverseOf
for≡forOftraverseiforl s ≡forl s.Indexed
forOf::Functorf =>Isos t a b -> s -> (a -> f b) -> f tforOf::Functorf =>Lenss t a b -> s -> (a -> f b) -> f tforOf::Applicativef =>Traversals t a b -> s -> (a -> f b) -> f t
holes1Of :: Conjoined p => Over p (Bazaar1 p a a) s t a a -> s -> NonEmpty (Pretext p a a t) #
The non-empty version of holesOf.
This extract a non-empty list of immediate children according to a given
Traversal1 as editable contexts.
>>>let head1 f s = runPretext (NonEmpty.head $ holes1Of traversed1 s) f>>>('a' :| "bc") ^. head1'a'
>>>('a' :| "bc") & head1 %~ toUpper'A' :| "bc"
holes1Of::Iso's a -> s ->NonEmpty(Pretext'(->) a s)holes1Of::Lens's a -> s ->NonEmpty(Pretext'(->) a s)holes1Of::Traversal1's a -> s ->NonEmpty(Pretext'(->) a s)holes1Of::IndexedLens'i s a -> s ->NonEmpty(Pretext'(Indexedi) a s)holes1Of::IndexedTraversal1'i s a -> s ->NonEmpty(Pretext'(Indexedi) a s)
holesOf :: Conjoined p => Over p (Bazaar p a a) s t a a -> s -> [Pretext p a a t] #
The one-level version of contextsOf. This extracts a
list of the immediate children according to a given Traversal as editable
contexts.
Given a context you can use pos to see the
values, peek at what the structure would be
like with an edited result, or simply extract the original structure.
propChildren l x =toListOfl x==mappos(holesOfl x) propId l x =all(==x) [extractw | w <-holesOfl x]
holesOf::Iso's a -> s -> [Pretext'(->) a s]holesOf::Lens's a -> s -> [Pretext'(->) a s]holesOf::Traversal's a -> s -> [Pretext'(->) a s]holesOf::IndexedLens'i s a -> s -> [Pretext'(Indexedi) a s]holesOf::IndexedTraversal'i s a -> s -> [Pretext'(Indexedi) a s]
ifailover :: Alternative m => Over (Indexed i) ((,) Any) s t a b -> (i -> a -> b) -> s -> m t #
Try to map a function which uses the index over this IndexedTraversal, failing if the IndexedTraversal has no targets.
ifailover :: Alternative m => IndexedTraversal i s t a b -> (i -> a -> b) -> s -> m t
iforMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t) -> s -> (i -> a -> m b) -> m t #
Map each element of a structure targeted by a Lens to a monadic action,
evaluate these actions from left to right, and collect the results, with access
its position (and the arguments flipped).
forMOfl a ≡iforMOfl a.constiforMOf≡flip.imapMOf
iforMOf::Monadm =>IndexedLensi s t a b -> s -> (i -> a -> m b) -> m tiforMOf::Monadm =>IndexedTraversali s t a b -> s -> (i -> a -> m b) -> m t
iforOf :: (Indexed i a (f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t #
Traverse with an index (and the arguments flipped).
forOfl a ≡iforOfl a.constiforOf≡flip.itraverseOf
iforOf::Functorf =>IndexedLensi s t a b -> s -> (i -> a -> f b) -> f tiforOf::Applicativef =>IndexedTraversali s t a b -> s -> (i -> a -> f b) -> f tiforOf::Applyf =>IndexedTraversal1i s t a b -> s -> (i -> a -> f b) -> f t
ignored :: Applicative f => pafb -> s -> f s #
iloci :: forall i a c s b p f. (Indexable i p, Applicative f) => p a (f b) -> Bazaar (Indexed i) a c s -> f (Bazaar (Indexed i) b c s) #
This IndexedTraversal allows you to traverse the individual stores in
a Bazaar with access to their indices.
imapAccumLOf :: Over (Indexed i) (State acc) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t) #
Generalizes mapAccumL to an arbitrary IndexedTraversal with access to the index.
imapAccumLOf accumulates state from left to right.
mapAccumLOfl ≡imapAccumLOfl.const
imapAccumLOf::IndexedLensi s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)imapAccumLOf::IndexedTraversali s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
imapAccumROf :: Over (Indexed i) (Backwards (State acc)) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t) #
Generalizes mapAccumR to an arbitrary IndexedTraversal with access to the index.
imapAccumROf accumulates state from right to left.
mapAccumROfl ≡imapAccumROfl.const
imapAccumROf::IndexedLensi s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)imapAccumROf::IndexedTraversali s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
imapMOf :: Over (Indexed i) (WrappedMonad m) s t a b -> (i -> a -> m b) -> s -> m t #
Map each element of a structure targeted by a Lens to a monadic action,
evaluate these actions from left to right, and collect the results, with access
its position.
When you don't need access to the index mapMOf is more liberal in what it can accept.
mapMOfl ≡imapMOfl.const
imapMOf::Monadm =>IndexedLensi s t a b -> (i -> a -> m b) -> s -> m timapMOf::Monadm =>IndexedTraversali s t a b -> (i -> a -> m b) -> s -> m timapMOf::Bindm =>IndexedTraversal1i s t a b -> (i -> a -> m b) -> s -> m t
ipartsOf :: (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a a -> Over p f s t [a] [a] #
An indexed version of partsOf that receives the entire list of indices as its index.
ipartsOf' :: forall i p f s t a. (Indexable [i] p, Functor f) => Over (Indexed i) (Bazaar' (Indexed i) a) s t a a -> Over p f s t [a] [a] #
A type-restricted version of ipartsOf that can only be used with an IndexedTraversal.
itraverseOf :: (Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t #
Traversal with an index.
NB: When you don't need access to the index then you can just apply your IndexedTraversal
directly as a function!
itraverseOf≡withIndextraverseOfl =itraverseOfl.const=id
itraverseOf::Functorf =>IndexedLensi s t a b -> (i -> a -> f b) -> s -> f titraverseOf::Applicativef =>IndexedTraversali s t a b -> (i -> a -> f b) -> s -> f titraverseOf::Applyf =>IndexedTraversal1i s t a b -> (i -> a -> f b) -> s -> f t
iunsafePartsOf :: (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a b -> Over p f s t [a] [b] #
An indexed version of unsafePartsOf that receives the entire list of indices as its index.
iunsafePartsOf' :: forall i s t a b. Over (Indexed i) (Bazaar (Indexed i) a b) s t a b -> IndexedLens [i] s t [a] [b] #
loci :: forall a c s b f. Applicative f => (a -> f b) -> Bazaar (->) a c s -> f (Bazaar (->) b c s) #
mapAccumLOf :: LensLike (State acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) #
This generalizes mapAccumL to an arbitrary Traversal.
mapAccumL≡mapAccumLOftraverse
mapAccumLOf accumulates State from left to right.
mapAccumLOf::Isos t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)mapAccumLOf::Lenss t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)mapAccumLOf::Traversals t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumLOf::LensLike(Stateacc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)mapAccumLOfl f acc0 s =swap(runState(l (a ->state(acc ->swap(f acc a))) s) acc0)
mapAccumROf :: LensLike (Backwards (State acc)) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) #
This generalizes mapAccumR to an arbitrary Traversal.
mapAccumR≡mapAccumROftraverse
mapAccumROf accumulates State from right to left.
mapAccumROf::Isos t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)mapAccumROf::Lenss t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)mapAccumROf::Traversals t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumROf::LensLike(Backwards(Stateacc)) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapMOf :: LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t #
Map each element of a structure targeted by a Lens to a monadic action,
evaluate these actions from left to right, and collect the results.
>>>mapMOf both (\x -> [x, x + 1]) (1,3)[(1,3),(1,4),(2,3),(2,4)]
mapM≡mapMOftraverseimapMOfl ≡forMl.Indexed
mapMOf::Monadm =>Isos t a b -> (a -> m b) -> s -> m tmapMOf::Monadm =>Lenss t a b -> (a -> m b) -> s -> m tmapMOf::Monadm =>Traversals t a b -> (a -> m b) -> s -> m t
partsOf :: Functor f => Traversing (->) f s t a a -> LensLike f s t [a] [a] #
partsOf turns a Traversal into a Lens that resembles an early version of the uniplate (or biplate) type.
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.
When applied to a Fold the result is merely a Getter.
partsOf::Iso's a ->Lens's [a]partsOf::Lens's a ->Lens's [a]partsOf::Traversal's a ->Lens's [a]partsOf::Folds a ->Getters [a]partsOf::Getters a ->Getters [a]
partsOf' :: ATraversal s t a a -> Lens s t [a] [a] #
sequenceAOf :: LensLike f s t (f b) b -> s -> f t #
Evaluate each action in the structure from left to right, and collect the results.
>>>sequenceAOf both ([1,2],[3,4])[(1,3),(1,4),(2,3),(2,4)]
sequenceA≡sequenceAOftraverse≡traverseidsequenceAOfl ≡traverseOflid≡ lid
sequenceAOf::Functorf =>Isos t (f b) b -> s -> f tsequenceAOf::Functorf =>Lenss t (f b) b -> s -> f tsequenceAOf::Applicativef =>Traversals t (f b) b -> s -> f t
sequenceByOf :: Traversal s t (f b) b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> s -> f t #
Sequence a container using a specified Applicative.
This is like traverseBy where the Traversable instance can be specified by any Traversal
sequenceByOftraverse≡sequenceBy
sequenceOf :: LensLike (WrappedMonad m) s t (m b) b -> s -> m t #
Sequence the (monadic) effects targeted by a Lens in a container from left to right.
>>>sequenceOf each ([1,2],[3,4],[5,6])[(1,3,5),(1,3,6),(1,4,5),(1,4,6),(2,3,5),(2,3,6),(2,4,5),(2,4,6)]
sequence≡sequenceOftraversesequenceOfl ≡mapMOflidsequenceOfl ≡unwrapMonad.lWrapMonad
sequenceOf::Monadm =>Isos t (m b) b -> s -> m tsequenceOf::Monadm =>Lenss t (m b) b -> s -> m tsequenceOf::Monadm =>Traversals t (m b) b -> s -> m t
singular :: (HasCallStack, Conjoined p, Functor f) => Traversing p f s t a a -> Over p f s t a a #
This converts a Traversal that you "know" will target one or more elements to a Lens. It can
also be used to transform a non-empty Fold into a Getter.
The resulting Lens or Getter will be partial if the supplied Traversal returns
no results.
>>>[1,2,3] ^. singular _head1
>>>Left (ErrorCall "singular: empty traversal") <- try (evaluate ([] ^. singular _head)) :: IO (Either ErrorCall ())
>>>Left 4 ^. singular _Left4
>>>[1..10] ^. singular (ix 7)8
>>>[] & singular traverse .~ 0[]
singular::Traversals t a a ->Lenss t a asingular::Folds a ->Getters asingular::IndexedTraversali s t a a ->IndexedLensi s t a asingular::IndexedFoldi s a ->IndexedGetteri s a
taking :: (Conjoined p, Applicative f) => Int -> Traversing p f s t a a -> Over p f s t a a #
Visit the first n targets of a Traversal, Fold, Getter or Lens.
>>>[("hello","world"),("!!!","!!!")]^.. taking 2 (traverse.both)["hello","world"]
>>>timingOut $ [1..] ^.. taking 3 traverse[1,2,3]
>>>over (taking 5 traverse) succ "hello world""ifmmp world"
taking::Int->Traversal's a ->Traversal's ataking::Int->Lens's a ->Traversal's ataking::Int->Iso's a ->Traversal's ataking::Int->Prism's a ->Traversal's ataking::Int->Getters a ->Folds ataking::Int->Folds a ->Folds ataking::Int->IndexedTraversal'i s a ->IndexedTraversal'i s ataking::Int->IndexedLens'i s a ->IndexedTraversal'i s ataking::Int->IndexedGetteri s a ->IndexedFoldi s ataking::Int->IndexedFoldi s a ->IndexedFoldi s a
transposeOf :: LensLike ZipList s t [a] a -> s -> [t] #
This generalizes transpose to an arbitrary Traversal.
Note: transpose handles ragged inputs more intelligently, but for non-ragged inputs:
>>>transposeOf traverse [[1,2,3],[4,5,6]][[1,4],[2,5],[3,6]]
transpose≡transposeOftraverse
Since every Lens is a Traversal, we can use this as a form of
monadic strength as well:
transposeOf_2:: (b, [a]) -> [(b, a)]
traversal :: ((a -> f b) -> s -> f t) -> LensLike f s t a b #
Build a Traversal by providing a function which specifies the elements you wish to
focus.
The caller provides a function of type:
Applicative f => (a -> f b) -> s -> f t
Which is a higher order function which accepts a "focusing function" and applies
it to all desired focuses within s, then constructs a t using the Applicative
instance of f.
Only elements which are "focused" using the focusing function will be targeted by the resulting traversal.
For example, we can explicitly write a traversal which targets the first and third elements of a tuple like this:
firstAndThird :: Traversal (a, x, a) (b, x, b) a b
firstAndThird = traversal go
where
go :: Applicative f => (a -> f b) -> (a, x, a) -> f (b, x, b)
go focus (a, x, a') = liftA3 (,,) (focus a) (pure x) (focus a')
>>>(1,"two",3) & firstAndThird *~ 10(10,"two",30)
>>>over firstAndThird length ("one",2,"three")(3,2,5)
We can re-use existing Traversals when writing new ones by passing our focusing function
along to them. This example re-uses traverse to focus all elements in a list which is
embedded in a tuple. This traversal could also be written simply as _2 . traverse.
selectNested :: Traversal (x, [a]) (x, [b]) a b
selectNested = traversal go
where
go :: Applicative f => (a -> f b) -> (x, [a]) -> f (x, [b])
go focus (x, as) = liftA2 (,) (pure x) (traverse focus as)
>>>selectNested .~ "hello" $ (1,[2,3,4,5])(1,["hello","hello","hello","hello"])
>>>(1,[2,3,4,5]) & selectNested *~ 3(1,[6,9,12,15])
Note that the traversal function actually just returns the same function you pass to
it. The function it accepts is in fact a valid traversal all on its own! The use of
traversal does nothing except verify that the function it is passed matches the signature
of a valid traversal. One could remove the traversal combinator from either of the last
two examples and use the definition of go directly with no change in behaviour.
This function exists for consistency with the lens, prism and iso constructors
as well as to serve as a touchpoint for beginners who wish to construct their own
traversals but are uncertain how to do so.
traverseByOf :: Traversal s t a b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (a -> f b) -> s -> f t #
Traverse a container using a specified Applicative.
This is like traverseBy where the Traversable instance can be specified by any Traversal
traverseByOftraverse≡traverseBy
traverseOf :: LensLike f s t a b -> (a -> f b) -> s -> f t #
Map each element of a structure targeted by a Lens or Traversal,
evaluate these actions from left to right, and collect the results.
This function is only provided for consistency, id is strictly more general.
>>>traverseOf each print (1,2,3)1 2 3 ((),(),())
traverseOf≡iditraverseOfl ≡traverseOfl.IndexeditraverseOfitraversed≡itraverse
This yields the obvious law:
traverse≡traverseOftraverse
traverseOf::Functorf =>Isos t a b -> (a -> f b) -> s -> f ttraverseOf::Functorf =>Lenss t a b -> (a -> f b) -> s -> f ttraverseOf::Applyf =>Traversal1s t a b -> (a -> f b) -> s -> f ttraverseOf::Applicativef =>Traversals t a b -> (a -> f b) -> s -> f t
traversed :: forall (f :: Type -> Type) a b. Traversable f => IndexedTraversal Int (f a) (f b) a b #
Traverse any Traversable container. This is an IndexedTraversal that is indexed by ordinal position.
traversed1 :: forall (f :: Type -> Type) a b. Traversable1 f => IndexedTraversal1 Int (f a) (f b) a b #
Traverse any Traversable1 container. This is an IndexedTraversal1 that is indexed by ordinal position.
traversed64 :: forall (f :: Type -> Type) a b. Traversable f => IndexedTraversal Int64 (f a) (f b) a b #
Traverse any Traversable container. This is an IndexedTraversal that is indexed by ordinal position.
unsafePartsOf :: Functor f => Traversing (->) f s t a b -> LensLike f s t [a] [b] #
unsafePartsOf turns a Traversal into a uniplate (or biplate) family.
If you do not need the types of s and t to be different, it is recommended that
you use partsOf.
It is generally safer to traverse with the Bazaar rather than use this
combinator. However, it is sometimes convenient.
This is unsafe because if you don't supply at least as many b's as you were
given a's, then the reconstruction of t will result in an error!
When applied to a Fold the result is merely a Getter (and becomes safe).
unsafePartsOf::Isos t a b ->Lenss t [a] [b]unsafePartsOf::Lenss t a b ->Lenss t [a] [b]unsafePartsOf::Traversals t a b ->Lenss t [a] [b]unsafePartsOf::Folds a ->Getters [a]unsafePartsOf::Getters a ->Getters [a]
unsafePartsOf' :: ATraversal s t a b -> Lens s t [a] [b] #
unsafeSingular :: (HasCallStack, Conjoined p, Functor f) => Traversing p f s t a b -> Over p f s t a b #
This converts a Traversal that you "know" will target only one element to a Lens. It can also be
used to transform a Fold into a Getter.
The resulting Lens or Getter will be partial if the Traversal targets nothing
or more than one element.
>>>Left (ErrorCall "unsafeSingular: empty traversal") <- try (evaluate ([] & unsafeSingular traverse .~ 0)) :: IO (Either ErrorCall [Integer])
unsafeSingular::Traversals t a b ->Lenss t a bunsafeSingular::Folds a ->Getters aunsafeSingular::IndexedTraversali s t a b ->IndexedLensi s t a bunsafeSingular::IndexedFoldi s a ->IndexedGetteri s a
sequenceBy :: Traversable t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> t (f a) -> f (t a) #
Sequence a container using its Traversable instance using
explicitly provided Applicative operations. This is like sequence
where the Applicative instance can be manually specified.
traverseBy :: Traversable t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (a -> f b) -> t a -> f (t b) #
Traverse a container using its Traversable instance using
explicitly provided Applicative operations. This is like traverse
where the Applicative instance can be manually specified.
class (Functor t, Foldable t) => Traversable (t :: Type -> Type) where #
Functors representing data structures that can be transformed to
structures of the same shape by performing an Applicative (or,
therefore, Monad) action on each element from left to right.
A more detailed description of what same shape means, the various methods, how traversals are constructed, and example advanced use-cases can be found in the Overview section of Data.Traversable.
For the class laws see the Laws section of Data.Traversable.
Methods
traverse :: Applicative f => (a -> f b) -> t a -> f (t b) #
Map each element of a structure to an action, evaluate these actions
from left to right, and collect the results. For a version that ignores
the results see traverse_.
Examples
Basic usage:
In the first two examples we show each evaluated action mapping to the output structure.
>>>traverse Just [1,2,3,4]Just [1,2,3,4]
>>>traverse id [Right 1, Right 2, Right 3, Right 4]Right [1,2,3,4]
In the next examples, we show that Nothing and Left values short
circuit the created structure.
>>>traverse (const Nothing) [1,2,3,4]Nothing
>>>traverse (\x -> if odd x then Just x else Nothing) [1,2,3,4]Nothing
>>>traverse id [Right 1, Right 2, Right 3, Right 4, Left 0]Left 0
Instances
newtype Bazaar (p :: Type -> Type -> Type) a b t #
This is used to characterize a Traversal.
a.k.a. indexed Cartesian store comonad, indexed Kleene store comonad, or an indexed FunList.
http://twanvl.nl/blog/haskell/non-regular1
A Bazaar is like a Traversal that has already been applied to some structure.
Where a holds an Context a b ta and a function from b to
t, a holds Bazaar a b tN as and a function from N
bs to t, (where N might be infinite).
Mnemonically, a Bazaar holds many stores and you can easily add more.
This is a final encoding of Bazaar.
Constructors
| Bazaar | |
Fields
| |
Instances
| Profunctor p => Bizarre p (Bazaar p) # | |
Defined in Control.Lens.Internal.Bazaar Methods bazaar :: Applicative f => p a (f b) -> Bazaar p a b t -> f t # | |
| Corepresentable p => Sellable p (Bazaar p) # | |
Defined in Control.Lens.Internal.Bazaar | |
| Conjoined p => IndexedComonad (Bazaar p) # | |
| IndexedFunctor (Bazaar p) # | |
Defined in Control.Lens.Internal.Bazaar | |
| (a ~ b, Conjoined p) => Comonad (Bazaar p a b) # | |
| (a ~ b, Conjoined p) => ComonadApply (Bazaar p a b) # | |
| Applicative (Bazaar p a b) # | |
Defined in Control.Lens.Internal.Bazaar Methods pure :: a0 -> Bazaar p a b a0 # (<*>) :: Bazaar p a b (a0 -> b0) -> Bazaar p a b a0 -> Bazaar p a b b0 # liftA2 :: (a0 -> b0 -> c) -> Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b c # (*>) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b b0 # (<*) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b a0 # | |
| Functor (Bazaar p a b) # | |
| Apply (Bazaar p a b) # | |
Defined in Control.Lens.Internal.Bazaar | |
newtype Bazaar1 (p :: Type -> Type -> Type) a b t #
This is used to characterize a Traversal.
a.k.a. indexed Cartesian store comonad, indexed Kleene store comonad, or an indexed FunList.
http://twanvl.nl/blog/haskell/non-regular1
A Bazaar1 is like a Traversal that has already been applied to some structure.
Where a holds an Context a b ta and a function from b to
t, a holds Bazaar1 a b tN as and a function from N
bs to t, (where N might be infinite).
Mnemonically, a Bazaar1 holds many stores and you can easily add more.
This is a final encoding of Bazaar1.
Constructors
| Bazaar1 | |
Fields
| |
Instances
| Profunctor p => Bizarre1 p (Bazaar1 p) # | |
Defined in Control.Lens.Internal.Bazaar | |
| Corepresentable p => Sellable p (Bazaar1 p) # | |
Defined in Control.Lens.Internal.Bazaar | |
| Conjoined p => IndexedComonad (Bazaar1 p) # | |
| IndexedFunctor (Bazaar1 p) # | |
Defined in Control.Lens.Internal.Bazaar | |
| (a ~ b, Conjoined p) => Comonad (Bazaar1 p a b) # | |
| (a ~ b, Conjoined p) => ComonadApply (Bazaar1 p a b) # | |
| Functor (Bazaar1 p a b) # | |
| Apply (Bazaar1 p a b) # | |
Defined in Control.Lens.Internal.Bazaar Methods (<.>) :: Bazaar1 p a b (a0 -> b0) -> Bazaar1 p a b a0 -> Bazaar1 p a b b0 # (.>) :: Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b b0 # (<.) :: Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b a0 # liftF2 :: (a0 -> b0 -> c) -> Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b c # | |
type ATraversal s t a b = LensLike (Bazaar (->) a b) s t a b #
When you see this as an argument to a function, it expects a Traversal.
type ATraversal' s a = ATraversal s s a a #
typeATraversal'=SimpleATraversal
type ATraversal1 s t a b = LensLike (Bazaar1 (->) a b) s t a b #
When you see this as an argument to a function, it expects a Traversal1.
type ATraversal1' s a = ATraversal1 s s a a #
typeATraversal1'=SimpleATraversal1
type AnIndexedTraversal i s t a b = Over (Indexed i) (Bazaar (Indexed i) a b) s t a b #
When you see this as an argument to a function, it expects an IndexedTraversal.
type AnIndexedTraversal' i s a = AnIndexedTraversal i s s a a #
typeAnIndexedTraversal'=Simple(AnIndexedTraversali)
type AnIndexedTraversal1 i s t a b = Over (Indexed i) (Bazaar1 (Indexed i) a b) s t a b #
When you see this as an argument to a function, it expects an IndexedTraversal1.
type AnIndexedTraversal1' i s a = AnIndexedTraversal1 i s s a a #
typeAnIndexedTraversal1'=Simple(AnIndexedTraversal1i)
class Ord k => TraverseMax k (m :: Type -> Type) | m -> k where #
Allows IndexedTraversal of the value at the largest index.
Methods
traverseMax :: IndexedTraversal' k (m v) v #
IndexedTraversal of the element at the largest index.
Instances
| TraverseMax Int IntMap # | |
Defined in Control.Lens.Traversal Methods traverseMax :: IndexedTraversal' Int (IntMap v) v # | |
| Ord k => TraverseMax k (Map k) # | |
Defined in Control.Lens.Traversal Methods traverseMax :: IndexedTraversal' k (Map k v) v # | |
class Ord k => TraverseMin k (m :: Type -> Type) | m -> k where #
Allows IndexedTraversal the value at the smallest index.
Methods
traverseMin :: IndexedTraversal' k (m v) v #
IndexedTraversal of the element with the smallest index.
Instances
| TraverseMin Int IntMap # | |
Defined in Control.Lens.Traversal Methods traverseMin :: IndexedTraversal' Int (IntMap v) v # | |
| Ord k => TraverseMin k (Map k) # | |
Defined in Control.Lens.Traversal Methods traverseMin :: IndexedTraversal' k (Map k v) v # | |
type Traversing (p :: Type -> Type -> Type) (f :: Type -> Type) s t a b = Over p (BazaarT p f a b) s t a b #
When you see this as an argument to a function, it expects
- to be indexed if
pis an instance ofIndexedi, - to be unindexed if
pis(->), - a
TraversaliffisApplicative, - a
Getteriffis only aFunctorandContravariant, - a
Lensiffis only aFunctor, - a
FoldiffisApplicativeandContravariant.
type Traversing' (p :: Type -> Type -> Type) (f :: Type -> Type) s a = Traversing p f s s a a #
typeTraversing'f =Simple(Traversingf)
type Traversing1 (p :: Type -> Type -> Type) (f :: Type -> Type) s t a b = Over p (BazaarT1 p f a b) s t a b #
type Traversing1' (p :: Type -> Type -> Type) (f :: Type -> Type) s a = Traversing1 p f s s a a #
type IndexedTraversal i s t a b = forall (p :: Type -> Type -> Type) (f :: Type -> Type). (Indexable i p, Applicative f) => p a (f b) -> s -> f t #
Every IndexedTraversal is a valid Traversal or
IndexedFold.
The Indexed constraint is used to allow an IndexedTraversal to be used
directly as a Traversal.
The Traversal laws are still required to hold.
In addition, the index i should satisfy the requirement that it stays
unchanged even when modifying the value a, otherwise traversals like
indices break the Traversal laws.
type IndexedTraversal' i s a = IndexedTraversal i s s a a #
typeIndexedTraversal'i =Simple(IndexedTraversali)
type IndexedTraversal1 i s t a b = forall (p :: Type -> Type -> Type) (f :: Type -> Type). (Indexable i p, Apply f) => p a (f b) -> s -> f t #
type IndexedTraversal1' i s a = IndexedTraversal1 i s s a a #
type Traversal s t a b = forall (f :: Type -> Type). Applicative f => (a -> f b) -> s -> f t #
A Traversal can be used directly as a Setter or a Fold (but not as a Lens) and provides
the ability to both read and update multiple fields, subject to some relatively weak Traversal laws.
These have also been known as multilenses, but they have the signature and spirit of
traverse::Traversablef =>Traversal(f a) (f b) a b
and the more evocative name suggests their application.
Most of the time the Traversal you will want to use is just traverse, but you can also pass any
Lens or Iso as a Traversal, and composition of a Traversal (or Lens or Iso) with a Traversal (or Lens or Iso)
using (.) forms a valid Traversal.
The laws for a Traversal t follow from the laws for Traversable as stated in "The Essence of the Iterator Pattern".
tpure≡purefmap(t f).t g ≡getCompose.t (Compose.fmapf.g)
One consequence of this requirement is that a Traversal needs to leave the same number of elements as a
candidate for subsequent Traversal that it started with. Another testament to the strength of these laws
is that the caveat expressed in section 5.5 of the "Essence of the Iterator Pattern" about exotic
Traversable instances that traverse the same entry multiple times was actually already ruled out by the
second law in that same paper!
type Traversal' s a = Traversal s s a a #
typeTraversal'=SimpleTraversal
type Traversal1 s t a b = forall (f :: Type -> Type). Apply f => (a -> f b) -> s -> f t #
A Traversal which targets at least one element.
Note that since Apply is not a superclass of Applicative, a Traversal1
cannot always be used in place of a Traversal. In such circumstances
cloneTraversal will convert a Traversal1 into a Traversal.
type Traversal1' s a = Traversal1 s s a a #
class (Foldable1 t, Traversable t) => Traversable1 (t :: Type -> Type) where #
Instances
module Control.Lens.Getter
(%=) :: MonadState s m => ASetter s s a b -> (a -> b) -> m () infix 4 #
Map over the target of a Lens or all of the targets of a Setter or Traversal in our monadic state.
>>>execState (do _1 %= f;_2 %= g) (a,b)(f a,g b)
>>>execState (do both %= f) (a,b)(f a,f b)
(%=) ::MonadStates m =>Iso's a -> (a -> a) -> m () (%=) ::MonadStates m =>Lens's a -> (a -> a) -> m () (%=) ::MonadStates m =>Traversal's a -> (a -> a) -> m () (%=) ::MonadStates m =>Setter's a -> (a -> a) -> m ()
(%=) ::MonadStates m =>ASetters s a b -> (a -> b) -> m ()
(%@=) :: MonadState s m => AnIndexedSetter i s s a b -> (i -> a -> b) -> m () infix 4 #
Adjust every target in the current state of an IndexedSetter, IndexedLens or IndexedTraversal
with access to the index.
When you do not need access to the index then (%=) is more liberal in what it can accept.
l%=f ≡ l%@=constf
(%@=) ::MonadStates m =>IndexedSetteri s s a b -> (i -> a -> b) -> m () (%@=) ::MonadStates m =>IndexedLensi s s a b -> (i -> a -> b) -> m () (%@=) ::MonadStates m =>IndexedTraversali s t a b -> (i -> a -> b) -> m ()
(%@~) :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t infixr 4 #
Adjust every target of an IndexedSetter, IndexedLens or IndexedTraversal
with access to the index.
(%@~) ≡iover
When you do not need access to the index then (%~) is more liberal in what it can accept.
l%~f ≡ l%@~constf
(%@~) ::IndexedSetteri s t a b -> (i -> a -> b) -> s -> t (%@~) ::IndexedLensi s t a b -> (i -> a -> b) -> s -> t (%@~) ::IndexedTraversali s t a b -> (i -> a -> b) -> s -> t
(%~) :: ASetter s t a b -> (a -> b) -> s -> t infixr 4 #
Modifies the target of a Lens or all of the targets of a Setter or
Traversal with a user supplied function.
This is an infix version of over.
fmapf ≡mapped%~ffmapDefaultf ≡traverse%~f
>>>(a,b,c) & _3 %~ f(a,b,f c)
>>>(a,b) & both %~ f(f a,f b)
>>>_2 %~ length $ (1,"hello")(1,5)
>>>traverse %~ f $ [a,b,c][f a,f b,f c]
>>>traverse %~ even $ [1,2,3][False,True,False]
>>>traverse.traverse %~ length $ [["hello","world"],["!!!"]][[5,5],[3]]
(%~) ::Setters t a b -> (a -> b) -> s -> t (%~) ::Isos t a b -> (a -> b) -> s -> t (%~) ::Lenss t a b -> (a -> b) -> s -> t (%~) ::Traversals t a b -> (a -> b) -> s -> t
(&&=) :: MonadState s m => ASetter' s Bool -> Bool -> m () infix 4 #
Modify the target(s) of a Lens', Iso, Setter or Traversal by taking their logical && with a value.
>>>execState (do _1 &&= True; _2 &&= False; _3 &&= True; _4 &&= False) (True,True,False,False)(True,False,False,False)
(&&=) ::MonadStates m =>Setter'sBool->Bool-> m () (&&=) ::MonadStates m =>Iso'sBool->Bool-> m () (&&=) ::MonadStates m =>Lens'sBool->Bool-> m () (&&=) ::MonadStates m =>Traversal'sBool->Bool-> m ()
(&&~) :: ASetter s t Bool Bool -> Bool -> s -> t infixr 4 #
Logically && the target(s) of a Bool-valued Lens or Setter.
>>>both &&~ True $ (False, True)(False,True)
>>>both &&~ False $ (False, True)(False,False)
(&&~) ::Setter'sBool->Bool-> s -> s (&&~) ::Iso'sBool->Bool-> s -> s (&&~) ::Lens'sBool->Bool-> s -> s (&&~) ::Traversal'sBool->Bool-> s -> s
(**=) :: (MonadState s m, Floating a) => ASetter' s a -> a -> m () infix 4 #
Raise the target(s) of a numerically valued Lens, Setter or Traversal to an arbitrary power
>>>execState (do _1 **= c; _2 **= d) (a,b)(a**c,b**d)
(**=) :: (MonadStates m,Floatinga) =>Setter's a -> a -> m () (**=) :: (MonadStates m,Floatinga) =>Iso's a -> a -> m () (**=) :: (MonadStates m,Floatinga) =>Lens's a -> a -> m () (**=) :: (MonadStates m,Floatinga) =>Traversal's a -> a -> m ()
(**~) :: Floating a => ASetter s t a a -> a -> s -> t infixr 4 #
Raise the target(s) of a floating-point valued Lens, Setter or Traversal to an arbitrary power.
>>>(a,b) & _1 **~ c(a**c,b)
>>>(a,b) & both **~ c(a**c,b**c)
>>>_2 **~ 10 $ (3,2)(3,1024.0)
(**~) ::Floatinga =>Setter's a -> a -> s -> s (**~) ::Floatinga =>Iso's a -> a -> s -> s (**~) ::Floatinga =>Lens's a -> a -> s -> s (**~) ::Floatinga =>Traversal's a -> a -> s -> s
(*=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m () infix 4 #
Modify the target(s) of a Lens', Iso, Setter or Traversal by multiplying by value.
>>>execState (do _1 *= c; _2 *= d) (a,b)(a * c,b * d)
(*=) :: (MonadStates m,Numa) =>Setter's a -> a -> m () (*=) :: (MonadStates m,Numa) =>Iso's a -> a -> m () (*=) :: (MonadStates m,Numa) =>Lens's a -> a -> m () (*=) :: (MonadStates m,Numa) =>Traversal's a -> a -> m ()
(*~) :: Num a => ASetter s t a a -> a -> s -> t infixr 4 #
Multiply the target(s) of a numerically valued Lens, Iso, Setter or Traversal.
>>>(a,b) & _1 *~ c(a * c,b)
>>>(a,b) & both *~ c(a * c,b * c)
>>>(1,2) & _2 *~ 4(1,8)
>>>Just 24 & mapped *~ 2Just 48
(*~) ::Numa =>Setter's a -> a -> s -> s (*~) ::Numa =>Iso's a -> a -> s -> s (*~) ::Numa =>Lens's a -> a -> s -> s (*~) ::Numa =>Traversal's a -> a -> s -> s
(+=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m () infix 4 #
Modify the target(s) of a Lens', Iso, Setter or Traversal by adding a value.
Example:
fresh::MonadStateIntm => mIntfresh= doid+=1useid
>>>execState (do _1 += c; _2 += d) (a,b)(a + c,b + d)
>>>execState (do _1.at 1.non 0 += 10) (Map.fromList [(2,100)],"hello")(fromList [(1,10),(2,100)],"hello")
(+=) :: (MonadStates m,Numa) =>Setter's a -> a -> m () (+=) :: (MonadStates m,Numa) =>Iso's a -> a -> m () (+=) :: (MonadStates m,Numa) =>Lens's a -> a -> m () (+=) :: (MonadStates m,Numa) =>Traversal's a -> a -> m ()
(+~) :: Num a => ASetter s t a a -> a -> s -> t infixr 4 #
Increment the target(s) of a numerically valued Lens, Setter or Traversal.
>>>(a,b) & _1 +~ c(a + c,b)
>>>(a,b) & both +~ c(a + c,b + c)
>>>(1,2) & _2 +~ 1(1,3)
>>>[(a,b),(c,d)] & traverse.both +~ e[(a + e,b + e),(c + e,d + e)]
(+~) ::Numa =>Setter's a -> a -> s -> s (+~) ::Numa =>Iso's a -> a -> s -> s (+~) ::Numa =>Lens's a -> a -> s -> s (+~) ::Numa =>Traversal's a -> a -> s -> s
(-=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m () infix 4 #
Modify the target(s) of a Lens', Iso, Setter or Traversal by subtracting a value.
>>>execState (do _1 -= c; _2 -= d) (a,b)(a - c,b - d)
(-=) :: (MonadStates m,Numa) =>Setter's a -> a -> m () (-=) :: (MonadStates m,Numa) =>Iso's a -> a -> m () (-=) :: (MonadStates m,Numa) =>Lens's a -> a -> m () (-=) :: (MonadStates m,Numa) =>Traversal's a -> a -> m ()
(-~) :: Num a => ASetter s t a a -> a -> s -> t infixr 4 #
Decrement the target(s) of a numerically valued Lens, Iso, Setter or Traversal.
>>>(a,b) & _1 -~ c(a - c,b)
>>>(a,b) & both -~ c(a - c,b - c)
>>>_1 -~ 2 $ (1,2)(-1,2)
>>>mapped.mapped -~ 1 $ [[4,5],[6,7]][[3,4],[5,6]]
(-~) ::Numa =>Setter's a -> a -> s -> s (-~) ::Numa =>Iso's a -> a -> s -> s (-~) ::Numa =>Lens's a -> a -> s -> s (-~) ::Numa =>Traversal's a -> a -> s -> s
(.=) :: MonadState s m => ASetter s s a b -> b -> m () infix 4 #
Replace the target of a Lens or all of the targets of a Setter
or Traversal in our monadic state with a new value, irrespective of the
old.
This is an infix version of assign.
>>>execState (do _1 .= c; _2 .= d) (a,b)(c,d)
>>>execState (both .= c) (a,b)(c,c)
(.=) ::MonadStates m =>Iso's a -> a -> m () (.=) ::MonadStates m =>Lens's a -> a -> m () (.=) ::MonadStates m =>Traversal's a -> a -> m () (.=) ::MonadStates m =>Setter's a -> a -> m ()
It puts the state in the monad or it gets the hose again.
(.@=) :: MonadState s m => AnIndexedSetter i s s a b -> (i -> b) -> m () infix 4 #
Replace every target in the current state of an IndexedSetter, IndexedLens or IndexedTraversal
with access to the index.
When you do not need access to the index then (.=) is more liberal in what it can accept.
l.=b ≡ l.@=constb
(.@=) ::MonadStates m =>IndexedSetteri s s a b -> (i -> b) -> m () (.@=) ::MonadStates m =>IndexedLensi s s a b -> (i -> b) -> m () (.@=) ::MonadStates m =>IndexedTraversali s t a b -> (i -> b) -> m ()
(.@~) :: AnIndexedSetter i s t a b -> (i -> b) -> s -> t infixr 4 #
Replace every target of an IndexedSetter, IndexedLens or IndexedTraversal
with access to the index.
(.@~) ≡iset
When you do not need access to the index then (.~) is more liberal in what it can accept.
l.~b ≡ l.@~constb
(.@~) ::IndexedSetteri s t a b -> (i -> b) -> s -> t (.@~) ::IndexedLensi s t a b -> (i -> b) -> s -> t (.@~) ::IndexedTraversali s t a b -> (i -> b) -> s -> t
(.~) :: ASetter s t a b -> b -> s -> t infixr 4 #
Replace the target of a Lens or all of the targets of a Setter
or Traversal with a constant value.
This is an infix version of set, provided for consistency with (.=).
f<$a ≡mapped.~f$a
>>>(a,b,c,d) & _4 .~ e(a,b,c,e)
>>>(42,"world") & _1 .~ "hello"("hello","world")
>>>(a,b) & both .~ c(c,c)
(.~) ::Setters t a b -> b -> s -> t (.~) ::Isos t a b -> b -> s -> t (.~) ::Lenss t a b -> b -> s -> t (.~) ::Traversals t a b -> b -> s -> t
(//=) :: (MonadState s m, Fractional a) => ASetter' s a -> a -> m () infix 4 #
Modify the target(s) of a Lens', Iso, Setter or Traversal by dividing by a value.
>>>execState (do _1 //= c; _2 //= d) (a,b)(a / c,b / d)
(//=) :: (MonadStates m,Fractionala) =>Setter's a -> a -> m () (//=) :: (MonadStates m,Fractionala) =>Iso's a -> a -> m () (//=) :: (MonadStates m,Fractionala) =>Lens's a -> a -> m () (//=) :: (MonadStates m,Fractionala) =>Traversal's a -> a -> m ()
(//~) :: Fractional a => ASetter s t a a -> a -> s -> t infixr 4 #
Divide the target(s) of a numerically valued Lens, Iso, Setter or Traversal.
>>>(a,b) & _1 //~ c(a / c,b)
>>>(a,b) & both //~ c(a / c,b / c)
>>>("Hawaii",10) & _2 //~ 2("Hawaii",5.0)
(//~) ::Fractionala =>Setter's a -> a -> s -> s (//~) ::Fractionala =>Iso's a -> a -> s -> s (//~) ::Fractionala =>Lens's a -> a -> s -> s (//~) ::Fractionala =>Traversal's a -> a -> s -> s
(<.=) :: MonadState s m => ASetter s s a b -> b -> m b infix 4 #
Set with pass-through
This is useful for chaining assignment without round-tripping through your Monad stack.
do x <-_2<.=ninety_nine_bottles_of_beer_on_the_wall
If you do not need a copy of the intermediate result, then using l will avoid unused binding warnings..= d
(<.=) ::MonadStates m =>Setters s a b -> b -> m b (<.=) ::MonadStates m =>Isos s a b -> b -> m b (<.=) ::MonadStates m =>Lenss s a b -> b -> m b (<.=) ::MonadStates m =>Traversals s a b -> b -> m b
(<.~) :: ASetter s t a b -> b -> s -> (b, t) infixr 4 #
Set with pass-through.
This is mostly present for consistency, but may be useful for chaining assignments.
If you do not need a copy of the intermediate result, then using l directly is a good idea..~ t
>>>(a,b) & _1 <.~ c(c,(c,b))
>>>("good","morning","vietnam") & _3 <.~ "world"("world",("good","morning","world"))
>>>(42,Map.fromList [("goodnight","gracie")]) & _2.at "hello" <.~ Just "world"(Just "world",(42,fromList [("goodnight","gracie"),("hello","world")]))
(<.~) ::Setters t a b -> b -> s -> (b, t) (<.~) ::Isos t a b -> b -> s -> (b, t) (<.~) ::Lenss t a b -> b -> s -> (b, t) (<.~) ::Traversals t a b -> b -> s -> (b, t)
(<>:=) :: (MonadState s m, Semigroup a) => ASetter' s a -> a -> m () infix 4 #
(<>=) :: (MonadState s m, Semigroup a) => ASetter' s a -> a -> m () infix 4 #
Modify the target(s) of a Lens', Iso, Setter or Traversal by using (.<>)
>>>execState (do _1 <>= Sum c; _2 <>= Product d) (Sum a,Product b)(Sum {getSum = a + c},Product {getProduct = b * d})
>>>execState (both <>= "!!!") ("hello","world")("hello!!!","world!!!")
(<>=) :: (MonadStates m,Semigroupa) =>Setter's a -> a -> m () (<>=) :: (MonadStates m,Semigroupa) =>Iso's a -> a -> m () (<>=) :: (MonadStates m,Semigroupa) =>Lens's a -> a -> m () (<>=) :: (MonadStates m,Semigroupa) =>Traversal's a -> a -> m ()
(<>~) :: Semigroup a => ASetter s t a a -> a -> s -> t infixr 4 #
Modify the target of a Semigroup value by using (.<>)
>>>(Sum a,b) & _1 <>~ Sum c(Sum {getSum = a + c},b)
>>>(Sum a,Sum b) & both <>~ Sum c(Sum {getSum = a + c},Sum {getSum = b + c})
>>>both <>~ "!!!" $ ("hello","world")("hello!!!","world!!!")
(<>~) ::Semigroupa =>Setters t a a -> a -> s -> t (<>~) ::Semigroupa =>Isos t a a -> a -> s -> t (<>~) ::Semigroupa =>Lenss t a a -> a -> s -> t (<>~) ::Semigroupa =>Traversals t a a -> a -> s -> t
(<?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m b infix 4 #
Set Just a value with pass-through
This is useful for chaining assignment without round-tripping through your Monad stack.
do x <-at"foo"<?=ninety_nine_bottles_of_beer_on_the_wall
If you do not need a copy of the intermediate result, then using l will avoid unused binding warnings.?= d
(<?=) ::MonadStates m =>Setters s a (Maybeb) -> b -> m b (<?=) ::MonadStates m =>Isos s a (Maybeb) -> b -> m b (<?=) ::MonadStates m =>Lenss s a (Maybeb) -> b -> m b (<?=) ::MonadStates m =>Traversals s a (Maybeb) -> b -> m b
(<?~) :: ASetter s t a (Maybe b) -> b -> s -> (b, t) infixr 4 #
Set to Just a value with pass-through.
This is mostly present for consistency, but may be useful for for chaining assignments.
If you do not need a copy of the intermediate result, then using l directly is a good idea.?~ d
>>>import qualified Data.Map as Map>>>_2.at "hello" <?~ "world" $ (42,Map.fromList [("goodnight","gracie")])("world",(42,fromList [("goodnight","gracie"),("hello","world")]))
(<?~) ::Setters t a (Maybeb) -> b -> s -> (b, t) (<?~) ::Isos t a (Maybeb) -> b -> s -> (b, t) (<?~) ::Lenss t a (Maybeb) -> b -> s -> (b, t) (<?~) ::Traversals t a (Maybeb) -> b -> s -> (b, t)
(<~) :: MonadState s m => ASetter s s a b -> m b -> m () infixr 2 #
Run a monadic action, and set all of the targets of a Lens, Setter or Traversal to its result.
(<~) ::MonadStates m =>Isos s a b -> m b -> m () (<~) ::MonadStates m =>Lenss s a b -> m b -> m () (<~) ::MonadStates m =>Traversals s a b -> m b -> m () (<~) ::MonadStates m =>Setters s a b -> m b -> m ()
As a reasonable mnemonic, this lets you store the result of a monadic action in a Lens rather than
in a local variable.
do foo <- bar ...
will store the result in a variable, while
do foo <~ bar
...
(?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m () infix 4 #
Replace the target of a Lens or all of the targets of a Setter or Traversal in our monadic
state with Just a new value, irrespective of the old.
>>>execState (do at 1 ?= a; at 2 ?= b) Map.emptyfromList [(1,a),(2,b)]
>>>execState (do _1 ?= b; _2 ?= c) (Just a, Nothing)(Just b,Just c)
(?=) ::MonadStates m =>Iso's (Maybea) -> a -> m () (?=) ::MonadStates m =>Lens's (Maybea) -> a -> m () (?=) ::MonadStates m =>Traversal's (Maybea) -> a -> m () (?=) ::MonadStates m =>Setter's (Maybea) -> a -> m ()
(?~) :: ASetter s t a (Maybe b) -> b -> s -> t infixr 4 #
Set the target of a Lens, Traversal or Setter to Just a value.
l?~t ≡setl (Justt)
>>>Nothing & id ?~ aJust a
>>>Map.empty & at 3 ?~ xfromList [(3,x)]
?~ can be used type-changily:
>>>('a', ('b', 'c')) & _2.both ?~ 'x'('a',(Just 'x',Just 'x'))
(?~) ::Setters t a (Maybeb) -> b -> s -> t (?~) ::Isos t a (Maybeb) -> b -> s -> t (?~) ::Lenss t a (Maybeb) -> b -> s -> t (?~) ::Traversals t a (Maybeb) -> b -> s -> t
(^=) :: (MonadState s m, Num a, Integral e) => ASetter' s a -> e -> m () infix 4 #
Raise the target(s) of a numerically valued Lens, Setter or Traversal to a non-negative integral power.
(^=) :: (MonadStates m,Numa,Integrale) =>Setter's a -> e -> m () (^=) :: (MonadStates m,Numa,Integrale) =>Iso's a -> e -> m () (^=) :: (MonadStates m,Numa,Integrale) =>Lens's a -> e -> m () (^=) :: (MonadStates m,Numa,Integrale) =>Traversal's a -> e -> m ()
(^^=) :: (MonadState s m, Fractional a, Integral e) => ASetter' s a -> e -> m () infix 4 #
Raise the target(s) of a numerically valued Lens, Setter or Traversal to an integral power.
(^^=) :: (MonadStates m,Fractionala,Integrale) =>Setter's a -> e -> m () (^^=) :: (MonadStates m,Fractionala,Integrale) =>Iso's a -> e -> m () (^^=) :: (MonadStates m,Fractionala,Integrale) =>Lens's a -> e -> m () (^^=) :: (MonadStates m,Fractionala,Integrale) =>Traversal's a -> e -> m ()
(^^~) :: (Fractional a, Integral e) => ASetter s t a a -> e -> s -> t infixr 4 #
Raise the target(s) of a fractionally valued Lens, Setter or Traversal to an integral power.
>>>(1,2) & _2 ^^~ (-1)(1,0.5)
(^^~) :: (Fractionala,Integrale) =>Setter's a -> e -> s -> s (^^~) :: (Fractionala,Integrale) =>Iso's a -> e -> s -> s (^^~) :: (Fractionala,Integrale) =>Lens's a -> e -> s -> s (^^~) :: (Fractionala,Integrale) =>Traversal's a -> e -> s -> s
(^~) :: (Num a, Integral e) => ASetter s t a a -> e -> s -> t infixr 4 #
Raise the target(s) of a numerically valued Lens, Setter or Traversal to a non-negative integral power.
>>>(1,3) & _2 ^~ 2(1,9)
(^~) :: (Numa,Integrale) =>Setter's a -> e -> s -> s (^~) :: (Numa,Integrale) =>Iso's a -> e -> s -> s (^~) :: (Numa,Integrale) =>Lens's a -> e -> s -> s (^~) :: (Numa,Integrale) =>Traversal's a -> e -> s -> s
argument :: forall (p :: Type -> Type -> Type) b r a. Profunctor p => Setter (p b r) (p a r) a b #
This Setter can be used to map over the input of a Profunctor.
The most common Profunctor to use this with is (->).
>>>(argument %~ f) g xg (f x)
>>>(argument %~ show) length [1,2,3]7
>>>(argument %~ f) h x yh (f x) y
Map over the argument of the result of a function -- i.e., its second argument:
>>>(mapped.argument %~ f) h x yh x (f y)
argument::Setter(b -> r) (a -> r) a b
assignA :: Arrow p => ASetter s t a b -> p s b -> p s t #
Run an arrow command and use the output to set all the targets of
a Lens, Setter or Traversal to the result.
assignA can be used very similarly to (<~), except that the type of
the object being modified can change; for example:
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::Arrowp =>Isos t a b -> p s b -> p s tassignA::Arrowp =>Lenss t a b -> p s b -> p s tassignA::Arrowp =>Traversals t a b -> p s b -> p s tassignA::Arrowp =>Setters t a b -> p s b -> p s t
censoring :: MonadWriter w m => Setter w w u v -> (u -> v) -> m a -> m a #
This is a generalization of censor that allows you to censor just a
portion of the resulting MonadWriter.
cloneIndexPreservingSetter :: ASetter s t a b -> IndexPreservingSetter s t a b #
Build an IndexPreservingSetter from any Setter.
cloneIndexedSetter :: AnIndexedSetter i s t a b -> IndexedSetter i s t a b #
Clone an IndexedSetter.
contramapped :: forall (f :: Type -> Type) b a. Contravariant f => Setter (f b) (f a) a b #
This Setter can be used to map over all of the inputs to a Contravariant.
contramap≡overcontramapped
>>>getPredicate (over contramapped (*2) (Predicate even)) 5True
>>>getOp (over contramapped (*5) (Op show)) 100"500"
>>>Prelude.map ($ 1) $ over (mapped . _Unwrapping' Op . contramapped) (*12) [(*2),(+1),(^3)][24,13,1728]
icensoring :: MonadWriter w m => IndexedSetter i w w u v -> (i -> u -> v) -> m a -> m a #
This is a generalization of censor that allows you to censor just a
portion of the resulting MonadWriter, with access to the index of an
IndexedSetter.
ilocally :: MonadReader s m => AnIndexedSetter i s s a b -> (i -> a -> b) -> m r -> m r #
This is a generalization of locally that allows one to make indexed
local changes to a Reader environment associated with the target of a
Setter, Lens, or Traversal.
locallyl f ≡ilocallyl f . constilocallyl f ≡locallyl f .Indexed
ilocally :: MonadReader s m =>IndexedLenss s a b -> (i -> a -> b) -> m r -> m r ilocally :: MonadReader s m =>IndexedTraversals s a b -> (i -> a -> b) -> m r -> m r ilocally :: MonadReader s m =>IndexedSetters s a b -> (i -> a -> b) -> m r -> m r
imapOf :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t #
Deprecated: Use iover
Map with index. (Deprecated alias for iover).
When you do not need access to the index, then mapOf is more liberal in what it can accept.
mapOfl ≡imapOfl.const
imapOf::IndexedSetteri s t a b -> (i -> a -> b) -> s -> timapOf::IndexedLensi s t a b -> (i -> a -> b) -> s -> timapOf::IndexedTraversali s t a b -> (i -> a -> b) -> s -> t
imodifying :: MonadState s m => AnIndexedSetter i s s a b -> (i -> a -> b) -> m () #
This is an alias for (%@=).
iover :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t #
Map with index. This is an alias for imapOf.
When you do not need access to the index, then over is more liberal in what it can accept.
overl ≡ioverl.constioverl ≡overl.Indexed
iover::IndexedSetteri s t a b -> (i -> a -> b) -> s -> tiover::IndexedLensi s t a b -> (i -> a -> b) -> s -> tiover::IndexedTraversali s t a b -> (i -> a -> b) -> s -> t
ipassing :: MonadWriter w m => IndexedSetter i w w u v -> m (a, i -> u -> v) -> m a #
This is a generalization of pass that allows you to modify just a
portion of the resulting MonadWriter with access to the index of an
IndexedSetter.
iset :: AnIndexedSetter i s t a b -> (i -> b) -> s -> t #
Set with index. Equivalent to iover with the current value ignored.
When you do not need access to the index, then set is more liberal in what it can accept.
setl ≡isetl.const
iset::IndexedSetteri s t a b -> (i -> b) -> s -> tiset::IndexedLensi s t a b -> (i -> b) -> s -> tiset::IndexedTraversali s t a b -> (i -> b) -> s -> t
isets :: ((i -> a -> b) -> s -> t) -> IndexedSetter i s t a b #
Build an IndexedSetter from an imap-like function.
Your supplied function f is required to satisfy:
fid≡idf g.f h ≡ f (g.h)
Equational reasoning:
isets.iover≡idiover.isets≡id
Another way to view isets is that it takes a "semantic editor combinator"
which has been modified to carry an index and transforms it into a IndexedSetter.
lifted :: forall (m :: Type -> Type) a b. Monad m => Setter (m a) (m b) a b #
This setter can be used to modify all of the values in a Monad.
You sometimes have to use this rather than mapped -- due to
temporary insanity Functor was not a superclass of Monad until
GHC 7.10.
liftM≡overlifted
>>>over lifted f [a,b,c][f a,f b,f c]
>>>set lifted b (Just a)Just b
If you want an IndexPreservingSetter use .setting liftM
locally :: MonadReader s m => ASetter s s a b -> (a -> b) -> m r -> m r #
Modify the value of the Reader environment associated with the target of a
Setter, Lens, or Traversal.
locallylida ≡ alocallyl f.locally l g ≡locallyl (f.g)
>>>(1,1) & locally _1 (+1) (uncurry (+))3
>>>"," & locally ($) ("Hello" <>) (<> " world!")"Hello, world!"
locally :: MonadReader s m =>Isos s a b -> (a -> b) -> m r -> m r locally :: MonadReader s m =>Lenss s a b -> (a -> b) -> m r -> m r locally :: MonadReader s m =>Traversals s a b -> (a -> b) -> m r -> m r locally :: MonadReader s m =>Setters s a b -> (a -> b) -> m r -> m r
mapped :: forall (f :: Type -> Type) a b. Functor f => Setter (f a) (f b) a b #
This Setter can be used to map over all of the values in a Functor.
fmap≡overmappedfmapDefault≡overtraverse(<$) ≡setmapped
>>>over mapped f [a,b,c][f a,f b,f c]
>>>over mapped (+1) [1,2,3][2,3,4]
>>>set mapped x [a,b,c][x,x,x]
>>>[[a,b],[c]] & mapped.mapped +~ x[[a + x,b + x],[c + x]]
>>>over (mapped._2) length [("hello","world"),("leaders","!!!")][("hello",5),("leaders",3)]
mapped::Functorf =>Setter(f a) (f b) a b
If you want an IndexPreservingSetter use .setting fmap
modifying :: MonadState s m => ASetter s s a b -> (a -> b) -> m () #
This is an alias for (%=).
over :: ASetter s t a b -> (a -> b) -> s -> t #
Modify the target of a Lens or all the targets of a Setter or Traversal
with a function.
fmap≡overmappedfmapDefault≡overtraversesets.over≡idover.sets≡id
Given any valid Setter l, you can also rely on the law:
overl f.overl g =overl (f.g)
e.g.
>>>over mapped f (over mapped g [a,b,c]) == over mapped (f . g) [a,b,c]True
Another way to view over is to say that it transforms a Setter into a
"semantic editor combinator".
>>>over mapped f (Just a)Just (f a)
>>>over mapped (*10) [1,2,3][10,20,30]
>>>over _1 f (a,b)(f a,b)
>>>over _1 show (10,20)("10",20)
over::Setters t a b -> (a -> b) -> s -> tover::ASetters t a b -> (a -> b) -> s -> t
passing :: MonadWriter w m => Setter w w u v -> m (a, u -> v) -> m a #
This is a generalization of pass that allows you to modify just a
portion of the resulting MonadWriter.
scribe :: (MonadWriter t m, Monoid s) => ASetter s t a b -> b -> m () #
Write to a fragment of a larger Writer format.
set :: ASetter s t a b -> b -> s -> t #
Replace the target of a Lens or all of the targets of a Setter
or Traversal with a constant value.
(<$) ≡setmapped
>>>set _2 "hello" (1,())(1,"hello")
>>>set mapped () [1,2,3,4][(),(),(),()]
Note: Attempting to set a Fold or Getter will fail at compile time with an
relatively nice error message.
set::Setters t a b -> b -> s -> tset::Isos t a b -> b -> s -> tset::Lenss t a b -> b -> s -> tset::Traversals t a b -> b -> s -> t
sets :: (Profunctor p, Profunctor q, Settable f) => (p a b -> q s t) -> Optical p q f s t a b #
Build a Setter, IndexedSetter or IndexPreservingSetter depending on your choice of Profunctor.
sets:: ((a -> b) -> s -> t) ->Setters t a b
setting :: ((a -> b) -> s -> t) -> IndexPreservingSetter s t a b #
Build an index-preserving Setter from a map-like function.
Your supplied function f is required to satisfy:
fid≡idf g.f h ≡ f (g.h)
Equational reasoning:
setting.over≡idover.setting≡id
Another way to view sets is that it takes a "semantic editor combinator"
and transforms it into a Setter.
setting:: ((a -> b) -> s -> t) ->Setters t a b
(||=) :: MonadState s m => ASetter' s Bool -> Bool -> m () infix 4 #
Modify the target(s) of a Lens', 'Iso, Setter or Traversal by taking their logical || with a value.
>>>execState (do _1 ||= True; _2 ||= False; _3 ||= True; _4 ||= False) (True,True,False,False)(True,True,True,False)
(||=) ::MonadStates m =>Setter'sBool->Bool-> m () (||=) ::MonadStates m =>Iso'sBool->Bool-> m () (||=) ::MonadStates m =>Lens'sBool->Bool-> m () (||=) ::MonadStates m =>Traversal'sBool->Bool-> m ()
(||~) :: ASetter s t Bool Bool -> Bool -> s -> t infixr 4 #
Logically || the target(s) of a Bool-valued Lens or Setter.
>>>both ||~ True $ (False,True)(True,True)
>>>both ||~ False $ (False,True)(False,True)
(||~) ::Setter'sBool->Bool-> s -> s (||~) ::Iso'sBool->Bool-> s -> s (||~) ::Lens'sBool->Bool-> s -> s (||~) ::Traversal'sBool->Bool-> s -> s
Identity functor and monad. (a non-strict monad)
Examples
>>>fmap (+1) (Identity 0)Identity 1
>>>Identity [1, 2, 3] <> Identity [4, 5, 6]Identity [1,2,3,4,5,6]
>>> do
x <- Identity 10
y <- Identity (x + 5)
pure (x + y)
Identity 25
Since: base-4.8.0.0
Constructors
| Identity | |
Fields
| |
Instances
class (Applicative f, Distributive f, Traversable f) => Settable (f :: Type -> Type) #
Minimal complete definition
Instances
| Settable Identity # | So you can pass our |
Defined in Control.Lens.Internal.Setter Methods untainted :: Identity a -> a # untaintedDot :: Profunctor p => p a (Identity b) -> p a b # taintedDot :: Profunctor p => p a b -> p a (Identity b) # | |
| Settable f => Settable (Backwards f) # | |
Defined in Control.Lens.Internal.Setter Methods untainted :: Backwards f a -> a # untaintedDot :: Profunctor p => p a (Backwards f b) -> p a b # taintedDot :: Profunctor p => p a b -> p a (Backwards f b) # | |
| (Settable f, Settable g) => Settable (Compose f g) # | |
Defined in Control.Lens.Internal.Setter Methods untainted :: Compose f g a -> a # untaintedDot :: Profunctor p => p a (Compose f g b) -> p a b # taintedDot :: Profunctor p => p a b -> p a (Compose f g b) # | |
type ASetter s t a b = (a -> Identity b) -> s -> Identity t #
Running a Setter instantiates it to a concrete type.
When consuming a setter directly to perform a mapping, you can use this type, but most user code will not need to use this type.
type AnIndexedSetter i s t a b = Indexed i a (Identity b) -> s -> Identity t #
Running an IndexedSetter instantiates it to a concrete type.
When consuming a setter directly to perform a mapping, you can use this type, but most user code will not need to use this type.
type AnIndexedSetter' i s a = AnIndexedSetter i s s a a #
typeAnIndexedSetter'i =Simple(AnIndexedSetteri)
type Setting (p :: Type -> Type -> Type) s t a b = p a (Identity b) -> s -> Identity t #
This is a convenient alias when defining highly polymorphic code that takes both
ASetter and AnIndexedSetter as appropriate. If a function takes this it is
expecting one of those two things based on context.
type Setting' (p :: Type -> Type -> Type) s a = Setting p s s a a #
This is a convenient alias when defining highly polymorphic code that takes both
ASetter' and AnIndexedSetter' as appropriate. If a function takes this it is
expecting one of those two things based on context.
type IndexedSetter i s t a b = forall (f :: Type -> Type) (p :: Type -> Type -> Type). (Indexable i p, Settable f) => p a (f b) -> s -> f t #
Every IndexedSetter is a valid Setter.
The Setter laws are still required to hold.
type IndexedSetter' i s a = IndexedSetter i s s a a #
typeIndexedSetter'i =Simple(IndexedSetteri)
type Setter s t a b = forall (f :: Type -> Type). Settable f => (a -> f b) -> s -> f t #
The only LensLike law that can apply to a Setter l is that
setl y (setl x a) ≡setl y a
You can't view a Setter in general, so the other two laws are irrelevant.
However, two Functor laws apply to a Setter:
overlid≡idoverl f.overl g ≡overl (f.g)
These can be stated more directly:
lpure≡purel f.untainted.l g ≡ l (f.untainted.g)
You can compose a Setter with a Lens or a Traversal using (.) from the Prelude
and the result is always only a Setter and nothing more.
>>>over traverse f [a,b,c,d][f a,f b,f c,f d]
>>>over _1 f (a,b)(f a,b)
>>>over (traverse._1) f [(a,b),(c,d)][(f a,b),(f c,d)]
>>>over both f (a,b)(f a,f b)
>>>over (traverse.both) f [(a,b),(c,d)][(f a,f b),(f c,f d)]
module Control.Lens.Tuple
(&) :: a -> (a -> b) -> b infixl 1 #
& 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 $.
This is a version of , where flip idid is specialized from a -> a to (a -> b) -> (a -> b)
which by the associativity of (->) is (a -> b) -> a -> b.
flipping this yields a -> (a -> b) -> b which is the type signature of &
Examples
>>>5 & (+1) & show"6"
>>>sqrt $ [1 / n^2 | n <- [1..1000]] & sum & (*6)3.1406380562059946
Since: base-4.8.0.0
(#%%=) :: MonadState s m => ALens s s a b -> (a -> (r, b)) -> m r infix 4 #
(#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m () infix 4 #
(#=) :: MonadState s m => ALens s s a b -> b -> m () infix 4 #
(%%=) :: forall {k} s m p r (a :: k) b. MonadState s m => Over p ((,) r) s s a b -> p a (r, b) -> m r infix 4 #
Modify the target of a Lens in the current state returning some extra
information of type r or modify all targets of a
Traversal in the current state, extracting extra
information of type r and return a monoidal summary of the changes.
>>>runState (_1 %%= \x -> (f x, g x)) (a,b)(f a,(g a,b))
(%%=) ≡ (state.)
It may be useful to think of (%%=), instead, as having either of the
following more restricted type signatures:
(%%=) ::MonadStates m =>Isos s a b -> (a -> (r, b)) -> m r (%%=) ::MonadStates m =>Lenss s a b -> (a -> (r, b)) -> m r (%%=) :: (MonadStates m,Monoidr) =>Traversals s a b -> (a -> (r, b)) -> m r
(%%@=) :: MonadState s m => Over (Indexed i) ((,) r) s s a b -> (i -> a -> (r, b)) -> m r infix 4 #
Adjust the target of an IndexedLens returning a supplementary result, or
adjust all of the targets of an IndexedTraversal within the current state, and
return a monoidal summary of the supplementary results.
l%%@=f ≡state(l%%@~f)
(%%@=) ::MonadStates m =>IndexedLensi s s a b -> (i -> a -> (r, b)) -> s -> m r (%%@=) :: (MonadStates m,Monoidr) =>IndexedTraversali s s a b -> (i -> a -> (r, b)) -> s -> m r
(%%@~) :: forall {k1} i f s (t :: k1) a (b :: k1). Over (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t infixr 4 #
Adjust the target of an IndexedLens returning a supplementary result, or
adjust all of the targets of an IndexedTraversal and return a monoidal summary
of the supplementary results and the answer.
(%%@~) ≡withIndex
(%%@~) ::Functorf =>IndexedLensi s t a b -> (i -> a -> f b) -> s -> f t (%%@~) ::Applicativef =>IndexedTraversali s t a b -> (i -> a -> f b) -> s -> f t
In particular, it is often useful to think of this function as having one of these even more restricted type signatures:
(%%@~) ::IndexedLensi s t a b -> (i -> a -> (r, b)) -> s -> (r, t) (%%@~) ::Monoidr =>IndexedTraversali s t a b -> (i -> a -> (r, b)) -> s -> (r, t)
(%%~) :: forall {k} f s (t :: k) a (b :: k). LensLike f s t a b -> (a -> f b) -> s -> f t infixr 4 #
(%%~) can be used in one of two scenarios:
When applied to a Lens, it can edit the target of the Lens in a
structure, extracting a functorial result.
When applied to a Traversal, it can edit the
targets of the traversals, extracting an applicative summary of its
actions.
>>>[66,97,116,109,97,110] & each %%~ \a -> ("na", chr a)("nananananana","Batman")
For all that the definition of this combinator is just:
(%%~) ≡id
It may be beneficial to think about it as if it had these even more restricted types, however:
(%%~) ::Functorf =>Isos t a b -> (a -> f b) -> s -> f t (%%~) ::Functorf =>Lenss t a b -> (a -> f b) -> s -> f t (%%~) ::Applicativef =>Traversals t a b -> (a -> f b) -> s -> f t
When applied to a Traversal, it can edit the
targets of the traversals, extracting a supplemental monoidal summary
of its actions, by choosing f = ((,) m)
(%%~) ::Isos t a b -> (a -> (r, b)) -> s -> (r, t) (%%~) ::Lenss t a b -> (a -> (r, b)) -> s -> (r, t) (%%~) ::Monoidm =>Traversals t a b -> (a -> (m, b)) -> s -> (m, t)
(&~) :: s -> State s a -> s infixl 1 #
This can be used to chain lens operations using op= syntax
rather than op~ syntax for simple non-type-changing cases.
>>>(10,20) & _1 .~ 30 & _2 .~ 40(30,40)
>>>(10,20) &~ do _1 .= 30; _2 .= 40(30,40)
This does not support type-changing assignment, e.g.
>>>(10,20) & _1 .~ "hello"("hello",20)
(<#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m b infix 4 #
(<#=) :: MonadState s m => ALens s s a b -> b -> m b infix 4 #
(<%=) :: MonadState s m => LensLike ((,) b) s s a b -> (a -> b) -> m b infix 4 #
Modify the target of a Lens into your Monad's state by a user supplied
function and return the result.
When applied to a Traversal, it this will return a monoidal summary of all of the intermediate
results.
When you do not need the result of the operation, (%=) is more flexible.
(<%=) ::MonadStates m =>Lens's a -> (a -> a) -> m a (<%=) ::MonadStates m =>Iso's a -> (a -> a) -> m a (<%=) :: (MonadStates m,Monoida) =>Traversal's a -> (a -> a) -> m a
(<%@=) :: MonadState s m => Over (Indexed i) ((,) b) s s a b -> (i -> a -> b) -> m b infix 4 #
Adjust the target of an IndexedLens returning the intermediate result, or
adjust all of the targets of an IndexedTraversal within the current state, and
return a monoidal summary of the intermediate results.
(<%@=) ::MonadStates m =>IndexedLensi s s a b -> (i -> a -> b) -> m b (<%@=) :: (MonadStates m,Monoidb) =>IndexedTraversali s s a b -> (i -> a -> b) -> m b
(<%@~) :: Over (Indexed i) ((,) b) s t a b -> (i -> a -> b) -> s -> (b, t) infixr 4 #
Adjust the target of an IndexedLens returning the intermediate result, or
adjust all of the targets of an IndexedTraversal and return a monoidal summary
along with the answer.
l<%~f ≡ l<%@~constf
When you do not need access to the index then (<%~) is more liberal in what it can accept.
If you do not need the intermediate result, you can use (%@~) or even (%~).
(<%@~) ::IndexedLensi s t a b -> (i -> a -> b) -> s -> (b, t) (<%@~) ::Monoidb =>IndexedTraversali s t a b -> (i -> a -> b) -> s -> (b, t)
(<**=) :: (MonadState s m, Floating a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Raise the target of a floating-point valued Lens into your Monad's
state to an arbitrary power and return the result.
When you do not need the result of the operation, (**=) is more flexible.
(<**=) :: (MonadStates m,Floatinga) =>Lens's a -> a -> m a (<**=) :: (MonadStates m,Floatinga) =>Iso's a -> a -> m a
(<*=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Multiply the target of a numerically valued Lens into your Monad's
state and return the result.
When you do not need the result of the multiplication, (*=) is more
flexible.
(<*=) :: (MonadStates m,Numa) =>Lens's a -> a -> m a (<*=) :: (MonadStates m,Numa) =>Iso's a -> a -> m a
(<+=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Add to the target of a numerically valued Lens into your Monad's state
and return the result.
When you do not need the result of the addition, (+=) is more
flexible.
(<+=) :: (MonadStates m,Numa) =>Lens's a -> a -> m a (<+=) :: (MonadStates m,Numa) =>Iso's a -> a -> m a
(<-=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Subtract from the target of a numerically valued Lens into your Monad's
state and return the result.
When you do not need the result of the subtraction, (-=) is more
flexible.
(<-=) :: (MonadStates m,Numa) =>Lens's a -> a -> m a (<-=) :: (MonadStates m,Numa) =>Iso's a -> a -> m a
(<//=) :: (MonadState s m, Fractional a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Divide the target of a fractionally valued Lens into your Monad's state
and return the result.
When you do not need the result of the division, (//=) is more flexible.
(<//=) :: (MonadStates m,Fractionala) =>Lens's a -> a -> m a (<//=) :: (MonadStates m,Fractionala) =>Iso's a -> a -> m a
(<//~) :: Fractional a => LensLike ((,) a) s t a a -> a -> s -> (a, t) infixr 4 #
Divide the target of a fractionally valued Lens and return the result.
When you do not need the result of the division, (//~) is more flexible.
(<//~) ::Fractionala =>Lens's a -> a -> s -> (a, s) (<//~) ::Fractionala =>Iso's a -> a -> s -> (a, s)
(<<%=) :: (Strong p, MonadState s m) => Over p ((,) a) s s a b -> p a b -> m a infix 4 #
Modify the target of a Lens into your Monad's state by a user supplied
function and return the old value that was replaced.
When applied to a Traversal, this will return a monoidal summary of all of the old values
present.
When you do not need the result of the operation, (%=) is more flexible.
(<<%=) ::MonadStates m =>Lens's a -> (a -> a) -> m a (<<%=) ::MonadStates m =>Iso's a -> (a -> a) -> m a (<<%=) :: (MonadStates m,Monoida) =>Traversal's a -> (a -> a) -> m a
(<<%=) ::MonadStates m =>LensLike((,)a) s s a b -> (a -> b) -> m a
(<<%@=) :: MonadState s m => Over (Indexed i) ((,) a) s s a b -> (i -> a -> b) -> m a infix 4 #
Adjust the target of an IndexedLens returning the old value, or
adjust all of the targets of an IndexedTraversal within the current state, and
return a monoidal summary of the old values.
(<<%@=) ::MonadStates m =>IndexedLensi s s a b -> (i -> a -> b) -> m a (<<%@=) :: (MonadStates m,Monoidb) =>IndexedTraversali s s a b -> (i -> a -> b) -> m a
(<<%@~) :: Over (Indexed i) ((,) a) s t a b -> (i -> a -> b) -> s -> (a, t) infixr 4 #
Adjust the target of an IndexedLens returning the old value, or
adjust all of the targets of an IndexedTraversal and return a monoidal summary
of the old values along with the answer.
(<<%@~) ::IndexedLensi s t a b -> (i -> a -> b) -> s -> (a, t) (<<%@~) ::Monoida =>IndexedTraversali s t a b -> (i -> a -> b) -> s -> (a, t)
(<<&&=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool infix 4 #
Modify the target of a Lens into your Monad's state by taking its logical && with a value
and return the old value that was replaced.
When you do not need the result of the operation, (&&=) is more flexible.
(<<&&=) ::MonadStates m =>Lens'sBool->Bool-> mBool(<<&&=) ::MonadStates m =>Iso'sBool->Bool-> mBool
(<<&&~) :: LensLike' ((,) Bool) s Bool -> Bool -> s -> (Bool, s) infixr 4 #
Logically && the target of a Bool-valued Lens and return the old value.
When you do not need the old value, (&&~) is more flexible.
>>>(False,6) & _1 <<&&~ True(False,(False,6))
>>>("hello",True) & _2 <<&&~ False(True,("hello",False))
(<<&&~) ::Lens's Bool -> Bool -> s -> (Bool, s) (<<&&~) ::Iso's Bool -> Bool -> s -> (Bool, s)
(<<**=) :: (MonadState s m, Floating a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Modify the target of a Lens into your Monad's state by raising it by an arbitrary power
and return the old value that was replaced.
When you do not need the result of the operation, (**=) is more flexible.
(<<**=) :: (MonadStates m,Floatinga) =>Lens's a -> a -> m a (<<**=) :: (MonadStates m,Floatinga) =>Iso's a -> a -> m a
(<<**~) :: Floating a => LensLike' ((,) a) s a -> a -> s -> (a, s) infixr 4 #
Raise the target of a floating-point valued Lens to an arbitrary power and return the old value.
When you do not need the old value, (**~) is more flexible.
>>>(a,b) & _1 <<**~ c(a,(a**c,b))
>>>(a,b) & _2 <<**~ c(b,(a,b**c))
(<<**~) ::Floatinga =>Lens's a -> a -> s -> (a, s) (<<**~) ::Floatinga =>Iso's a -> a -> s -> (a, s)
(<<*=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Modify the target of a Lens into your Monad's state by multipling a value
and return the old value that was replaced.
When you do not need the result of the operation, (*=) is more flexible.
(<<*=) :: (MonadStates m,Numa) =>Lens's a -> a -> m a (<<*=) :: (MonadStates m,Numa) =>Iso's a -> a -> m a
(<<*~) :: Num a => LensLike' ((,) a) s a -> a -> s -> (a, s) infixr 4 #
Multiply the target of a numerically valued Lens and return the old value.
When you do not need the old value, (-~) is more flexible.
>>>(a,b) & _1 <<*~ c(a,(a * c,b))
>>>(a,b) & _2 <<*~ c(b,(a,b * c))
(<<*~) ::Numa =>Lens's a -> a -> s -> (a, s) (<<*~) ::Numa =>Iso's a -> a -> s -> (a, s)
(<<+=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Modify the target of a Lens into your Monad's state by adding a value
and return the old value that was replaced.
When you do not need the result of the operation, (+=) is more flexible.
(<<+=) :: (MonadStates m,Numa) =>Lens's a -> a -> m a (<<+=) :: (MonadStates m,Numa) =>Iso's a -> a -> m a
(<<+~) :: Num a => LensLike' ((,) a) s a -> a -> s -> (a, s) infixr 4 #
Increment the target of a numerically valued Lens and return the old value.
When you do not need the old value, (+~) is more flexible.
>>>(a,b) & _1 <<+~ c(a,(a + c,b))
>>>(a,b) & _2 <<+~ c(b,(a,b + c))
(<<+~) ::Numa =>Lens's a -> a -> s -> (a, s) (<<+~) ::Numa =>Iso's a -> a -> s -> (a, s)
(<<-=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Modify the target of a Lens into your Monad's state by subtracting a value
and return the old value that was replaced.
When you do not need the result of the operation, (-=) is more flexible.
(<<-=) :: (MonadStates m,Numa) =>Lens's a -> a -> m a (<<-=) :: (MonadStates m,Numa) =>Iso's a -> a -> m a
(<<-~) :: Num a => LensLike' ((,) a) s a -> a -> s -> (a, s) infixr 4 #
Decrement the target of a numerically valued Lens and return the old value.
When you do not need the old value, (-~) is more flexible.
>>>(a,b) & _1 <<-~ c(a,(a - c,b))
>>>(a,b) & _2 <<-~ c(b,(a,b - c))
(<<-~) ::Numa =>Lens's a -> a -> s -> (a, s) (<<-~) ::Numa =>Iso's a -> a -> s -> (a, s)
(<<.=) :: MonadState s m => LensLike ((,) a) s s a b -> b -> m a infix 4 #
Replace the target of a Lens into your Monad's state with a user supplied
value and return the old value that was replaced.
When applied to a Traversal, this will return a monoidal summary of all of the old values
present.
When you do not need the result of the operation, (.=) is more flexible.
(<<.=) ::MonadStates m =>Lens's a -> a -> m a (<<.=) ::MonadStates m =>Iso's a -> a -> m a (<<.=) :: (MonadStates m,Monoida) =>Traversal's a -> a -> m a
(<<//=) :: (MonadState s m, Fractional a) => LensLike' ((,) a) s a -> a -> m a infix 4 #
Modify the target of a Lens into your Monads state by dividing by a value
and return the old value that was replaced.
When you do not need the result of the operation, (//=) is more flexible.
(<<//=) :: (MonadStates m,Fractionala) =>Lens's a -> a -> m a (<<//=) :: (MonadStates m,Fractionala) =>Iso's a -> a -> m a
(<<//~) :: Fractional a => LensLike' ((,) a) s a -> a -> s -> (a, s) infixr 4 #
Divide the target of a numerically valued Lens and return the old value.
When you do not need the old value, (//~) is more flexible.
>>>(a,b) & _1 <<//~ c(a,(a / c,b))
>>>("Hawaii",10) & _2 <<//~ 2(10.0,("Hawaii",5.0))
(<<//~) :: Fractional a =>Lens's a -> a -> s -> (a, s) (<<//~) :: Fractional a =>Iso's a -> a -> s -> (a, s)
(<<<>=) :: (MonadState s m, Semigroup r) => LensLike' ((,) r) s r -> r -> m r infix 4 #
Modify the target of a Lens into your Monad's state by using (<>)
and return the old value that was replaced.
When you do not need the result of the operation, (<>=) is more flexible.
(<<<>=) :: (MonadStates m,Semigroupr) =>Lens's r -> r -> m r (<<<>=) :: (MonadStates m,Semigroupr) =>Iso's r -> r -> m r
(<<<>~) :: Semigroup r => LensLike' ((,) r) s r -> r -> s -> (r, s) infixr 4 #
Modify the target of a monoidally valued Lens by using (<>) a new value and return the old value.
When you do not need the old value, (<>~) is more flexible.
>>>(Sum a,b) & _1 <<<>~ Sum c(Sum {getSum = a},(Sum {getSum = a + c},b))
>>>_2 <<<>~ ", 007" $ ("James", "Bond")("Bond",("James","Bond, 007"))
(<<<>~) ::Semigroupr =>Lens's r -> r -> s -> (r, s) (<<<>~) ::Semigroupr =>Iso's r -> r -> s -> (r, s)
(<<?=) :: MonadState s m => LensLike ((,) a) s s a (Maybe b) -> b -> m a infix 4 #
Replace the target of a Lens into your Monad's state with Just a user supplied
value and return the old value that was replaced.
When applied to a Traversal, this will return a monoidal summary of all of the old values
present.
When you do not need the result of the operation, (?=) is more flexible.
(<<?=) ::MonadStates m =>Lenss t a (Maybe b) -> b -> m a (<<?=) ::MonadStates m =>Isos t a (Maybe b) -> b -> m a (<<?=) :: (MonadStates m,Monoida) =>Traversals t a (Maybe b) -> b -> m a
(<<?~) :: LensLike ((,) a) s t a (Maybe b) -> b -> s -> (a, t) infixr 4 #
Replace the target of a Lens with a Just value, but return the old value.
If you do not need the old value (?~) is more flexible.
>>>import qualified Data.Map as Map>>>_2.at "hello" <<?~ "world" $ (42,Map.fromList [("goodnight","gracie")])(Nothing,(42,fromList [("goodnight","gracie"),("hello","world")]))
(<<?~) ::Isos t a (Maybeb) -> b -> s -> (a, t) (<<?~) ::Lenss t a (Maybeb) -> b -> s -> (a, t) (<<?~) ::Traversals t a (Maybeb) -> b -> s -> (a, t)
(<<^=) :: (MonadState s m, Num a, Integral e) => LensLike' ((,) a) s a -> e -> m a infix 4 #
Modify the target of a Lens into your Monad's state by raising it by a non-negative power
and return the old value that was replaced.
When you do not need the result of the operation, (^=) is more flexible.
(<<^=) :: (MonadStates m,Numa,Integrale) =>Lens's a -> e -> m a (<<^=) :: (MonadStates m,Numa,Integrale) =>Iso's a -> a -> m a
(<<^^=) :: (MonadState s m, Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> m a infix 4 #
Modify the target of a Lens into your Monad's state by raising it by an integral power
and return the old value that was replaced.
When you do not need the result of the operation, (^^=) is more flexible.
(<<^^=) :: (MonadStates m,Fractionala,Integrale) =>Lens's a -> e -> m a (<<^^=) :: (MonadStates m,Fractionala,Integrale) =>Iso's a -> e -> m a
(<<^^~) :: (Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> s -> (a, s) infixr 4 #
Raise the target of a fractionally valued Lens to an integral power and return the old value.
When you do not need the old value, (^^~) is more flexible.
(<<^^~) :: (Fractionala,Integrale) =>Lens's a -> e -> s -> (a, s) (<<^^~) :: (Fractionala,Integrale) =>Iso's a -> e -> S -> (a, s)
(<<||=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool infix 4 #
Modify the target of a Lens into your Monad's state by taking its logical || with a value
and return the old value that was replaced.
When you do not need the result of the operation, (||=) is more flexible.
(<<||=) ::MonadStates m =>Lens'sBool->Bool-> mBool(<<||=) ::MonadStates m =>Iso'sBool->Bool-> mBool
(<<||~) :: LensLike' ((,) Bool) s Bool -> Bool -> s -> (Bool, s) infixr 4 #
Logically || the target of a Bool-valued Lens and return the old value.
When you do not need the old value, (||~) is more flexible.
>>>(False,6) & _1 <<||~ True(False,(True,6))
>>>("hello",True) & _2 <<||~ False(True,("hello",True))
(<<||~) ::Lens'sBool->Bool-> s -> (Bool, s) (<<||~) ::Iso'sBool->Bool-> s -> (Bool, s)
(<<~) :: MonadState s m => ALens s s a b -> m b -> m b infixr 2 #
Run a monadic action, and set the target of Lens to its result.
(<<~) ::MonadStates m =>Isos s a b -> m b -> m b (<<~) ::MonadStates m =>Lenss s a b -> m b -> m b
NB: This is limited to taking an actual Lens than admitting a Traversal because
there are potential loss of state issues otherwise.
(<^=) :: (MonadState s m, Num a, Integral e) => LensLike' ((,) a) s a -> e -> m a infix 4 #
Raise the target of a numerically valued Lens into your Monad's state
to a non-negative Integral power and return the result.
When you do not need the result of the operation, (^=) is more flexible.
(<^=) :: (MonadStates m,Numa,Integrale) =>Lens's a -> e -> m a (<^=) :: (MonadStates m,Numa,Integrale) =>Iso's a -> e -> m a
(<^^=) :: (MonadState s m, Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> m a infix 4 #
Raise the target of a fractionally valued Lens into your Monad's state
to an Integral power and return the result.
When you do not need the result of the operation, (^^=) is more flexible.
(<^^=) :: (MonadStates m,Fractionalb,Integrale) =>Lens's a -> e -> m a (<^^=) :: (MonadStates m,Fractionalb,Integrale) =>Iso's a -> e -> m a
(<^^~) :: (Fractional a, Integral e) => LensLike ((,) a) s t a a -> e -> s -> (a, t) infixr 4 #
Raise the target of a fractionally valued Lens to an Integral power
and return the result.
When you do not need the result of the operation, (^^~) is more flexible.
(<^^~) :: (Fractionala,Integrale) =>Lens's a -> e -> s -> (a, s) (<^^~) :: (Fractionala,Integrale) =>Iso's a -> e -> s -> (a, s)
(??) :: Functor f => f (a -> b) -> a -> f b infixl 1 #
This is convenient to flip argument order of composite functions defined as:
fab ?? a = fmap ($ a) fab
For the Functor instance f = ((->) r) you can reason about this function as if the definition was (:??) ≡ flip
>>>(h ?? x) ah a x
>>>execState ?? [] $ modify (1:)[1]
>>>over _2 ?? ("hello","world") $ length("hello",5)
>>>over ?? length ?? ("hello","world") $ _2("hello",5)
alongside :: LensLike (AlongsideLeft f b') s t a b -> LensLike (AlongsideRight f t) s' t' a' b' -> LensLike f (s, s') (t, t') (a, a') (b, b') #
alongside makes a Lens from two other lenses or a Getter from two other getters
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::Lenss t a b ->Lenss' t' a' b' ->Lens(s,s') (t,t') (a,a') (b,b')alongside::Getters a ->Getters' a' ->Getter(s,s') (a,a')
choosing :: Functor f => LensLike f s t a b -> LensLike f s' t' a b -> LensLike f (Either s s') (Either t t') a b #
Merge two lenses, getters, setters, folds or traversals.
chosen≡choosingidid
choosing::Getters a ->Getters' a ->Getter(Eithers s') achoosing::Folds a ->Folds' a ->Fold(Eithers s') achoosing::Lens's a ->Lens's' a ->Lens'(Eithers s') achoosing::Traversal's a ->Traversal's' a ->Traversal'(Eithers s') achoosing::Setter's a ->Setter's' a ->Setter'(Eithers s') a
chosen :: forall a b p f. (Conjoined p, Functor f) => p a (f b) -> p (Either a a) (f (Either b b)) #
This is a Lens that updates either side of an Either, where both sides have the same type.
chosen≡choosingidid
>>>Left a^.chosena
>>>Right a^.chosena
>>>Right "hello"^.chosen"hello"
>>>Right a & chosen *~ bRight (a * b)
chosen::Lens(Eithera a) (Eitherb b) a bchosenf (Lefta) =Left<$>f achosenf (Righta) =Right<$>f a
cloneIndexPreservingLens :: ALens s t a b -> IndexPreservingLens s t a b #
Clone a Lens as an IndexedPreservingLens that just passes through whatever
index is on any IndexedLens, IndexedFold, IndexedGetter or IndexedTraversal it is composed with.
cloneIndexedLens :: AnIndexedLens i s t a b -> IndexedLens i s t a b #
Clone an IndexedLens as an IndexedLens with the same index.
cloneLens :: ALens s t a b -> Lens s t a b #
Cloning a Lens is one way to make sure you aren't given
something weaker, such as a Traversal and can be
used as a way to pass around lenses that have to be monomorphic in f.
Note: This only accepts a proper Lens.
>>>let example l x = set (cloneLens l) (x^.cloneLens l + 1) x in example _2 ("hello",1,"you")("hello",2,"you")
fusing :: Functor f => LensLike (Yoneda f) s t a b -> LensLike f s t a b #
Fuse a composition of lenses using Yoneda to provide fmap fusion.
In general, given a pair of lenses foo and bar
fusing (foo.bar) = foo.bar
however, foo and bar are either going to fmap internally or they are trivial.
fusing exploits the Yoneda lemma to merge these separate uses into a single fmap.
This is particularly effective when the choice of functor f is unknown at compile
time or when the Lens foo.bar in the above description is recursive or complex
enough to prevent inlining.
fusing::Lenss t a b ->Lenss t a b
head1 :: forall (t :: Type -> Type) a. Traversable1 t => Lens' (t a) a #
A Lens focusing on the first element of a Traversable1 container.
>>>2 :| [3, 4] & head1 +~ 1012 :| [3,4]
>>>Identity True ^. head1True
ilens :: (s -> (i, a)) -> (s -> b -> t) -> IndexedLens i s t a b #
Build an IndexedLens from a Getter and
a Setter.
inside :: forall (p :: Type -> Type -> Type) s t a b e. Corepresentable p => ALens s t a b -> Lens (p e s) (p e t) (p e a) (p e b) #
iplens :: (s -> a) -> (s -> b -> t) -> IndexPreservingLens s t a b #
locus :: forall (p :: Type -> Type -> Type -> Type) a c s b. IndexedComonadStore p => Lens (p a c s) (p b c s) a b #
This Lens lets you view the current pos of any indexed
store comonad and seek to a new position. This reduces the API
for working these instances to a single Lens.
iposw ≡ w^.locusiseeks w ≡ w&locus.~siseeksf w ≡ w&locus%~f
locus::Lens'(Context'a s) alocus::Conjoinedp =>Lens'(Pretext'p a s) alocus::Conjoinedp =>Lens'(PretextT'p g a s) a
united :: forall a f. Functor f => (() -> f ()) -> a -> f a #
We can always retrieve a () from any type.
>>>"hello"^.united()
>>>"hello" & united .~ ()"hello"
withLens :: ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r #
Obtain a getter and a setter from a lens, reversing lens.
type AnIndexedLens i s t a b = Optical (Indexed i) (->) (Pretext (Indexed i) a b) s t a b #
When you see this as an argument to a function, it expects an IndexedLens
type AnIndexedLens' i s a = AnIndexedLens i s s a a #
typeAnIndexedLens'=Simple(AnIndexedLensi)
type IndexedLens i s t a b = forall (f :: Type -> Type) (p :: Type -> Type -> Type). (Indexable i p, Functor f) => p a (f b) -> s -> f t #
Every IndexedLens is a valid Lens and a valid IndexedTraversal.
type IndexedLens' i s a = IndexedLens i s s a a #
typeIndexedLens'i =Simple(IndexedLensi)
type Lens s t a b = forall (f :: Type -> Type). Functor f => (a -> f b) -> s -> f t #
A Lens is actually a lens family as described in
http://comonad.com/reader/2012/mirrored-lenses/.
With great power comes great responsibility and a Lens is subject to the
three common sense Lens laws:
1) You get back what you put in:
viewl (setl v s) ≡ v
2) Putting back what you got doesn't change anything:
setl (viewl s) s ≡ s
3) Setting twice is the same as setting once:
setl v' (setl v s) ≡setl v' s
These laws are strong enough that the 4 type parameters of a Lens cannot
vary fully independently. For more on how they interact, read the "Why is
it a Lens Family?" section of
http://comonad.com/reader/2012/mirrored-lenses/.
There are some emergent properties of these laws:
1) must be injective for every set l ss This is a consequence of law #1
2) must be surjective, because of law #2, which indicates that it is possible to obtain any set lv from some s such that set s v = s
3) Given just the first two laws you can prove a weaker form of law #3 where the values v that you are setting match:
setl v (setl v s) ≡setl v s
Every Lens can be used directly as a Setter or Traversal.
You can also use a Lens for Getting as if it were a
Fold or Getter.
Since every Lens is a valid Traversal, the
Traversal laws are required of any Lens you create:
lpure≡purefmap(l f).l g ≡getCompose.l (Compose.fmapf.g)
typeLenss t a b = forall f.Functorf =>LensLikef s t a b
module Control.Lens.Iso
module Control.Lens.At
(&&&) :: Arrow a => a b c -> a b c' -> a b (c, c') infixr 3 #
Fanout: send the input to both argument arrows and combine their output.
The default definition may be overridden with a more efficient version if desired.
╭───────╮ c
b │ ┌─ f ─┼───>
>───┼─┤ │
│ └─ g ─┼───>
╰───────╯ c'lensProduct :: ALens' s a -> ALens' s b -> Lens' s (a, b) #
A lens product. There is no law-abiding way to do this in general.
Result is only a valid Lens if the input lenses project disjoint parts of
the structure s. Otherwise "you get what you put in" law
viewl (setl v s) ≡ v
is violated by
>>>let badLens :: Lens' (Int, Char) (Int, Int); badLens = lensProduct _1 _1>>>view badLens (set badLens (1,2) (3,'x'))(2,2)
but we should get (1,2).
Are you looking for alongside?