Agda-2.8.0: A dependently typed functional programming language and proof assistant

Safe Haskell | None
Language | Haskell2010

Agda.Utils.Lens

Description

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

Synopsis

- key :: Ord k => k -> Lens' (Map k v) (Maybe v)
- (.=) :: MonadState o m => Lens' o i -> i -> m ()
- contains :: Ord k => k -> Lens' (Set k) Bool
- set :: Lens' o i -> LensSet o i
- type Lens' o i = forall (f :: Type -> Type). Functor f => (i -> f i) -> o -> f o
- iso :: (o -> i) -> (i -> o) -> Lens' o i
- (^.) :: o -> Lens' o i -> i
- over :: Lens' o i -> LensMap o i
- type LensGet o i = o -> i
- type LensSet o i = i -> o -> o
- type LensMap o i = (i -> i) -> o -> o
- lFst :: forall a b f. Functor f => (a -> f a) -> (a, b) -> f (a, b)
- lSnd :: forall a b f. Functor f => (b -> f b) -> (a, b) -> f (a, b)
- lens :: LensGet o i -> LensSet o i -> Lens' o i
- lensProduct :: Lens' s a -> Lens' s b -> Lens' s (a, b)
- focus :: forall (m :: Type -> Type) o i a. Monad m => Lens' o i -> StateT i m a -> StateT o m a
- use :: MonadState o m => Lens' o i -> m i
- (%=) :: MonadState o m => Lens' o i -> (i -> i) -> m ()
- (%==) :: MonadState o m => Lens' o i -> (i -> m i) -> m ()
- (%%=) :: MonadState o m => Lens' o i -> (i -> m (i, r)) -> m r
- locallyState :: MonadState o m => Lens' o i -> (i -> i) -> m r -> m r
- view :: MonadReader o m => Lens' o i -> m i
- locally :: MonadReader o m => Lens' o i -> (i -> i) -> m a -> m a
- locally' :: ((o -> o) -> m a -> m a) -> Lens' o i -> (i -> i) -> m a -> m a
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- (&&&) :: Arrow a => a b c -> a b c' -> a b (c, c')

# Documentation

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

Access a map value at a given key.

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

Write a part of the state.

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

Focus on given element in a set.

set :: Lens' o i -> LensSet o i Source #

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

type Lens' o i = forall (f :: Type -> Type). Functor f => (i -> f i) -> o -> f o Source #

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

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

Build a lens out of an isomorphism.

(^.) :: o -> Lens' o i -> i infixl 8 Source #

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

over :: Lens' o i -> LensMap o i Source #

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

type LensGet o i = o -> i Source #

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

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

lFst :: forall a b f. Functor f => (a -> f a) -> (a, b) -> f (a, b) Source #

lSnd :: forall a b f. Functor f => (b -> f b) -> (a, b) -> f (a, b) Source #

lens :: LensGet o i -> LensSet o i -> Lens' o i 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!

focus :: forall (m :: Type -> Type) o i a. Monad m => Lens' o i -> StateT i m a -> StateT o m a Source #

Focus on a part of the state for a stateful computation.

use :: MonadState o m => Lens' o i -> m i Source #

Read a part of the state.

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

Modify a part of the state.

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

Modify a part of the state monadically.

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

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

Modify a part of the state locally.

view :: MonadReader o m => Lens' o i -> m i Source #

Ask for part of read-only state.

locally :: MonadReader o m => Lens' o i -> (i -> i) -> m a -> m a Source #

Modify a part of the state in a subcomputation.

locally' :: ((o -> o) -> m a -> m a) -> Lens' o i -> (i -> i) -> m a -> m a Source #

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

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

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.