Agda
Safe HaskellNone
LanguageHaskell2010

Agda.Utils.Lens

Description

A cut-down implementation of lenses, with names mostly taken from Edward Kmett's lens package.

Synopsis

Documentation

(%%=) :: MonadState o m => Lens' o i -> (i -> m (i, r)) -> m r infix 4 Source #

Modify a part of the state monadically, and return some result.

(%%=!) :: MonadState o m => Lens' o i -> (i -> m (i, r)) -> m r infix 4 Source #

Strictly modify a part of the state monadically, and return some result.

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

Modify a part of the state.

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

Strictly modify a part of the state.

(%==) :: MonadState s m => Lens' s a -> (a -> m a) -> m () infix 4 Source #

Modify a part of the state monadically.

(%==!) :: MonadState s m => Lens' s a -> (a -> m a) -> m () infix 4 Source #

Strictly modify a part of the state monadically.

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

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

(.=) :: MonadState s m => ASetter s s a b -> b -> m () infix 4 Source #

Write a part of the state.

(.=!) :: MonadState s m => ASetter s s a b -> b -> m () infix 4 Source #

Strictly write a part of the state.

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

(^.) :: s -> Getting a s a -> a infixl 8 Source #

Get inner part i of structure o as designated by Lens' o i.

contains :: Ord k => k -> Lens' (Set k) Bool Source #

Focus on given element in a set.

iso :: (o -> i) -> (i -> o) -> Lens' o i Source #

Build a lens out of an isomorphism.

key :: Ord k => k -> Lens' (Map k v) (Maybe v) Source #

Access a map value at a given key.

lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b Source #

Build a lens from a getter and a setter.

lensProduct :: Lens' s a -> Lens' s b -> Lens' s (a, b) Source #

Only sound if the lenses are disjoint!

locally :: MonadReader r m => ASetter r r a b -> (a -> b) -> m c -> m c Source #

Modify a part of the state in a subcomputation.

locallyState :: MonadState o m => Lens' o i -> (i -> i) -> m r -> m r Source #

Modify a part of the state locally.

over :: ASetter s t a b -> (a -> b) -> s -> t Source #

Modify inner part i of structure o using a function i -> i.

over' :: ASetter s t a b -> (a -> b) -> s -> t Source #

Strictly modify inner part i of structure o using a function i -> i.

set :: ASetter s t a b -> b -> s -> t Source #

Set inner part i of structure o as designated by Lens' o i.

set' :: ASetter s t a b -> b -> s -> t Source #

Strictly set inner part i of structure o as designated by Lens' o i.

use :: MonadState s m => Getting a s a -> m a Source #

Read a part of the state.

view :: MonadReader s m => Getting a s a -> m a Source #

Read part of the environment.

type ASetter s t a b = (a -> Identity b) -> s -> Identity t Source #

class Field1 s t a b | s -> a, t -> b, s b -> t, t a -> s where Source #

Methods

_1 :: Lens s t a b Source #

_1' :: Lens s t a b Source #

Instances

