lens-4.2: Lenses, Folds and Traversals

Copyright(C) 2012-14 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
PortabilityRank2Types
Safe HaskellSafe-Inferred
LanguageHaskell98

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 b Source

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 a Source

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

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 -> t Source

A version of set that works on ALens.

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

(^#) :: s -> ALens s t a b -> a infixl 8 Source

A version of ('Control.Lens.Getter.^.') that works on ALens.

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

(#~) :: ALens s t a b -> b -> s -> t infixr 4 Source

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

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

(#%~) :: ALens s t a b -> (a -> b) -> s -> t infixr 4 Source

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 t infixr 4 Source

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) infixr 4 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) infixr 4 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 () infix 4 Source

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

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

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

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

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

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

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

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

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

Deprecated Aliases

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

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 a Source

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.