Safe Haskell | Safe |
---|---|
Language | Haskell98 |
This module contains lenses and traversals for common structures in Haskell. It also contains the combinators for lenses and traversals.
Synopsis
- choosing :: Functor f => LensLike f a a' c c' -> LensLike f b b' c c' -> LensLike f (Either a b) (Either a' b') c c'
- alongside :: Functor f => LensLike (AlongsideLeft f b2') a1 a1' b1 b1' -> LensLike (AlongsideRight f a1') a2 a2' b2 b2' -> LensLike f (a1, a2) (a1', a2') (b1, b2) (b1', b2')
- beside :: Applicative f => LensLike f a a' c c' -> LensLike f b b' c c' -> LensLike f (a, b) (a', b') c c'
- _1 :: Lens (a, b) (a', b) a a'
- _2 :: Lens (a, b) (a, b') b b'
- chosen :: Lens (Either a a) (Either b b) a b
- ix :: Eq k => k -> Lens' (k -> v) v
- at :: Ord k => k -> Lens' (Map k v) (Maybe v)
- intAt :: Int -> Lens' (IntMap v) (Maybe v)
- at' :: Ord k => k -> Lens' (Map k v) (Maybe v)
- intAt' :: Int -> Lens' (IntMap v) (Maybe v)
- contains :: Ord k => k -> Lens' (Set k) Bool
- intContains :: Int -> Lens' IntSet Bool
- both :: Traversal (a, a) (b, b) a b
- _Left :: Traversal (Either a b) (Either a' b) a a'
- _Right :: Traversal (Either a b) (Either a b') b b'
- _Just :: Traversal (Maybe a) (Maybe a') a a'
- _Nothing :: Traversal' (Maybe a) ()
- ignored :: Traversal a a b b'
- mapped :: Functor f => Setter (f a) (f a') a a'
- data AlongsideLeft (f :: * -> *) b a
- data AlongsideRight (f :: * -> *) a b
- type Lens a a' b b' = forall f. Functor f => LensLike f a a' b b'
- type Lens' a b = forall f. Functor f => LensLike' f a b
- type Traversal a a' b b' = forall f. Applicative f => LensLike f a a' b b'
- type Traversal' a b = forall f. Applicative f => LensLike' f a b
- type Setter a a' b b' = forall f. Identical f => LensLike f a a' b b'
- type LensLike (f :: * -> *) a a' b b' = (b -> f b') -> a -> f a'
- type LensLike' (f :: * -> *) a b = (b -> f b) -> a -> f a
- class Functor f => Applicative (f :: * -> *)
- class Applicative f => Identical (f :: * -> *)
Lens Combinators
choosing :: Functor f => LensLike f a a' c c' -> LensLike f b b' c c' -> LensLike f (Either a b) (Either a' b') c c' #
choosing :: Lens a a' c c' -> Lens b b' c c' -> Lens (Either a b) (Either a' b') c c'
choosing :: Traversal a a' c c' -> Traversal b b' c c' -> Traversal (Either a b) (Either a' b') c c'
choosing :: Getter a a' c c' -> Getter b b' c c' -> Getter (Either a b) (Either a' b') c c'
choosing :: Fold a a' c c' -> Fold b b' c c' -> Fold (Either a b) (Either a' b') c c'
choosing :: Setter a a' c c' -> Setter b b' c c' -> Setter (Either a b) (Either a' b') c c'
Given two lens/traversal/getter/fold/setter families with the same substructure, make a new lens/traversal/getter/fold/setter on Either
.
alongside :: Functor f => LensLike (AlongsideLeft f b2') a1 a1' b1 b1' -> LensLike (AlongsideRight f a1') a2 a2' b2 b2' -> LensLike f (a1, a2) (a1', a2') (b1, b2) (b1', b2') #
alongside :: Lens a1 a1' b1 b1' -> Lens a2 a2' b2 b2' -> Lens (a1, a2) (a1', a2') (b1, b2) (b1', b2')
alongside :: Getter a1 a1' b1 b1' -> Getter a2 a2' b2 b2' -> Getter (a1, a2) (a1', a2') (b1, b2) (b1', b2')
Given two lens/getter families, make a new lens/getter on their product.
beside :: Applicative f => LensLike f a a' c c' -> LensLike f b b' c c' -> LensLike f (a, b) (a', b') c c' #
beside :: Traversal a a' c c' -> Traversal b' b' c c' -> Traversal (a,b) (a',b') c c'
beside :: Fold a a' c c' -> Fold b' b' c c' -> Fold (a,b) (a',b') c c'
beside :: Setter a a' c c' -> Setter b' b' c c' -> Setter (a,b) (a',b') c c'
Given two traversals/folds/setters referencing a type c
, create a traversal/fold/setter on the pair referencing c
.
Stock Lenses
chosen :: Lens (Either a a) (Either b b) a b Source #
Lens on the Left or Right element of an (Either
a a).
at' :: Ord k => k -> Lens' (Map k v) (Maybe v) Source #
Lens providing strict access to a given point of a Map
.
intAt' :: Int -> Lens' (IntMap v) (Maybe v) Source #
Lens providing strict access to a given point of a IntMap
.
Stock Traversals
Stock SECs
mapped :: Functor f => Setter (f a) (f a') a a' Source #
An SEC referencing the parameter of a functor.
Types
data AlongsideLeft (f :: * -> *) b a #
Instances
Functor f => Functor (AlongsideLeft f a) | |
Defined in Lens.Family.Stock fmap :: (a0 -> b) -> AlongsideLeft f a a0 -> AlongsideLeft f a b # (<$) :: a0 -> AlongsideLeft f a b -> AlongsideLeft f a a0 # | |
Phantom f => Phantom (AlongsideLeft f a) | |
Defined in Lens.Family.Stock coerce :: AlongsideLeft f a a0 -> AlongsideLeft f a b |
data AlongsideRight (f :: * -> *) a b #
Instances
Functor f => Functor (AlongsideRight f a) | |
Defined in Lens.Family.Stock fmap :: (a0 -> b) -> AlongsideRight f a a0 -> AlongsideRight f a b # (<$) :: a0 -> AlongsideRight f a b -> AlongsideRight f a a0 # | |
Phantom f => Phantom (AlongsideRight f a) | |
Defined in Lens.Family.Stock coerce :: AlongsideRight f a a0 -> AlongsideRight f a b |
Re-exports
type Traversal a a' b b' = forall f. Applicative f => LensLike f a a' b b' Source #
type Traversal' a b = forall f. Applicative f => LensLike' f a b Source #
class Functor f => Applicative (f :: * -> *) #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*>
or liftA2
. If it defines both, then they must behave
the same as their default definitions:
(<*>
) =liftA2
id
liftA2
f x y = f<$>
x<*>
y
Further, any definition must satisfy the following:
- identity
pure
id
<*>
v = v- composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w)- homomorphism
pure
f<*>
pure
x =pure
(f x)- interchange
u
<*>
pure
y =pure
($
y)<*>
u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor
instance for f
will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2
p (liftA2
q u v) =liftA2
f u .liftA2
g v
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Instances
Applicative [] | Since: base-2.1 |
Applicative Maybe | Since: base-2.1 |
Applicative IO | Since: base-2.1 |
Applicative Par1 | Since: base-4.9.0.0 |
Applicative ZipList | f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsN = 'ZipList' (zipWithN f xs1 ... xsN) where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]} Since: base-2.1 |
Applicative Identity | Since: base-4.8.0.0 |
Applicative First | |
Applicative Last | |
Applicative Dual | Since: base-4.8.0.0 |
Applicative Sum | Since: base-4.8.0.0 |
Applicative Product | Since: base-4.8.0.0 |
Applicative ReadP | Since: base-4.6.0.0 |
Applicative NonEmpty | Since: base-4.9.0.0 |
Applicative P | Since: base-4.5.0.0 |
Applicative (Either e) | Since: base-3.0 |
Applicative (U1 :: * -> *) | Since: base-4.9.0.0 |
Monoid a => Applicative ((,) a) | For tuples, the ("hello ", (+15)) <*> ("world!", 2002) ("hello world!",2017) Since: base-2.1 |
Monad m => Applicative (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative pure :: a -> WrappedMonad m a # (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b # liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c # (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a # | |
Arrow a => Applicative (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow pure :: a0 -> ArrowMonad a a0 # (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c # (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
Applicative (Proxy :: * -> *) | Since: base-4.7.0.0 |
Applicative m => Applicative (ListT m) | |
(Functor m, Monad m) => Applicative (MaybeT m) | |
Applicative f => Applicative (Rec1 f) | Since: base-4.9.0.0 |
Arrow a => Applicative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative pure :: a0 -> WrappedArrow a b a0 # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Monoid m => Applicative (Const m :: * -> *) | Since: base-2.0.1 |
Applicative f => Applicative (Alt f) | |
(Applicative f, Monad f) => Applicative (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal pure :: a -> WhenMissing f x a # (<*>) :: WhenMissing f x (a -> b) -> WhenMissing f x a -> WhenMissing f x b # liftA2 :: (a -> b -> c) -> WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x c # (*>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b # (<*) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x a # | |
(Monoid c, Monad m) => Applicative (Zooming m c) | |
Defined in Lens.Family.State.Zoom | |
Applicative f => Applicative (Backwards f) | Apply |
Defined in Control.Applicative.Backwards | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Lazy | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
Monoid a => Applicative (Constant a :: * -> *) | |
Defined in Data.Functor.Constant | |
Applicative m => Applicative (IdentityT m) | |
Defined in Control.Monad.Trans.Identity | |
(Functor m, Monad m) => Applicative (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
(Functor m, Monad m) => Applicative (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Lazy | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Strict | |
Applicative ((->) a :: * -> *) | Since: base-2.1 |
(Applicative f, Applicative g) => Applicative (f :*: g) | Since: base-4.9.0.0 |
(Monad f, Applicative f) => Applicative (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal pure :: a -> WhenMatched f x y a # (<*>) :: WhenMatched f x y (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b # liftA2 :: (a -> b -> c) -> WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y c # (*>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b # (<*) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y a # | |
(Applicative f, Monad f) => Applicative (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal pure :: a -> WhenMissing f k x a # (<*>) :: WhenMissing f k x (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b # liftA2 :: (a -> b -> c) -> WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x c # (*>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b # (<*) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x a # | |
Applicative (ContT r m) | |
Applicative m => Applicative (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
Applicative f => Applicative (M1 i c f) | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (f :.: g) | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
(Monad f, Applicative f) => Applicative (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal pure :: a -> WhenMatched f k x y a # (<*>) :: WhenMatched f k x y (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b # liftA2 :: (a -> b -> c) -> WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y c # (*>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b # (<*) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y a # | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Lazy | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Strict |
class Applicative f => Identical (f :: * -> *) #
extract
Instances
Identical Identity | |
Defined in Lens.Family.Identical | |
Identical f => Identical (Backwards f) | |
Defined in Lens.Family.Identical | |
(Identical f, Identical g) => Identical (Compose f g) | |
Defined in Lens.Family.Identical |