Instances details
Field1 (a, b) (a', b) a a' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_1 :: Lens (a, b) (a', b) a a' Source #

_1' :: Lens (a, b) (a', b) a a' Source #

Field1 (a, b, c) (a', b, c) a a' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_1 :: Lens (a, b, c) (a', b, c) a a' Source #

_1' :: Lens (a, b, c) (a', b, c) a a' Source #

Field1 (a, b, c, d) (a', b, c, d) a a' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_1 :: Lens (a, b, c, d) (a', b, c, d) a a' Source #

_1' :: Lens (a, b, c, d) (a', b, c, d) a a' Source #

Field1 (a, b, c, d, e) (a', b, c, d, e) a a' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_1 :: Lens (a, b, c, d, e) (a', b, c, d, e) a a' Source #

_1' :: Lens (a, b, c, d, e) (a', b, c, d, e) a a' Source #

class Field2 s t a b | s -> a, t -> b, s b -> t, t a -> s where Source #

Methods

_2 :: Lens s t a b Source #

_2' :: Lens s t a b Source #

Instances

Instances details
Field2 (a, b) (a, b') b b' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_2 :: Lens (a, b) (a, b') b b' Source #

_2' :: Lens (a, b) (a, b') b b' Source #

Field2 (a, b, c) (a, b', c) b b' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_2 :: Lens (a, b, c) (a, b', c) b b' Source #

_2' :: Lens (a, b, c) (a, b', c) b b' Source #

Field2 (a, b, c, d) (a, b', c, d) b b' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_2 :: Lens (a, b, c, d) (a, b', c, d) b b' Source #

_2' :: Lens (a, b, c, d) (a, b', c, d) b b' Source #

Field2 (a, b, c, d, e) (a, b', c, d, e) b b' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_2 :: Lens (a, b, c, d, e) (a, b', c, d, e) b b' Source #

_2' :: Lens (a, b, c, d, e) (a, b', c, d, e) b b' Source #

class Field3 s t a b | s -> a, t -> b, s b -> t, t a -> s where Source #

Methods

_3 :: Lens s t a b Source #

_3' :: Lens s t a b Source #

Instances

Instances details
Field3 (a, b, c) (a, b, c') c c' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_3 :: Lens (a, b, c) (a, b, c') c c' Source #

_3' :: Lens (a, b, c) (a, b, c') c c' Source #

Field3 (a, b, c, d) (a, b, c', d) c c' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_3 :: Lens (a, b, c, d) (a, b, c', d) c c' Source #

_3' :: Lens (a, b, c, d) (a, b, c', d) c c' Source #

Field3 (a, b, c, d, e) (a, b, c', d, e) c c' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_3 :: Lens (a, b, c, d, e) (a, b, c', d, e) c c' Source #

_3' :: Lens (a, b, c, d, e) (a, b, c', d, e) c c' Source #

class Field4 s t a b | s -> a, t -> b, s b -> t, t a -> s where Source #

Methods

_4 :: Lens s t a b Source #

_4' :: Lens s t a b Source #

Instances

Instances details
Field4 (a, b, c, d) (a, b, c, d') d d' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_4 :: Lens (a, b, c, d) (a, b, c, d') d d' Source #

_4' :: Lens (a, b, c, d) (a, b, c, d') d d' Source #

Field4 (a, b, c, d, e) (a, b, c, d', e) d d' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_4 :: Lens (a, b, c, d, e) (a, b, c, d', e) d d' Source #

_4' :: Lens (a, b, c, d, e) (a, b, c, d', e) d d' Source #

class Field5 s t a b | s -> a, t -> b, s b -> t, t a -> s where Source #

Methods

_5 :: Lens s t a b Source #

_5' :: Lens s t a b Source #

Instances

Instances details
Field5 (a, b, c, d, e) (a, b, c, d, e') e e' Source # 
Instance details

Defined in Agda.Utils.Lens

Methods

_5 :: Lens (a, b, c, d, e) (a, b, c, d, e') e e' Source #

_5' :: Lens (a, b, c, d, e) (a, b, c, d, e') e e' Source #

type Getting r s a = (a -> Const r a) -> s -> Const r s Source #

type Lens s t a b = forall (f :: Type -> Type). Functor f => (a -> f b) -> s -> f t Source #

Van Laarhoven style homogeneous lenses. Mnemoic: "Lens outer inner", same type argument order as 'get :: o -> i'.

type Lens' s a = Lens s s a a Source #

type LensGet o i = o -> i Source #

type LensMap o i = (i -> i) -> o -> o Source #

type LensSet o i = i -> o -> o Source #

(<&>) :: Functor f => f a -> (a -> b) -> f b infixl 1 #

Flipped version of <$>.

(<&>) = flip fmap

Examples

Expand

Apply (+1) to a list, a Just and a Right:

>>> Just 2 <&> (+1)
Just 3
>>> [1,2,3] <&> (+1)
[2,3,4]
>>> Right 3 <&> (+1)
Right 4

Since: base-4.11.0.0

(&&&) :: Arrow a => a b c -> a b c' -> a b (c, c') infixr 3 #

Fanout: send the input to both argument arrows and combine their output.

The default definition may be overridden with a more efficient version if desired.

    ╭───────╮ c
  b │ ┌─ f ─┼───>
>───┼─┤     │
    │ └─ g ─┼───>
    ╰───────╯ c'

(&) :: a -> (a -> b) -> b infixl 1 #

& is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator $, which allows & to be nested in $.

This is a version of flip id, where id is specialized from a -> a to (a -> b) -> (a -> b) which by the associativity of (->) is (a -> b) -> a -> b. flipping this yields a -> (a -> b) -> b which is the type signature of &

Examples

Expand
>>> 5 & (+1) & show
"6"
>>> sqrt $ [1 / n^2 | n <- [1..1000]] & sum & (*6)
3.1406380562059946

Since: base-4.8.0.0