lens-3.10: Lenses, Folds and Traversals

PortabilityRank2Types
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Inferred

Control.Lens.Loupe

Contents

Description

This module exports a minimalist API for working with lenses in highly monomorphic settings.

Synopsis

Documentation

type ALens s t a b = LensLike (Pretext (->) a b) s t a bSource

When you see this as an argument to a function, it expects a Lens.

This type can also be used when you need to store a Lens in a container, since it is rank-1. You can turn them back into a Lens with cloneLens, or use it directly with combinators like storing and (^#).

type ALens' s a = ALens s s a aSource

cloneLens :: ALens s t a b -> Lens s t a bSource

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")

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

A version of set that works on ALens.

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

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

A version of (^.) that works on ALens.

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

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

A version of (.~) that works on ALens.

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

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

A version of (%~) that works on ALens.

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

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

A version of (%%~) that works on ALens.

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

(<#~) :: ALens s t a b -> b -> s -> (b, t)Source

A version of (<.~) that works on ALens.

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

(<#%~) :: ALens s t a b -> (a -> b) -> s -> (b, t)Source

A version of (<%~) that works on ALens.

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

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

A version of (.=) that works on ALens.

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

A version of (%=) that works on ALens.

(#%%=) :: MonadState s m => ALens s s a b -> (a -> (r, b)) -> m rSource

A version of (%%=) that works on ALens.

(<#=) :: MonadState s m => ALens s s a b -> b -> m bSource

A version of (<#=) that works on ALens.

(<#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m bSource

A version of (<%=) that works on ALens.

Deprecated Aliases

type Loupe s t a b = LensLike (Pretext (->) a b) s t a bSource

Deprecated: use ALens

This is an older alias for a type-restricted form of lens that is able to be passed around in containers monomorphically.

Deprecated. This has since been renamed to ALens for consistency.

type SimpleLoupe s a = Loupe s s a aSource

Deprecated: use ALens'

 type SimpleLoupe = Simple Loupe

Deprecated for two reasons. Loupe is now ALens, and we no longer use the verbose SimpleFoo naming convention, this has since been renamed to ALens' for consistency.