lens-3.7.1: Lenses, Folds and Traversals

PortabilityRank2Types
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellTrustworthy

Control.Lens.Loupe

Contents

Description

A Loupe is a minimalist Lens suitable for storing in containers or returning monadically that can still be composed with other lenses.

Synopsis

Lenses

type Loupe s t a b = LensLike (Context a b) s t a bSource

A Loupe s t a b is almost a Lens. 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.

storing :: Loupe s t a b -> b -> s -> tSource

A Loupe-specific version of set

>>> storing _2 "world" ("hello","there")
("hello","world")

(^#) :: s -> Loupe s t a b -> aSource

A Loupe-specific version of (^.)

>>> ("hello","world")^#_2
"world"

(#~) :: Loupe s t a b -> b -> s -> tSource

A Loupe-specific version of (.~)

>>> ("hello","there") & _2 #~ "world"
("hello","world")

(#%~) :: Loupe s t a b -> (a -> b) -> s -> tSource

A Loupe-specific version of (%~)

>>> ("hello","world") & _2 #%~ length
("hello",5)

(#%%~) :: Functor f => Loupe s t a b -> (a -> f b) -> s -> f tSource

A Loupe-specific version of (%%~)

>>> ("hello","world") & _2 #%%~ \x -> (length x, x ++ "!")
(5,("hello","world!"))

(<#~) :: 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 -> b -> m ()Source

A Loupe-specific version of (.=)

(#%=) :: MonadState s m => Loupe s s a b -> (a -> b) -> m ()Source

A Loupe-specific version of (%=)

(#%%=) :: 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