Portability | Rank2Types |
---|---|
Stability | provisional |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Safe Haskell | Trustworthy |
- type Loupe s t a b = LensLike (Context a b) s t a b
- storing :: Loupe s t a b -> b -> s -> t
- (^#) :: s -> Loupe s t a b -> a
- (#~) :: Loupe s t a b -> b -> s -> t
- (#%~) :: Loupe s t a b -> (a -> b) -> s -> t
- (#%%~) :: Functor f => Loupe s t a b -> (a -> f b) -> s -> f t
- (<#~) :: Loupe s t a b -> b -> s -> (b, t)
- (<#%~) :: Loupe s t a b -> (a -> b) -> s -> (b, t)
- (#=) :: MonadState s m => Loupe s s a b -> b -> m ()
- (#%=) :: MonadState s m => Loupe s s a b -> (a -> b) -> m ()
- (#%%=) :: MonadState s m => Loupe s s a b -> (a -> (r, b)) -> m r
- (<#=) :: MonadState s m => Loupe s s a b -> b -> m b
- (<#%=) :: MonadState s m => Loupe s s a b -> (a -> b) -> m b
- type SimpleLoupe s a = Loupe s s a a
- type ALens s t a b = Loupe s t a b
- type ALens' s a = Loupe s s a a
- cloneLens :: Functor f => LensLike (Context a b) s t a b -> (a -> f b) -> s -> f t
Lenses
type Loupe s t a b = LensLike (Context a b) s t a bSource
A
is almost a Loupe
s t a bLens
. It can be composed on the left of other lenses,
you can use cloneLens
to promote it to a Lens
, and it provides a minimalist lens-like
interface. They can be used in an API where you need to pass around lenses inside containers
or as monadic results. Unlike a ReifiedLens
they can be composed and used directly, but
they are slightly lower performance.
(<#~) :: Loupe s t a b -> b -> s -> (b, t)Source
Replace the target of a Loupe
and return the new value.
>>>
("hello","there") & _2 <#~ "world"
("world",("hello","world"))
(<#%~) :: Loupe s t a b -> (a -> b) -> s -> (b, t)Source
Modify the target of a Loupe
and return the result.
>>>
("hello","world") & _2 <#%~ length
(5,("hello",5))
(#%%=) :: MonadState s m => Loupe s s a b -> (a -> (r, b)) -> m rSource
Modify the target of a Loupe
in the current monadic state, returning an auxiliary result.
(<#=) :: MonadState s m => Loupe s s a b -> b -> m bSource
Replace the target of a Loupe
in the current monadic state, returning the new value.
(<#%=) :: MonadState s m => Loupe s s a b -> (a -> b) -> m bSource
Modify the target of a Loupe
into your monad's state by a user supplied function and return the result.
Simplified
type SimpleLoupe s a = Loupe s s a aSource
typeSimpleLoupe
=Simple
Loupe
ALens forward compatibility
cloneLens :: Functor f => LensLike (Context a b) s t a b -> (a -> f b) -> s -> f tSource
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")