lens-3.8.7.3: Lenses, Folds and Traversals

Portability | Rank2Types
Stability | provisional
Maintainer | Edward Kmett <ekmett@gmail.com>
Safe Haskell | Safe-Infered

Control.Lens.Loupe

Contents

- Deprecated Aliases

Description

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

Synopsis

- type ALens s t a b = LensLike (Pretext (->) a b) s t a b
- type ALens' s a = ALens s s a a
- cloneLens :: ALens s t a b -> Lens s t a b
- storing :: ALens s t a b -> b -> s -> t
- (^#) :: s -> ALens s t a b -> a
- (#~) :: ALens s t a b -> b -> s -> t
- (#%~) :: ALens s t a b -> (a -> b) -> s -> t
- (#%%~) :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t
- (<#~) :: ALens s t a b -> b -> s -> (b, t)
- (<#%~) :: ALens s t a b -> (a -> b) -> s -> (b, t)
- (#=) :: MonadState s m => ALens s s a b -> b -> m ()
- (#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m ()
- (#%%=) :: MonadState s m => ALens s s a b -> (a -> (r, b)) -> m r
- (<#=) :: MonadState s m => ALens s s a b -> b -> m b
- (<#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m b
- type Loupe s t a b = LensLike (Pretext (->) a b) s t a b
- type SimpleLoupe s a = Loupe s s a a

# Documentation

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

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

     type ALens' = Simple ALens

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

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

A version of `set` that works on `ALens`.

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

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

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

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

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

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

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

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

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

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)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Deprecated Aliases

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

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

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.