{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Trustworthy #-}

#if __GLASGOW_HASKELL__ >= 806
{-# LANGUAGE PolyKinds #-}
#else
{-# LANGUAGE TypeInType #-}
#endif

#include "lens-common.h"

-------------------------------------------------------------------------------

-- |

-- Module      :  Control.Lens.Lens

-- Copyright   :  (C) 2012-16 Edward Kmett

-- License     :  BSD-style (see the file LICENSE)

-- Maintainer  :  Edward Kmett <ekmett@gmail.com>

-- Stability   :  provisional

-- Portability :  Rank2Types

--

-- A @'Lens' s t a b@ is a purely functional reference.

--

-- While a 'Control.Lens.Traversal.Traversal' could be used for

-- 'Control.Lens.Getter.Getting' like a valid 'Control.Lens.Fold.Fold', it

-- wasn't a valid 'Control.Lens.Getter.Getter' as a

-- 'Control.Lens.Getter.Getter' can't require an 'Applicative' constraint.

--

-- 'Functor', however, is a constraint on both.

--

-- @

-- type 'Lens' s t a b = forall f. 'Functor' f => (a -> f b) -> s -> f t

-- @

--

-- Every 'Lens' is a valid 'Control.Lens.Setter.Setter'.

--

-- Every 'Lens' can be used for 'Control.Lens.Getter.Getting' like a

-- 'Control.Lens.Fold.Fold' that doesn't use the 'Applicative' or

-- 'Contravariant'.

--

-- Every 'Lens' is a valid 'Control.Lens.Traversal.Traversal' that only uses

-- the 'Functor' part of the 'Applicative' it is supplied.

--

-- Every 'Lens' can be used for 'Control.Lens.Getter.Getting' like a valid

-- 'Control.Lens.Getter.Getter'.

--

-- Since every 'Lens' can be used for 'Control.Lens.Getter.Getting' like a

-- valid 'Control.Lens.Getter.Getter' it follows that it must view exactly one element in the

-- structure.

--

-- The 'Lens' laws follow from this property and the desire for it to act like

-- a 'Data.Traversable.Traversable' when used as a

-- 'Control.Lens.Traversal.Traversal'.

--

-- In the examples below, 'getter' and 'setter' are supplied as example getters

-- and setters, and are not actual functions supplied by this package.

-------------------------------------------------------------------------------

module Control.Lens.Lens
  (
  -- * Lenses

    Lens, Lens'
  , IndexedLens, IndexedLens'
  -- ** Concrete Lenses

  , ALens, ALens'
  , AnIndexedLens, AnIndexedLens'

  -- * Combinators

  , lens, ilens, iplens, withLens
  , (%%~), (%%=)
  , (%%@~), (%%@=)
  , (<%@~), (<%@=)
  , (<<%@~), (<<%@=)
  -- ** General Purpose Combinators

  , (&), (<&>), (??)
  , (&~)
  -- * Lateral Composition

  , choosing
  , chosen
  , alongside
  , inside

  -- * Setting Functionally with Passthrough

  , (<%~), (<+~), (<-~), (<*~), (<//~)
  , (<^~), (<^^~), (<**~)
  , (<||~), (<&&~), (<<>~)
  , (<<%~), (<<.~), (<<?~), (<<+~), (<<-~), (<<*~)
  , (<<//~), (<<^~), (<<^^~), (<<**~)
  , (<<||~), (<<&&~), (<<<>~)

  -- * Setting State with Passthrough

  , (<%=), (<+=), (<-=), (<*=), (<//=)
  , (<^=), (<^^=), (<**=)
  , (<||=), (<&&=), (<<>=)
  , (<<%=), (<<.=), (<<?=), (<<+=), (<<-=), (<<*=)
  , (<<//=), (<<^=), (<<^^=), (<<**=)
  , (<<||=), (<<&&=), (<<<>=)
  , (<<~)

  -- * Cloning Lenses

  , cloneLens
  , cloneIndexPreservingLens
  , cloneIndexedLens

  -- * Arrow operators

  , overA

  -- * ALens Combinators

  , storing
  , (^#)
  , (#~), (#%~), (#%%~), (<#~), (<#%~)
  , (#=), (#%=), (#%%=), (<#=), (<#%=)

  -- * Common Lenses

  , devoid
  , united
  , head1, last1

  -- * Context

  , Context(..)
  , Context'
  , locus

  -- * Lens fusion

  , fusing
  ) where

import Prelude ()

import Control.Arrow
import Control.Comonad
import Control.Lens.Internal.Context
import Control.Lens.Internal.Prelude
import Control.Lens.Internal.Getter
import Control.Lens.Internal.Indexed
import Control.Lens.Type
import Control.Monad.State as State
import Data.Functor.Apply
import Data.Functor.Reverse
import Data.Functor.Yoneda
import Data.Semigroup.Traversable
import GHC.Exts (TYPE)

-- $setup

-- >>> :set -XNoOverloadedStrings

-- >>> import Control.Lens

-- >>> import Control.Arrow

-- >>> import Control.Monad.State

-- >>> import Data.Char (chr)

-- >>> import Data.List.NonEmpty (NonEmpty ((:|)))

-- >>> import Data.Monoid (Sum (..))

-- >>> import Data.Tree (Tree (Node))

-- >>> import Debug.SimpleReflect.Expr

-- >>> import Debug.SimpleReflect.Vars as Vars hiding (f,g,h)

-- >>> let f :: Expr -> Expr; f = Debug.SimpleReflect.Vars.f

-- >>> let g :: Expr -> Expr; g = Debug.SimpleReflect.Vars.g

-- >>> let h :: Expr -> Expr -> Expr; h = Debug.SimpleReflect.Vars.h

-- >>> let getter :: Expr -> Expr; getter = fun "getter"

-- >>> let setter :: Expr -> Expr -> Expr; setter = fun "setter"


infixl 8 ^#
infixr 4 %%@~, <%@~, <<%@~, %%~, <+~, <*~, <-~, <//~, <^~, <^^~, <**~, <&&~, <||~, <<>~, <%~, <<%~, <<.~, <<?~, <#~, #~, #%~, <#%~, #%%~
       , <<+~, <<-~, <<*~, <<//~, <<^~, <<^^~, <<**~, <<||~, <<&&~, <<<>~
infix  4 %%@=, <%@=, <<%@=, %%=, <+=, <*=, <-=, <//=, <^=, <^^=, <**=, <&&=, <||=, <<>=, <%=, <<%=, <<.=, <<?=, <#=, #=, #%=, <#%=, #%%=
       , <<+=, <<-=, <<*=, <<//=, <<^=, <<^^=, <<**=, <<||=, <<&&=, <<<>=
infixr 2 <<~
infixl 1 ??, &~

-------------------------------------------------------------------------------

-- Lenses

-------------------------------------------------------------------------------


-- | 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 t a b = LensLike (Pretext (->) a b) s t a b

-- | @

-- type 'ALens'' = 'Simple' 'ALens'

-- @

type ALens' s a = ALens s s a a

-- | When you see this as an argument to a function, it expects an 'IndexedLens'

type AnIndexedLens i s t a b = Optical (Indexed i) (->) (Pretext (Indexed i) a b) s t a b

-- | @

-- type 'AnIndexedLens'' = 'Simple' ('AnIndexedLens' i)

-- @

type AnIndexedLens' i s a  = AnIndexedLens i s s a a

--------------------------

-- Constructing Lenses

--------------------------


-- | Build a 'Lens' from a getter and a setter.

--

-- @

-- 'lens' :: 'Functor' f => (s -> a) -> (s -> b -> t) -> (a -> f b) -> s -> f t

-- @

--

-- >>> s ^. lens getter setter

-- getter s

--

-- >>> s & lens getter setter .~ b

-- setter s b

--

-- >>> s & lens getter setter %~ f

-- setter s (f (getter s))

--

-- @

-- 'lens' :: (s -> a) -> (s -> a -> s) -> 'Lens'' s a

-- @

lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
lens :: forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens s -> a
sa s -> b -> t
sbt a -> f b
afb s
s = s -> b -> t
sbt s
s forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
afb (s -> a
sa s
s)
{-# INLINE lens #-}

-- | Obtain a getter and a setter from a lens, reversing 'lens'.

withLens :: forall s t a b rep (r :: TYPE rep).
            ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r
withLens :: forall s t a b r.
ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r
withLens ALens s t a b
l (s -> a) -> (s -> b -> t) -> r
f = (s -> a) -> (s -> b -> t) -> r
f (forall s t a b. s -> ALens s t a b -> a
^# ALens s t a b
l) (forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall s t a b. ALens s t a b -> b -> s -> t
storing ALens s t a b
l))
{-# INLINE withLens #-}

-- | Build an index-preserving 'Lens' from a 'Control.Lens.Getter.Getter' and a

-- 'Control.Lens.Setter.Setter'.

iplens :: (s -> a) -> (s -> b -> t) -> IndexPreservingLens s t a b
iplens :: forall s a b t.
(s -> a) -> (s -> b -> t) -> IndexPreservingLens s t a b
iplens s -> a
sa s -> b -> t
sbt p a (f b)
pafb = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \Corep p s
ws -> s -> b -> t
sbt (forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p s
ws) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f b)
pafb (s -> a
sa forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Corep p s
ws)
{-# INLINE iplens #-}

-- | Build an 'IndexedLens' from a 'Control.Lens.Getter.Getter' and

-- a 'Control.Lens.Setter.Setter'.

ilens :: (s -> (i, a)) -> (s -> b -> t) -> IndexedLens i s t a b
ilens :: forall s i a b t.
(s -> (i, a)) -> (s -> b -> t) -> IndexedLens i s t a b
ilens s -> (i, a)
sia s -> b -> t
sbt p a (f b)
iafb s
s = s -> b -> t
sbt s
s forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p a (f b)
iafb) (s -> (i, a)
sia s
s)
{-# INLINE ilens #-}

-- | This can be used to chain lens operations using @op=@ syntax

-- rather than @op~@ syntax for simple non-type-changing cases.

--

-- >>> (10,20) & _1 .~ 30 & _2 .~ 40

-- (30,40)

--

-- >>> (10,20) &~ do _1 .= 30; _2 .= 40

-- (30,40)

--

-- This does not support type-changing assignment, /e.g./

--

-- >>> (10,20) & _1 .~ "hello"

-- ("hello",20)

(&~) :: s -> State s a -> s
s
s &~ :: forall s a. s -> State s a -> s
&~ State s a
l = forall s a. State s a -> s -> s
execState State s a
l s
s
{-# INLINE (&~) #-}

-- | ('%%~') can be used in one of two scenarios:

--

-- When applied to a 'Lens', it can edit the target of the 'Lens' in a

-- structure, extracting a functorial result.

--

-- When applied to a 'Traversal', it can edit the

-- targets of the traversals, extracting an applicative summary of its

-- actions.

--

-- >>> [66,97,116,109,97,110] & each %%~ \a -> ("na", chr a)

-- ("nananananana","Batman")

--

-- For all that the definition of this combinator is just:

--

-- @

-- ('%%~') ≡ 'id'

-- @

--

-- It may be beneficial to think about it as if it had these even more

-- restricted types, however:

--

-- @

-- ('%%~') :: 'Functor' f =>     'Control.Lens.Iso.Iso' s t a b       -> (a -> f b) -> s -> f t

-- ('%%~') :: 'Functor' f =>     'Lens' s t a b      -> (a -> f b) -> s -> f t

-- ('%%~') :: 'Applicative' f => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> f b) -> s -> f t

-- @

--

-- When applied to a 'Traversal', it can edit the

-- targets of the traversals, extracting a supplemental monoidal summary

-- of its actions, by choosing @f = ((,) m)@

--

-- @

-- ('%%~') ::             'Control.Lens.Iso.Iso' s t a b       -> (a -> (r, b)) -> s -> (r, t)

-- ('%%~') ::             'Lens' s t a b      -> (a -> (r, b)) -> s -> (r, t)

-- ('%%~') :: 'Monoid' m => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> (m, b)) -> s -> (m, t)

-- @

(%%~) :: LensLike f s t a b -> (a -> f b) -> s -> f t
%%~ :: forall {k} (f :: k -> *) s (t :: k) a (b :: k).
LensLike f s t a b -> LensLike f s t a b
(%%~) = forall a. a -> a
id
{-# INLINE (%%~) #-}

-- | Modify the target of a 'Lens' in the current state returning some extra

-- information of type @r@ or modify all targets of a

-- 'Control.Lens.Traversal.Traversal' in the current state, extracting extra

-- information of type @r@ and return a monoidal summary of the changes.

--

-- >>> runState (_1 %%= \x -> (f x, g x)) (a,b)

-- (f a,(g a,b))

--

-- @

-- ('%%=') ≡ ('state' '.')

-- @

--

-- It may be useful to think of ('%%='), instead, as having either of the

-- following more restricted type signatures:

--

-- @

-- ('%%=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso' s s a b       -> (a -> (r, b)) -> m r

-- ('%%=') :: 'MonadState' s m             => 'Lens' s s a b      -> (a -> (r, b)) -> m r

-- ('%%=') :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Traversal.Traversal' s s a b -> (a -> (r, b)) -> m r

-- @

(%%=) :: MonadState s m => Over p ((,) r) s s a b -> p a (r, b) -> m r
Over p ((,) r) s s a b
l %%= :: forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= p a (r, b)
f = forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
State.state (Over p ((,) r) s s a b
l p a (r, b)
f)
{-# INLINE (%%=) #-}

-------------------------------------------------------------------------------

-- General Purpose Combinators

-------------------------------------------------------------------------------


-- | This is convenient to 'flip' argument order of composite functions defined as:

--

-- @

-- fab ?? a = fmap ($ a) fab

-- @

--

-- For the 'Functor' instance @f = ((->) r)@ you can reason about this function as if the definition was @('??') ≡ 'flip'@:

--

-- >>> (h ?? x) a

-- h a x

--

-- >>> execState ?? [] $ modify (1:)

-- [1]

--

-- >>> over _2 ?? ("hello","world") $ length

-- ("hello",5)

--

-- >>> over ?? length ?? ("hello","world") $ _2

-- ("hello",5)

(??) :: Functor f => f (a -> b) -> a -> f b
f (a -> b)
fab ?? :: forall (f :: * -> *) a b. Functor f => f (a -> b) -> a -> f b
?? a
a = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. (a -> b) -> a -> b
$ a
a) f (a -> b)
fab
{-# INLINE (??) #-}

-------------------------------------------------------------------------------

-- Common Lenses

-------------------------------------------------------------------------------


-- | Lift a 'Lens' so it can run under a function (or other corepresentable profunctor).

--

-- @

-- 'inside' :: 'Lens' s t a b -> 'Lens' (e -> s) (e -> t) (e -> a) (e -> b)

-- @

--

--

-- >>> (\x -> (x-1,x+1)) ^. inside _1 $ 5

-- 4

--

-- >>> runState (modify (1:) >> modify (2:)) ^. (inside _2) $ []

-- [2,1]

inside :: Corepresentable p => ALens s t a b -> Lens (p e s) (p e t) (p e a) (p e b)
inside :: forall (p :: * -> * -> *) s t a b e.
Corepresentable p =>
ALens s t a b -> Lens (p e s) (p e t) (p e a) (p e b)
inside ALens s t a b
l p e a -> f (p e b)
f p e s
es = p e b -> p e t
o forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> p e a -> f (p e b)
f p e a
i where
  i :: p e a
i = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \ Corep p e
e -> forall (w :: * -> * -> * -> *) a c t.
IndexedComonadStore w =>
w a c t -> a
ipos forall a b. (a -> b) -> a -> b
$ ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p e s
es Corep p e
e)
  o :: p e b -> p e t
o p e b
ea = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \ Corep p e
e -> forall (w :: * -> * -> * -> *) c a t.
IndexedComonadStore w =>
c -> w a c t -> t
ipeek (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p e b
ea Corep p e
e) forall a b. (a -> b) -> a -> b
$ ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p e s
es Corep p e
e)
{-# INLINE inside #-}

{-
-- | Lift a 'Lens' so it can run under a function (or any other corepresentable functor).
insideF :: F.Representable f => ALens s t a b -> Lens (f s) (f t) (f a) (f b)
insideF l f es = o <$> f i where
  i = F.tabulate $ \e -> ipos $ l sell (F.index es e)
  o ea = F.tabulate $ \ e -> ipeek (F.index ea e) $ l sell (F.index es e)
{-# INLINE inside #-}
-}

-- | Merge two lenses, getters, setters, folds or traversals.

--

-- @

-- 'chosen' ≡ 'choosing' 'id' 'id'

-- @

--

-- @

-- 'choosing' :: 'Control.Lens.Getter.Getter' s a     -> 'Control.Lens.Getter.Getter' s' a     -> 'Control.Lens.Getter.Getter' ('Either' s s') a

-- 'choosing' :: 'Control.Lens.Fold.Fold' s a       -> 'Control.Lens.Fold.Fold' s' a       -> 'Control.Lens.Fold.Fold' ('Either' s s') a

-- 'choosing' :: 'Lens'' s a      -> 'Lens'' s' a      -> 'Lens'' ('Either' s s') a

-- 'choosing' :: 'Control.Lens.Traversal.Traversal'' s a -> 'Control.Lens.Traversal.Traversal'' s' a -> 'Control.Lens.Traversal.Traversal'' ('Either' s s') a

-- 'choosing' :: 'Control.Lens.Setter.Setter'' s a    -> 'Control.Lens.Setter.Setter'' s' a    -> 'Control.Lens.Setter.Setter'' ('Either' s s') a

-- @

choosing :: Functor f
       => LensLike f s t a b
       -> LensLike f s' t' a b
       -> LensLike f (Either s s') (Either t t') a b
choosing :: forall (f :: * -> *) s t a b s' t'.
Functor f =>
LensLike f s t a b
-> LensLike f s' t' a b
-> LensLike f (Either s s') (Either t t') a b
choosing LensLike f s t a b
l LensLike f s' t' a b
_ a -> f b
f (Left s
a)   = forall a b. a -> Either a b
Left forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LensLike f s t a b
l a -> f b
f s
a
choosing LensLike f s t a b
_ LensLike f s' t' a b
r a -> f b
f (Right s'
a') = forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LensLike f s' t' a b
r a -> f b
f s'
a'
{-# INLINE choosing #-}

-- | This is a 'Lens' that updates either side of an 'Either', where both sides have the same type.

--

-- @

-- 'chosen' ≡ 'choosing' 'id' 'id'

-- @

--

-- >>> Left a^.chosen

-- a

--

-- >>> Right a^.chosen

-- a

--

-- >>> Right "hello"^.chosen

-- "hello"

--

-- >>> Right a & chosen *~ b

-- Right (a * b)

--

-- @

-- 'chosen' :: 'Lens' ('Either' a a) ('Either' b b) a b

-- 'chosen' f ('Left' a)  = 'Left' '<$>' f a

-- 'chosen' f ('Right' a) = 'Right' '<$>' f a

-- @

chosen :: IndexPreservingLens (Either a a) (Either b b) a b
chosen :: forall a b. IndexPreservingLens (Either a a) (Either b b) a b
chosen p a (f b)
pafb = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \Corep p (Either a a)
weaa -> forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. a -> a
id forall a. a -> a
id forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
`lmap` p a (f b)
pafb) Corep p (Either a a)
weaa forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \b
b -> case forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p (Either a a)
weaa of
  Left a
_  -> forall a b. a -> Either a b
Left  b
b
  Right a
_ -> forall a b. b -> Either a b
Right b
b
{-# INLINE chosen #-}

-- | 'alongside' makes a 'Lens' from two other lenses or a 'Getter' from two other getters

-- by executing them on their respective halves of a product.

--

-- >>> (Left a, Right b)^.alongside chosen chosen

-- (a,b)

--

-- >>> (Left a, Right b) & alongside chosen chosen .~ (c,d)

-- (Left c,Right d)

--

-- @

-- 'alongside' :: 'Lens'   s t a b -> 'Lens'   s' t' a' b' -> 'Lens'   (s,s') (t,t') (a,a') (b,b')

-- 'alongside' :: 'Getter' s   a   -> 'Getter' s'    a'    -> 'Getter' (s,s')        (a,a')

-- @

alongside :: LensLike (AlongsideLeft f b') s  t  a  b
          -> LensLike (AlongsideRight f t) s' t' a' b'
          -> LensLike f (s, s') (t, t') (a, a') (b, b')
alongside :: forall (f :: * -> *) b' s t a b s' t' a'.
LensLike (AlongsideLeft f b') s t a b
-> LensLike (AlongsideRight f t) s' t' a' b'
-> LensLike f (s, s') (t, t') (a, a') (b, b')
alongside LensLike (AlongsideLeft f b') s t a b
l1 LensLike (AlongsideRight f t) s' t' a' b'
l2 (a, a') -> f (b, b')
f (s
a1, s'
a2)
  = forall (f :: * -> *) a b. AlongsideRight f a b -> f (a, b)
getAlongsideRight forall a b. (a -> b) -> a -> b
$ LensLike (AlongsideRight f t) s' t' a' b'
l2 forall (f :: * -> *) a b. Functor f => f (a -> b) -> a -> f b
?? s'
a2 forall a b. (a -> b) -> a -> b
$ \a'
b2 -> forall (f :: * -> *) a b. f (a, b) -> AlongsideRight f a b
AlongsideRight
  forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) b a. AlongsideLeft f b a -> f (a, b)
getAlongsideLeft  forall a b. (a -> b) -> a -> b
$ LensLike (AlongsideLeft f b') s t a b
l1 forall (f :: * -> *) a b. Functor f => f (a -> b) -> a -> f b
?? s
a1 forall a b. (a -> b) -> a -> b
$ \a
b1 -> forall (f :: * -> *) b a. f (a, b) -> AlongsideLeft f b a
AlongsideLeft
  forall a b. (a -> b) -> a -> b
$ (a, a') -> f (b, b')
f (a
b1,a'
b2)
{-# INLINE alongside #-}

-- | This 'Lens' lets you 'view' the current 'pos' of any indexed

-- store comonad and 'seek' to a new position. This reduces the API

-- for working these instances to a single 'Lens'.

--

-- @

-- 'ipos' w ≡ w 'Control.Lens.Getter.^.' 'locus'

-- 'iseek' s w ≡ w '&' 'locus' 'Control.Lens.Setter..~' s

-- 'iseeks' f w ≡ w '&' 'locus' 'Control.Lens.Setter.%~' f

-- @

--

-- @

-- 'locus' :: 'Lens'' ('Context'' a s) a

-- 'locus' :: 'Conjoined' p => 'Lens'' ('Pretext'' p a s) a

-- 'locus' :: 'Conjoined' p => 'Lens'' ('PretextT'' p g a s) a

-- @

locus :: IndexedComonadStore p => Lens (p a c s) (p b c s) a b
locus :: forall (p :: * -> * -> * -> *) a c s b.
IndexedComonadStore p =>
Lens (p a c s) (p b c s) a b
locus a -> f b
f p a c s
w = (forall (w :: * -> * -> * -> *) b a c t.
IndexedComonadStore w =>
b -> w a c t -> w b c t
`iseek` p a c s
w) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f (forall (w :: * -> * -> * -> *) a c t.
IndexedComonadStore w =>
w a c t -> a
ipos p a c s
w)
{-# INLINE locus #-}

-------------------------------------------------------------------------------

-- Cloning Lenses

-------------------------------------------------------------------------------


-- | Cloning a 'Lens' is one way to make sure you aren't given

-- something weaker, such as a 'Control.Lens.Traversal.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")

cloneLens :: ALens s t a b -> Lens s t a b
cloneLens :: forall s t a b. ALens s t a b -> Lens s t a b
cloneLens ALens s t a b
l a -> f b
afb s
s = forall (p :: * -> * -> *) a b t.
Pretext p a b t
-> forall (f :: * -> *). Functor f => p a (f b) -> f t
runPretext (ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s) a -> f b
afb
{-# INLINE cloneLens #-}

-- | Clone a 'Lens' as an 'IndexedPreservingLens' that just passes through whatever

-- index is on any 'IndexedLens', 'IndexedFold', 'IndexedGetter' or  'IndexedTraversal' it is composed with.

cloneIndexPreservingLens :: ALens s t a b -> IndexPreservingLens s t a b
cloneIndexPreservingLens :: forall s t a b. ALens s t a b -> IndexPreservingLens s t a b
cloneIndexPreservingLens ALens s t a b
l p a (f b)
pafb = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \Corep p s
ws -> forall (p :: * -> * -> *) a b t.
Pretext p a b t
-> forall (f :: * -> *). Functor f => p a (f b) -> f t
runPretext (ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell (forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p s
ws)) forall a b. (a -> b) -> a -> b
$ \a
a -> forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f b)
pafb (a
a forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Corep p s
ws)
{-# INLINE cloneIndexPreservingLens #-}

-- | Clone an 'IndexedLens' as an 'IndexedLens' with the same index.

cloneIndexedLens :: AnIndexedLens i s t a b -> IndexedLens i s t a b
cloneIndexedLens :: forall i s t a b. AnIndexedLens i s t a b -> IndexedLens i s t a b
cloneIndexedLens AnIndexedLens i s t a b
l p a (f b)
f s
s = forall (p :: * -> * -> *) a b t.
Pretext p a b t
-> forall (f :: * -> *). Functor f => p a (f b) -> f t
runPretext (AnIndexedLens i s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s) (forall i a b. (i -> a -> b) -> Indexed i a b
Indexed (forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p a (f b)
f))
{-# INLINE cloneIndexedLens #-}

-------------------------------------------------------------------------------

-- Setting and Remembering

-------------------------------------------------------------------------------


-- | Modify the target of a 'Lens' and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.%~') is more flexible.

--

-- @

-- ('<%~') ::             'Lens' s t a b      -> (a -> b) -> s -> (b, t)

-- ('<%~') ::             'Control.Lens.Iso.Iso' s t a b       -> (a -> b) -> s -> (b, t)

-- ('<%~') :: 'Monoid' b => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> b) -> s -> (b, t)

-- @

(<%~) :: LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
LensLike ((,) b) s t a b
l <%~ :: forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ a -> b
f = LensLike ((,) b) s t a b
l forall a b. (a -> b) -> a -> b
$ (\b
t -> (b
t, b
t)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f
{-# INLINE (<%~) #-}

-- | Increment the target of a numerically valued 'Lens' and return the result.

--

-- When you do not need the result of the addition, ('Control.Lens.Setter.+~') is more flexible.

--

-- @

-- ('<+~') :: 'Num' a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<+~') :: 'Num' a => 'Control.Lens.Iso.Iso'' s a  -> a -> s -> (a, s)

-- @

(<+~) :: Num a => LensLike ((,)a) s t a a -> a -> s -> (a, t)
LensLike ((,) a) s t a a
l <+~ :: forall a s t. Num a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
<+~ a
a = LensLike ((,) a) s t a a
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (forall a. Num a => a -> a -> a
+ a
a)
{-# INLINE (<+~) #-}

-- | Decrement the target of a numerically valued 'Lens' and return the result.

--

-- When you do not need the result of the subtraction, ('Control.Lens.Setter.-~') is more flexible.

--

-- @

-- ('<-~') :: 'Num' a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<-~') :: 'Num' a => 'Control.Lens.Iso.Iso'' s a  -> a -> s -> (a, s)

-- @

(<-~) :: Num a => LensLike ((,)a) s t a a -> a -> s -> (a, t)
LensLike ((,) a) s t a a
l <-~ :: forall a s t. Num a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
<-~ a
a = LensLike ((,) a) s t a a
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ forall a. Num a => a -> a -> a
subtract a
a
{-# INLINE (<-~) #-}

-- | Multiply the target of a numerically valued 'Lens' and return the result.

--

-- When you do not need the result of the multiplication, ('Control.Lens.Setter.*~') is more

-- flexible.

--

-- @

-- ('<*~') :: 'Num' a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<*~') :: 'Num' a => 'Control.Lens.Iso.Iso''  s a -> a -> s -> (a, s)

-- @

(<*~) :: Num a => LensLike ((,)a) s t a a -> a -> s -> (a, t)
LensLike ((,) a) s t a a
l <*~ :: forall a s t. Num a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
<*~ a
a = LensLike ((,) a) s t a a
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (forall a. Num a => a -> a -> a
* a
a)
{-# INLINE (<*~) #-}

-- | Divide the target of a fractionally valued 'Lens' and return the result.

--

-- When you do not need the result of the division, ('Control.Lens.Setter.//~') is more flexible.

--

-- @

-- ('<//~') :: 'Fractional' a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<//~') :: 'Fractional' a => 'Control.Lens.Iso.Iso''  s a -> a -> s -> (a, s)

-- @

(<//~) :: Fractional a => LensLike ((,)a) s t a a -> a -> s -> (a, t)
LensLike ((,) a) s t a a
l <//~ :: forall a s t.
Fractional a =>
LensLike ((,) a) s t a a -> a -> s -> (a, t)
<//~ a
a = LensLike ((,) a) s t a a
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (forall a. Fractional a => a -> a -> a
/ a
a)
{-# INLINE (<//~) #-}

-- | Raise the target of a numerically valued 'Lens' to a non-negative

-- 'Integral' power and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.^~') is more flexible.

--

-- @

-- ('<^~') :: ('Num' a, 'Integral' e) => 'Lens'' s a -> e -> s -> (a, s)

-- ('<^~') :: ('Num' a, 'Integral' e) => 'Control.Lens.Iso.Iso'' s a -> e -> s -> (a, s)

-- @

(<^~) :: (Num a, Integral e) => LensLike ((,)a) s t a a -> e -> s -> (a, t)
LensLike ((,) a) s t a a
l <^~ :: forall a e s t.
(Num a, Integral e) =>
LensLike ((,) a) s t a a -> e -> s -> (a, t)
<^~ e
e = LensLike ((,) a) s t a a
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (forall a b. (Num a, Integral b) => a -> b -> a
^ e
e)
{-# INLINE (<^~) #-}

-- | Raise the target of a fractionally valued 'Lens' to an 'Integral' power

-- and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.^^~') is more flexible.

--

-- @

-- ('<^^~') :: ('Fractional' a, 'Integral' e) => 'Lens'' s a -> e -> s -> (a, s)

-- ('<^^~') :: ('Fractional' a, 'Integral' e) => 'Control.Lens.Iso.Iso'' s a -> e -> s -> (a, s)

-- @

(<^^~) :: (Fractional a, Integral e) => LensLike ((,)a) s t a a -> e -> s -> (a, t)
LensLike ((,) a) s t a a
l <^^~ :: forall a e s t.
(Fractional a, Integral e) =>
LensLike ((,) a) s t a a -> e -> s -> (a, t)
<^^~ e
e = LensLike ((,) a) s t a a
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (forall a b. (Fractional a, Integral b) => a -> b -> a
^^ e
e)
{-# INLINE (<^^~) #-}

-- | Raise the target of a floating-point valued 'Lens' to an arbitrary power

-- and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.**~') is more flexible.

--

-- @

-- ('<**~') :: 'Floating' a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<**~') :: 'Floating' a => 'Control.Lens.Iso.Iso'' s a  -> a -> s -> (a, s)

-- @

(<**~) :: Floating a => LensLike ((,)a) s t a a -> a -> s -> (a, t)
LensLike ((,) a) s t a a
l <**~ :: forall a s t.
Floating a =>
LensLike ((,) a) s t a a -> a -> s -> (a, t)
<**~ a
a = LensLike ((,) a) s t a a
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (forall a. Floating a => a -> a -> a
** a
a)
{-# INLINE (<**~) #-}

-- | Logically '||' a Boolean valued 'Lens' and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.||~') is more flexible.

--

-- @

-- ('<||~') :: 'Lens'' s 'Bool' -> 'Bool' -> s -> ('Bool', s)

-- ('<||~') :: 'Control.Lens.Iso.Iso'' s 'Bool'  -> 'Bool' -> s -> ('Bool', s)

-- @

(<||~) :: LensLike ((,)Bool) s t Bool Bool -> Bool -> s -> (Bool, t)
LensLike ((,) Bool) s t Bool Bool
l <||~ :: forall s t.
LensLike ((,) Bool) s t Bool Bool -> Bool -> s -> (Bool, t)
<||~ Bool
b = LensLike ((,) Bool) s t Bool Bool
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (Bool -> Bool -> Bool
|| Bool
b)
{-# INLINE (<||~) #-}

-- | Logically '&&' a Boolean valued 'Lens' and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.&&~') is more flexible.

--

-- @

-- ('<&&~') :: 'Lens'' s 'Bool' -> 'Bool' -> s -> ('Bool', s)

-- ('<&&~') :: 'Control.Lens.Iso.Iso'' s 'Bool'  -> 'Bool' -> s -> ('Bool', s)

-- @

(<&&~) :: LensLike ((,)Bool) s t Bool Bool -> Bool -> s -> (Bool, t)
LensLike ((,) Bool) s t Bool Bool
l <&&~ :: forall s t.
LensLike ((,) Bool) s t Bool Bool -> Bool -> s -> (Bool, t)
<&&~ Bool
b = LensLike ((,) Bool) s t Bool Bool
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (Bool -> Bool -> Bool
&& Bool
b)
{-# INLINE (<&&~) #-}

-- | Modify the target of a 'Lens', but return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.%~') is more flexible.

--

-- @

-- ('<<%~') ::             'Lens' s t a b      -> (a -> b) -> s -> (a, t)

-- ('<<%~') ::             'Control.Lens.Iso.Iso' s t a b       -> (a -> b) -> s -> (a, t)

-- ('<<%~') :: 'Monoid' a => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> b) -> s -> (a, t)

-- @

(<<%~) :: LensLike ((,)a) s t a b -> (a -> b) -> s -> (a, t)
<<%~ :: forall a s t b. LensLike ((,) a) s t a b -> (a -> b) -> s -> (a, t)
(<<%~) LensLike ((,) a) s t a b
l = LensLike ((,) a) s t a b
l forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap (\a
a -> (a
a, a
a)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (c, a) (c, b)
second'
{-# INLINE (<<%~) #-}

-- | Replace the target of a 'Lens', but return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter..~') is more flexible.

--

-- @

-- ('<<.~') ::             'Lens' s t a b      -> b -> s -> (a, t)

-- ('<<.~') ::             'Control.Lens.Iso.Iso' s t a b       -> b -> s -> (a, t)

-- ('<<.~') :: 'Monoid' a => 'Control.Lens.Traversal.Traversal' s t a b -> b -> s -> (a, t)

-- @

(<<.~) :: LensLike ((,)a) s t a b -> b -> s -> (a, t)
LensLike ((,) a) s t a b
l <<.~ :: forall a s t b. LensLike ((,) a) s t a b -> b -> s -> (a, t)
<<.~ b
b = LensLike ((,) a) s t a b
l forall a b. (a -> b) -> a -> b
$ \a
a -> (a
a, b
b)
{-# INLINE (<<.~) #-}

-- | Replace the target of a 'Lens' with a 'Just' value, but return the old value.

--

-- If you do not need the old value ('Control.Lens.Setter.?~') is more flexible.

--

-- >>> import qualified Data.Map as Map

-- >>> _2.at "hello" <<?~ "world" $ (42,Map.fromList [("goodnight","gracie")])

-- (Nothing,(42,fromList [("goodnight","gracie"),("hello","world")]))

--

-- @

-- ('<<?~') :: 'Iso' s t a ('Maybe' b)       -> b -> s -> (a, t)

-- ('<<?~') :: 'Lens' s t a ('Maybe' b)      -> b -> s -> (a, t)

-- ('<<?~') :: 'Traversal' s t a ('Maybe' b) -> b -> s -> (a, t)

-- @

(<<?~) :: LensLike ((,)a) s t a (Maybe b) -> b -> s -> (a, t)
LensLike ((,) a) s t a (Maybe b)
l <<?~ :: forall a s t b.
LensLike ((,) a) s t a (Maybe b) -> b -> s -> (a, t)
<<?~ b
b = LensLike ((,) a) s t a (Maybe b)
l forall a s t b. LensLike ((,) a) s t a b -> b -> s -> (a, t)
<<.~ forall a. a -> Maybe a
Just b
b
{-# INLINE (<<?~) #-}

-- | Increment the target of a numerically valued 'Lens' and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.+~') is more flexible.

--

-- >>> (a,b) & _1 <<+~ c

-- (a,(a + c,b))

--

-- >>> (a,b) & _2 <<+~ c

-- (b,(a,b + c))

--

-- @

-- ('<<+~') :: 'Num' a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<<+~') :: 'Num' a => 'Iso'' s a -> a -> s -> (a, s)

-- @

(<<+~) :: Num a => LensLike' ((,) a) s a -> a -> s -> (a, s)
LensLike' ((,) a) s a
l <<+~ :: forall a s. Num a => LensLike' ((,) a) s a -> a -> s -> (a, s)
<<+~ a
b = LensLike' ((,) a) s a
l forall a b. (a -> b) -> a -> b
$ \a
a -> (a
a, a
a forall a. Num a => a -> a -> a
+ a
b)
{-# INLINE (<<+~) #-}

-- | Decrement the target of a numerically valued 'Lens' and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.-~') is more flexible.

--

-- >>> (a,b) & _1 <<-~ c

-- (a,(a - c,b))

--

-- >>> (a,b) & _2 <<-~ c

-- (b,(a,b - c))

--

-- @

-- ('<<-~') :: 'Num' a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<<-~') :: 'Num' a => 'Iso'' s a -> a -> s -> (a, s)

-- @

(<<-~) :: Num a => LensLike' ((,) a) s a -> a -> s -> (a, s)
LensLike' ((,) a) s a
l <<-~ :: forall a s. Num a => LensLike' ((,) a) s a -> a -> s -> (a, s)
<<-~ a
b = LensLike' ((,) a) s a
l forall a b. (a -> b) -> a -> b
$ \a
a -> (a
a, a
a forall a. Num a => a -> a -> a
- a
b)
{-# INLINE (<<-~) #-}

-- | Multiply the target of a numerically valued 'Lens' and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.-~') is more flexible.

--

-- >>> (a,b) & _1 <<*~ c

-- (a,(a * c,b))

--

-- >>> (a,b) & _2 <<*~ c

-- (b,(a,b * c))

--

-- @

-- ('<<*~') :: 'Num' a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<<*~') :: 'Num' a => 'Iso'' s a -> a -> s -> (a, s)

-- @

(<<*~) :: Num a => LensLike' ((,) a) s a -> a -> s -> (a, s)
LensLike' ((,) a) s a
l <<*~ :: forall a s. Num a => LensLike' ((,) a) s a -> a -> s -> (a, s)
<<*~ a
b = LensLike' ((,) a) s a
l forall a b. (a -> b) -> a -> b
$ \a
a -> (a
a, a
a forall a. Num a => a -> a -> a
* a
b)
{-# INLINE (<<*~) #-}

-- | Divide the target of a numerically valued 'Lens' and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.//~') is more flexible.

--

-- >>> (a,b) & _1 <<//~ c

-- (a,(a / c,b))

--

-- >>> ("Hawaii",10) & _2 <<//~ 2

-- (10.0,("Hawaii",5.0))

--

-- @

-- ('<<//~') :: Fractional a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<<//~') :: Fractional a => 'Iso'' s a -> a -> s -> (a, s)

-- @

(<<//~) :: Fractional a => LensLike' ((,) a) s a -> a -> s -> (a, s)
LensLike' ((,) a) s a
l <<//~ :: forall a s.
Fractional a =>
LensLike' ((,) a) s a -> a -> s -> (a, s)
<<//~ a
b = LensLike' ((,) a) s a
l forall a b. (a -> b) -> a -> b
$ \a
a -> (a
a, a
a forall a. Fractional a => a -> a -> a
/ a
b)
{-# INLINE (<<//~) #-}

-- | Raise the target of a numerically valued 'Lens' to a non-negative power and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.^~') is more flexible.

--

-- @

-- ('<<^~') :: ('Num' a, 'Integral' e) => 'Lens'' s a -> e -> s -> (a, s)

-- ('<<^~') :: ('Num' a, 'Integral' e) => 'Iso'' s a -> e -> s -> (a, s)

-- @

(<<^~) :: (Num a, Integral e) => LensLike' ((,) a) s a -> e -> s -> (a, s)
LensLike' ((,) a) s a
l <<^~ :: forall a e s.
(Num a, Integral e) =>
LensLike' ((,) a) s a -> e -> s -> (a, s)
<<^~ e
e = LensLike' ((,) a) s a
l forall a b. (a -> b) -> a -> b
$ \a
a -> (a
a, a
a forall a b. (Num a, Integral b) => a -> b -> a
^ e
e)
{-# INLINE (<<^~) #-}

-- | Raise the target of a fractionally valued 'Lens' to an integral power and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.^^~') is more flexible.

--

-- @

-- ('<<^^~') :: ('Fractional' a, 'Integral' e) => 'Lens'' s a -> e -> s -> (a, s)

-- ('<<^^~') :: ('Fractional' a, 'Integral' e) => 'Iso'' s a -> e -> S -> (a, s)

-- @

(<<^^~) :: (Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> s -> (a, s)
LensLike' ((,) a) s a
l <<^^~ :: forall a e s.
(Fractional a, Integral e) =>
LensLike' ((,) a) s a -> e -> s -> (a, s)
<<^^~ e
e = LensLike' ((,) a) s a
l forall a b. (a -> b) -> a -> b
$ \a
a -> (a
a, a
a forall a b. (Fractional a, Integral b) => a -> b -> a
^^ e
e)
{-# INLINE (<<^^~) #-}

-- | Raise the target of a floating-point valued 'Lens' to an arbitrary power and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.**~') is more flexible.

--

-- >>> (a,b) & _1 <<**~ c

-- (a,(a**c,b))

--

-- >>> (a,b) & _2 <<**~ c

-- (b,(a,b**c))

--

-- @

-- ('<<**~') :: 'Floating' a => 'Lens'' s a -> a -> s -> (a, s)

-- ('<<**~') :: 'Floating' a => 'Iso'' s a -> a -> s -> (a, s)

-- @

(<<**~) :: Floating a => LensLike' ((,) a) s a -> a -> s -> (a, s)
LensLike' ((,) a) s a
l <<**~ :: forall a s. Floating a => LensLike' ((,) a) s a -> a -> s -> (a, s)
<<**~ a
e = LensLike' ((,) a) s a
l forall a b. (a -> b) -> a -> b
$ \a
a -> (a
a, a
a forall a. Floating a => a -> a -> a
** a
e)
{-# INLINE (<<**~) #-}

-- | Logically '||' the target of a 'Bool'-valued 'Lens' and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.||~') is more flexible.

--

-- >>> (False,6) & _1 <<||~ True

-- (False,(True,6))

--

-- >>> ("hello",True) & _2 <<||~ False

-- (True,("hello",True))

--

-- @

-- ('<<||~') :: 'Lens'' s 'Bool' -> 'Bool' -> s -> ('Bool', s)

-- ('<<||~') :: 'Iso'' s 'Bool' -> 'Bool' -> s -> ('Bool', s)

-- @

(<<||~) :: LensLike' ((,) Bool) s Bool -> Bool -> s -> (Bool, s)
LensLike' ((,) Bool) s Bool
l <<||~ :: forall s. LensLike' ((,) Bool) s Bool -> Bool -> s -> (Bool, s)
<<||~ Bool
b = LensLike' ((,) Bool) s Bool
l forall a b. (a -> b) -> a -> b
$ \Bool
a -> (Bool
a, Bool
b Bool -> Bool -> Bool
|| Bool
a)
{-# INLINE (<<||~) #-}

-- | Logically '&&' the target of a 'Bool'-valued 'Lens' and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.&&~') is more flexible.

--

-- >>> (False,6) & _1 <<&&~ True

-- (False,(False,6))

--

-- >>> ("hello",True) & _2 <<&&~ False

-- (True,("hello",False))

--

-- @

-- ('<<&&~') :: 'Lens'' s Bool -> Bool -> s -> (Bool, s)

-- ('<<&&~') :: 'Iso'' s Bool -> Bool -> s -> (Bool, s)

-- @

(<<&&~) :: LensLike' ((,) Bool) s Bool -> Bool -> s -> (Bool, s)
LensLike' ((,) Bool) s Bool
l <<&&~ :: forall s. LensLike' ((,) Bool) s Bool -> Bool -> s -> (Bool, s)
<<&&~ Bool
b = LensLike' ((,) Bool) s Bool
l forall a b. (a -> b) -> a -> b
$ \Bool
a -> (Bool
a, Bool
b Bool -> Bool -> Bool
&& Bool
a)
{-# INLINE (<<&&~) #-}

-- | Modify the target of a monoidally valued 'Lens' by using ('<>') a new value and return the old value.

--

-- When you do not need the old value, ('Control.Lens.Setter.<>~') is more flexible.

--

-- >>> (Sum a,b) & _1 <<<>~ Sum c

-- (Sum {getSum = a},(Sum {getSum = a + c},b))

--

-- >>> _2 <<<>~ ", 007" $ ("James", "Bond")

-- ("Bond",("James","Bond, 007"))

--

-- @

-- ('<<<>~') :: 'Semigroup' r => 'Lens'' s r -> r -> s -> (r, s)

-- ('<<<>~') :: 'Semigroup' r => 'Iso'' s r -> r -> s -> (r, s)

-- @

(<<<>~) :: Semigroup r => LensLike' ((,) r) s r -> r -> s -> (r, s)
LensLike' ((,) r) s r
l <<<>~ :: forall r s.
Semigroup r =>
LensLike' ((,) r) s r -> r -> s -> (r, s)
<<<>~ r
b = LensLike' ((,) r) s r
l forall a b. (a -> b) -> a -> b
$ \r
a -> (r
a, r
a forall a. Semigroup a => a -> a -> a
<> r
b)
{-# INLINE (<<<>~) #-}

-------------------------------------------------------------------------------

-- Setting and Remembering State

-------------------------------------------------------------------------------


-- | Modify the target of a 'Lens' into your 'Monad''s state by a user supplied

-- function and return the result.

--

-- When applied to a 'Control.Lens.Traversal.Traversal', it this will return a monoidal summary of all of the intermediate

-- results.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.%=') is more flexible.

--

-- @

-- ('<%=') :: 'MonadState' s m             => 'Lens'' s a      -> (a -> a) -> m a

-- ('<%=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> (a -> a) -> m a

-- ('<%=') :: ('MonadState' s m, 'Monoid' a) => 'Control.Lens.Traversal.Traversal'' s a -> (a -> a) -> m a

-- @

(<%=) :: MonadState s m => LensLike ((,)b) s s a b -> (a -> b) -> m b
LensLike ((,) b) s s a b
l <%= :: forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= a -> b
f = LensLike ((,) b) s s a b
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= (\b
b -> (b
b, b
b)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f
{-# INLINE (<%=) #-}


-- | Add to the target of a numerically valued 'Lens' into your 'Monad''s state

-- and return the result.

--

-- When you do not need the result of the addition, ('Control.Lens.Setter.+=') is more

-- flexible.

--

-- @

-- ('<+=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a -> a -> m a

-- ('<+=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a

-- @

(<+=) :: (MonadState s m, Num a) => LensLike' ((,)a) s a -> a -> m a
LensLike' ((,) a) s a
l <+= :: forall s (m :: * -> *) a.
(MonadState s m, Num a) =>
LensLike' ((,) a) s a -> a -> m a
<+= a
a = LensLike' ((,) a) s a
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (forall a. Num a => a -> a -> a
+ a
a)
{-# INLINE (<+=) #-}

-- | Subtract from the target of a numerically valued 'Lens' into your 'Monad''s

-- state and return the result.

--

-- When you do not need the result of the subtraction, ('Control.Lens.Setter.-=') is more

-- flexible.

--

-- @

-- ('<-=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a -> a -> m a

-- ('<-=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a

-- @

(<-=) :: (MonadState s m, Num a) => LensLike' ((,)a) s a -> a -> m a
LensLike' ((,) a) s a
l <-= :: forall s (m :: * -> *) a.
(MonadState s m, Num a) =>
LensLike' ((,) a) s a -> a -> m a
<-= a
a = LensLike' ((,) a) s a
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= forall a. Num a => a -> a -> a
subtract a
a
{-# INLINE (<-=) #-}

-- | Multiply the target of a numerically valued 'Lens' into your 'Monad''s

-- state and return the result.

--

-- When you do not need the result of the multiplication, ('Control.Lens.Setter.*=') is more

-- flexible.

--

-- @

-- ('<*=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a -> a -> m a

-- ('<*=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a

-- @

(<*=) :: (MonadState s m, Num a) => LensLike' ((,)a) s a -> a -> m a
LensLike' ((,) a) s a
l <*= :: forall s (m :: * -> *) a.
(MonadState s m, Num a) =>
LensLike' ((,) a) s a -> a -> m a
<*= a
a = LensLike' ((,) a) s a
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (forall a. Num a => a -> a -> a
* a
a)
{-# INLINE (<*=) #-}

-- | Divide the target of a fractionally valued 'Lens' into your 'Monad''s state

-- and return the result.

--

-- When you do not need the result of the division, ('Control.Lens.Setter.//=') is more flexible.

--

-- @

-- ('<//=') :: ('MonadState' s m, 'Fractional' a) => 'Lens'' s a -> a -> m a

-- ('<//=') :: ('MonadState' s m, 'Fractional' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a

-- @

(<//=) :: (MonadState s m, Fractional a) => LensLike' ((,)a) s a -> a -> m a
LensLike' ((,) a) s a
l <//= :: forall s (m :: * -> *) a.
(MonadState s m, Fractional a) =>
LensLike' ((,) a) s a -> a -> m a
<//= a
a = LensLike' ((,) a) s a
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (forall a. Fractional a => a -> a -> a
/ a
a)
{-# INLINE (<//=) #-}

-- | Raise the target of a numerically valued 'Lens' into your 'Monad''s state

-- to a non-negative 'Integral' power and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.^=') is more flexible.

--

-- @

-- ('<^=') :: ('MonadState' s m, 'Num' a, 'Integral' e) => 'Lens'' s a -> e -> m a

-- ('<^=') :: ('MonadState' s m, 'Num' a, 'Integral' e) => 'Control.Lens.Iso.Iso'' s a -> e -> m a

-- @

(<^=) :: (MonadState s m, Num a, Integral e) => LensLike' ((,)a) s a -> e -> m a
LensLike' ((,) a) s a
l <^= :: forall s (m :: * -> *) a e.
(MonadState s m, Num a, Integral e) =>
LensLike' ((,) a) s a -> e -> m a
<^= e
e = LensLike' ((,) a) s a
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (forall a b. (Num a, Integral b) => a -> b -> a
^ e
e)
{-# INLINE (<^=) #-}

-- | Raise the target of a fractionally valued 'Lens' into your 'Monad''s state

-- to an 'Integral' power and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.^^=') is more flexible.

--

-- @

-- ('<^^=') :: ('MonadState' s m, 'Fractional' b, 'Integral' e) => 'Lens'' s a -> e -> m a

-- ('<^^=') :: ('MonadState' s m, 'Fractional' b, 'Integral' e) => 'Control.Lens.Iso.Iso'' s a  -> e -> m a

-- @

(<^^=) :: (MonadState s m, Fractional a, Integral e) => LensLike' ((,)a) s a -> e -> m a
LensLike' ((,) a) s a
l <^^= :: forall s (m :: * -> *) a e.
(MonadState s m, Fractional a, Integral e) =>
LensLike' ((,) a) s a -> e -> m a
<^^= e
e = LensLike' ((,) a) s a
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (forall a b. (Fractional a, Integral b) => a -> b -> a
^^ e
e)
{-# INLINE (<^^=) #-}

-- | Raise the target of a floating-point valued 'Lens' into your 'Monad''s

-- state to an arbitrary power and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.**=') is more flexible.

--

-- @

-- ('<**=') :: ('MonadState' s m, 'Floating' a) => 'Lens'' s a -> a -> m a

-- ('<**=') :: ('MonadState' s m, 'Floating' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a

-- @

(<**=) :: (MonadState s m, Floating a) => LensLike' ((,)a) s a -> a -> m a
LensLike' ((,) a) s a
l <**= :: forall s (m :: * -> *) a.
(MonadState s m, Floating a) =>
LensLike' ((,) a) s a -> a -> m a
<**= a
a = LensLike' ((,) a) s a
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (forall a. Floating a => a -> a -> a
** a
a)
{-# INLINE (<**=) #-}

-- | Logically '||' a Boolean valued 'Lens' into your 'Monad''s state and return

-- the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.||=') is more flexible.

--

-- @

-- ('<||=') :: 'MonadState' s m => 'Lens'' s 'Bool' -> 'Bool' -> m 'Bool'

-- ('<||=') :: 'MonadState' s m => 'Control.Lens.Iso.Iso'' s 'Bool'  -> 'Bool' -> m 'Bool'

-- @

(<||=) :: MonadState s m => LensLike' ((,)Bool) s Bool -> Bool -> m Bool
LensLike' ((,) Bool) s Bool
l <||= :: forall s (m :: * -> *).
MonadState s m =>
LensLike' ((,) Bool) s Bool -> Bool -> m Bool
<||= Bool
b = LensLike' ((,) Bool) s Bool
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (Bool -> Bool -> Bool
|| Bool
b)
{-# INLINE (<||=) #-}

-- | Logically '&&' a Boolean valued 'Lens' into your 'Monad''s state and return

-- the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.&&=') is more flexible.

--

-- @

-- ('<&&=') :: 'MonadState' s m => 'Lens'' s 'Bool' -> 'Bool' -> m 'Bool'

-- ('<&&=') :: 'MonadState' s m => 'Control.Lens.Iso.Iso'' s 'Bool'  -> 'Bool' -> m 'Bool'

-- @

(<&&=) :: MonadState s m => LensLike' ((,)Bool) s Bool -> Bool -> m Bool
LensLike' ((,) Bool) s Bool
l <&&= :: forall s (m :: * -> *).
MonadState s m =>
LensLike' ((,) Bool) s Bool -> Bool -> m Bool
<&&= Bool
b = LensLike' ((,) Bool) s Bool
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (Bool -> Bool -> Bool
&& Bool
b)
{-# INLINE (<&&=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by a user supplied

-- function and return the /old/ value that was replaced.

--

-- When applied to a 'Control.Lens.Traversal.Traversal', this will return a monoidal summary of all of the old values

-- present.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.%=') is more flexible.

--

-- @

-- ('<<%=') :: 'MonadState' s m             => 'Lens'' s a      -> (a -> a) -> m a

-- ('<<%=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> (a -> a) -> m a

-- ('<<%=') :: ('MonadState' s m, 'Monoid' a) => 'Control.Lens.Traversal.Traversal'' s a -> (a -> a) -> m a

-- @

--

-- @('<<%=') :: 'MonadState' s m => 'LensLike' ((,)a) s s a b -> (a -> b) -> m a@

(<<%=) :: (Strong p, MonadState s m) => Over p ((,)a) s s a b -> p a b -> m a
Over p ((,) a) s s a b
l <<%= :: forall (p :: * -> * -> *) s (m :: * -> *) a b.
(Strong p, MonadState s m) =>
Over p ((,) a) s s a b -> p a b -> m a
<<%= p a b
f = Over p ((,) a) s s a b
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap (\a
a -> (a
a,a
a)) (forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (c, a) (c, b)
second' p a b
f)
{-# INLINE (<<%=) #-}

-- | Replace the target of a 'Lens' into your 'Monad''s state with a user supplied

-- value and return the /old/ value that was replaced.

--

-- When applied to a 'Control.Lens.Traversal.Traversal', this will return a monoidal summary of all of the old values

-- present.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter..=') is more flexible.

--

-- @

-- ('<<.=') :: 'MonadState' s m             => 'Lens'' s a      -> a -> m a

-- ('<<.=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> a -> m a

-- ('<<.=') :: ('MonadState' s m, 'Monoid' a) => 'Control.Lens.Traversal.Traversal'' s a -> a -> m a

-- @

(<<.=) :: MonadState s m => LensLike ((,)a) s s a b -> b -> m a
LensLike ((,) a) s s a b
l <<.= :: forall s (m :: * -> *) a b.
MonadState s m =>
LensLike ((,) a) s s a b -> b -> m a
<<.= b
b = LensLike ((,) a) s s a b
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \a
a -> (a
a,b
b)
{-# INLINE (<<.=) #-}

-- | Replace the target of a 'Lens' into your 'Monad''s state with 'Just' a user supplied

-- value and return the /old/ value that was replaced.

--

-- When applied to a 'Control.Lens.Traversal.Traversal', this will return a monoidal summary of all of the old values

-- present.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.?=') is more flexible.

--

-- @

-- ('<<?=') :: 'MonadState' s m             => 'Lens' s t a (Maybe b)      -> b -> m a

-- ('<<?=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso' s t a (Maybe b)       -> b -> m a

-- ('<<?=') :: ('MonadState' s m, 'Monoid' a) => 'Control.Lens.Traversal.Traversal' s t a (Maybe b) -> b -> m a

-- @

(<<?=) :: MonadState s m => LensLike ((,)a) s s a (Maybe b) -> b -> m a
LensLike ((,) a) s s a (Maybe b)
l <<?= :: forall s (m :: * -> *) a b.
MonadState s m =>
LensLike ((,) a) s s a (Maybe b) -> b -> m a
<<?= b
b = LensLike ((,) a) s s a (Maybe b)
l forall s (m :: * -> *) a b.
MonadState s m =>
LensLike ((,) a) s s a b -> b -> m a
<<.= forall a. a -> Maybe a
Just b
b
{-# INLINE (<<?=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by adding a value

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.+=') is more flexible.

--

-- @

-- ('<<+=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a -> a -> m a

-- ('<<+=') :: ('MonadState' s m, 'Num' a) => 'Iso'' s a -> a -> m a

-- @

(<<+=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
LensLike' ((,) a) s a
l <<+= :: forall s (m :: * -> *) a.
(MonadState s m, Num a) =>
LensLike' ((,) a) s a -> a -> m a
<<+= a
n = LensLike' ((,) a) s a
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \a
a -> (a
a, a
a forall a. Num a => a -> a -> a
+ a
n)
{-# INLINE (<<+=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by subtracting a value

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.-=') is more flexible.

--

-- @

-- ('<<-=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a -> a -> m a

-- ('<<-=') :: ('MonadState' s m, 'Num' a) => 'Iso'' s a -> a -> m a

-- @

(<<-=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
LensLike' ((,) a) s a
l <<-= :: forall s (m :: * -> *) a.
(MonadState s m, Num a) =>
LensLike' ((,) a) s a -> a -> m a
<<-= a
n = LensLike' ((,) a) s a
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \a
a -> (a
a, a
a forall a. Num a => a -> a -> a
- a
n)
{-# INLINE (<<-=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by multipling a value

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.*=') is more flexible.

--

-- @

-- ('<<*=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a -> a -> m a

-- ('<<*=') :: ('MonadState' s m, 'Num' a) => 'Iso'' s a -> a -> m a

-- @

(<<*=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
LensLike' ((,) a) s a
l <<*= :: forall s (m :: * -> *) a.
(MonadState s m, Num a) =>
LensLike' ((,) a) s a -> a -> m a
<<*= a
n = LensLike' ((,) a) s a
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \a
a -> (a
a, a
a forall a. Num a => a -> a -> a
* a
n)
{-# INLINE (<<*=) #-}

-- | Modify the target of a 'Lens' into your 'Monad'\s state by dividing by a value

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.//=') is more flexible.

--

-- @

-- ('<<//=') :: ('MonadState' s m, 'Fractional' a) => 'Lens'' s a -> a -> m a

-- ('<<//=') :: ('MonadState' s m, 'Fractional' a) => 'Iso'' s a -> a -> m a

-- @

(<<//=) :: (MonadState s m, Fractional a) => LensLike' ((,) a) s a -> a -> m a
LensLike' ((,) a) s a
l <<//= :: forall s (m :: * -> *) a.
(MonadState s m, Fractional a) =>
LensLike' ((,) a) s a -> a -> m a
<<//= a
n = LensLike' ((,) a) s a
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \a
a -> (a
a, a
a forall a. Fractional a => a -> a -> a
/ a
n)
{-# INLINE (<<//=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by raising it by a non-negative power

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.^=') is more flexible.

--

-- @

-- ('<<^=') :: ('MonadState' s m, 'Num' a, 'Integral' e) => 'Lens'' s a -> e -> m a

-- ('<<^=') :: ('MonadState' s m, 'Num' a, 'Integral' e) => 'Iso'' s a -> a -> m a

-- @

(<<^=) :: (MonadState s m, Num a, Integral e) => LensLike' ((,) a) s a -> e -> m a
LensLike' ((,) a) s a
l <<^= :: forall s (m :: * -> *) a e.
(MonadState s m, Num a, Integral e) =>
LensLike' ((,) a) s a -> e -> m a
<<^= e
n = LensLike' ((,) a) s a
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \a
a -> (a
a, a
a forall a b. (Num a, Integral b) => a -> b -> a
^ e
n)
{-# INLINE (<<^=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by raising it by an integral power

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.^^=') is more flexible.

--

-- @

-- ('<<^^=') :: ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Lens'' s a -> e -> m a

-- ('<<^^=') :: ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Iso'' s a -> e -> m a

-- @

(<<^^=) :: (MonadState s m, Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> m a
LensLike' ((,) a) s a
l <<^^= :: forall s (m :: * -> *) a e.
(MonadState s m, Fractional a, Integral e) =>
LensLike' ((,) a) s a -> e -> m a
<<^^= e
n = LensLike' ((,) a) s a
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \a
a -> (a
a, a
a forall a b. (Fractional a, Integral b) => a -> b -> a
^^ e
n)
{-# INLINE (<<^^=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by raising it by an arbitrary power

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.**=') is more flexible.

--

-- @

-- ('<<**=') :: ('MonadState' s m, 'Floating' a) => 'Lens'' s a -> a -> m a

-- ('<<**=') :: ('MonadState' s m, 'Floating' a) => 'Iso'' s a -> a -> m a

-- @

(<<**=) :: (MonadState s m, Floating a) => LensLike' ((,) a) s a -> a -> m a
LensLike' ((,) a) s a
l <<**= :: forall s (m :: * -> *) a.
(MonadState s m, Floating a) =>
LensLike' ((,) a) s a -> a -> m a
<<**= a
n = LensLike' ((,) a) s a
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \a
a -> (a
a, a
a forall a. Floating a => a -> a -> a
** a
n)
{-# INLINE (<<**=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by taking its logical '||' with a value

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.||=') is more flexible.

--

-- @

-- ('<<||=') :: 'MonadState' s m => 'Lens'' s 'Bool' -> 'Bool' -> m 'Bool'

-- ('<<||=') :: 'MonadState' s m => 'Iso'' s 'Bool' -> 'Bool' -> m 'Bool'

-- @

(<<||=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
LensLike' ((,) Bool) s Bool
l <<||= :: forall s (m :: * -> *).
MonadState s m =>
LensLike' ((,) Bool) s Bool -> Bool -> m Bool
<<||= Bool
b = LensLike' ((,) Bool) s Bool
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \Bool
a -> (Bool
a, Bool
a Bool -> Bool -> Bool
|| Bool
b)
{-# INLINE (<<||=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by taking its logical '&&' with a value

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.&&=') is more flexible.

--

-- @

-- ('<<&&=') :: 'MonadState' s m => 'Lens'' s 'Bool' -> 'Bool' -> m 'Bool'

-- ('<<&&=') :: 'MonadState' s m => 'Iso'' s 'Bool' -> 'Bool' -> m 'Bool'

-- @

(<<&&=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
LensLike' ((,) Bool) s Bool
l <<&&= :: forall s (m :: * -> *).
MonadState s m =>
LensLike' ((,) Bool) s Bool -> Bool -> m Bool
<<&&= Bool
b = LensLike' ((,) Bool) s Bool
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \Bool
a -> (Bool
a, Bool
a Bool -> Bool -> Bool
&& Bool
b)
{-# INLINE (<<&&=) #-}

-- | Modify the target of a 'Lens' into your 'Monad''s state by using ('<>')

-- and return the /old/ value that was replaced.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.<>=') is more flexible.

--

-- @

-- ('<<<>=') :: ('MonadState' s m, 'Semigroup' r) => 'Lens'' s r -> r -> m r

-- ('<<<>=') :: ('MonadState' s m, 'Semigroup' r) => 'Iso'' s r -> r -> m r

-- @

(<<<>=) :: (MonadState s m, Semigroup r) => LensLike' ((,) r) s r -> r -> m r
LensLike' ((,) r) s r
l <<<>= :: forall s (m :: * -> *) r.
(MonadState s m, Semigroup r) =>
LensLike' ((,) r) s r -> r -> m r
<<<>= r
b = LensLike' ((,) r) s r
l forall {k} s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \r
a -> (r
a, r
a forall a. Semigroup a => a -> a -> a
<> r
b)
{-# INLINE (<<<>=) #-}

-- | Run a monadic action, and set the target of 'Lens' to its result.

--

-- @

-- ('<<~') :: 'MonadState' s m => 'Control.Lens.Iso.Iso' s s a b   -> m b -> m b

-- ('<<~') :: 'MonadState' s m => 'Lens' s s a b  -> m b -> m b

-- @

--

-- NB: This is limited to taking an actual 'Lens' than admitting a 'Control.Lens.Traversal.Traversal' because

-- there are potential loss of state issues otherwise.

(<<~) :: MonadState s m => ALens s s a b -> m b -> m b
ALens s s a b
l <<~ :: forall s (m :: * -> *) a b.
MonadState s m =>
ALens s s a b -> m b -> m b
<<~ m b
mb = do
  b
b <- m b
mb
  forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \s
s -> forall (w :: * -> * -> * -> *) c a t.
IndexedComonadStore w =>
c -> w a c t -> t
ipeek b
b (ALens s s a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s)
  forall (m :: * -> *) a. Monad m => a -> m a
return b
b
{-# INLINE (<<~) #-}

-- | ('<>') a 'Semigroup' value onto the end of the target of a 'Lens' and

-- return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.<>~') is more flexible.

(<<>~) :: Semigroup m => LensLike ((,)m) s t m m -> m -> s -> (m, t)
LensLike ((,) m) s t m m
l <<>~ :: forall m s t.
Semigroup m =>
LensLike ((,) m) s t m m -> m -> s -> (m, t)
<<>~ m
m = LensLike ((,) m) s t m m
l forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (forall a. Semigroup a => a -> a -> a
<> m
m)
{-# INLINE (<<>~) #-}

-- | ('<>') a 'Semigroup' value onto the end of the target of a 'Lens' into

-- your 'Monad''s state and return the result.

--

-- When you do not need the result of the operation, ('Control.Lens.Setter.<>=') is more flexible.

(<<>=) :: (MonadState s m, Semigroup r) => LensLike' ((,)r) s r -> r -> m r
LensLike' ((,) r) s r
l <<>= :: forall s (m :: * -> *) r.
(MonadState s m, Semigroup r) =>
LensLike' ((,) r) s r -> r -> m r
<<>= r
r = LensLike' ((,) r) s r
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (forall a. Semigroup a => a -> a -> a
<> r
r)
{-# INLINE (<<>=) #-}

------------------------------------------------------------------------------

-- Arrow operators

------------------------------------------------------------------------------


-- | 'Control.Lens.Setter.over' for Arrows.

--

-- Unlike 'Control.Lens.Setter.over', 'overA' can't accept a simple

-- 'Control.Lens.Setter.Setter', but requires a full lens, or close

-- enough.

--

-- >>> overA _1 ((+1) *** (+2)) ((1,2),6)

-- ((2,4),6)

--

-- @

-- overA :: Arrow ar => Lens s t a b -> ar a b -> ar s t

-- @

overA :: Arrow ar => LensLike (Context a b) s t a b -> ar a b -> ar s t
overA :: forall (ar :: * -> * -> *) a b s t.
Arrow ar =>
LensLike (Context a b) s t a b -> ar a b -> ar s t
overA LensLike (Context a b) s t a b
l ar a b
p = forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (\s
s -> let (Context b -> t
f a
a) = LensLike (Context a b) s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in (b -> t
f, a
a))
            forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ar a b
p
            forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. a -> a
id)

------------------------------------------------------------------------------

-- Indexed

------------------------------------------------------------------------------


-- | Adjust the target of an 'IndexedLens' returning the intermediate result, or

-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' and return a monoidal summary

-- along with the answer.

--

-- @

-- l '<%~' f ≡ l '<%@~' 'const' f

-- @

--

-- When you do not need access to the index then ('<%~') is more liberal in what it can accept.

--

-- If you do not need the intermediate result, you can use ('Control.Lens.Setter.%@~') or even ('Control.Lens.Setter.%~').

--

-- @

-- ('<%@~') ::             'IndexedLens' i s t a b      -> (i -> a -> b) -> s -> (b, t)

-- ('<%@~') :: 'Monoid' b => 'Control.Lens.Traversal.IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> (b, t)

-- @

(<%@~) :: Over (Indexed i) ((,) b) s t a b -> (i -> a -> b) -> s -> (b, t)
Over (Indexed i) ((,) b) s t a b
l <%@~ :: forall i b s t a.
Over (Indexed i) ((,) b) s t a b -> (i -> a -> b) -> s -> (b, t)
<%@~ i -> a -> b
f = Over (Indexed i) ((,) b) s t a b
l (forall i a b. (i -> a -> b) -> Indexed i a b
Indexed forall a b. (a -> b) -> a -> b
$ \i
i a
a -> let b :: b
b = i -> a -> b
f i
i a
a in (b
b, b
b))
{-# INLINE (<%@~) #-}

-- | Adjust the target of an 'IndexedLens' returning the old value, or

-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' and return a monoidal summary

-- of the old values along with the answer.

--

-- @

-- ('<<%@~') ::             'IndexedLens' i s t a b      -> (i -> a -> b) -> s -> (a, t)

-- ('<<%@~') :: 'Monoid' a => 'Control.Lens.Traversal.IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> (a, t)

-- @

(<<%@~) :: Over (Indexed i) ((,) a) s t a b -> (i -> a -> b) -> s -> (a, t)
Over (Indexed i) ((,) a) s t a b
l <<%@~ :: forall i a s t b.
Over (Indexed i) ((,) a) s t a b -> (i -> a -> b) -> s -> (a, t)
<<%@~ i -> a -> b
f = Over (Indexed i) ((,) a) s t a b
l forall a b. (a -> b) -> a -> b
$ forall i a b. (i -> a -> b) -> Indexed i a b
Indexed forall a b. (a -> b) -> a -> b
$ \i
i a
a -> forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (c, a) (c, b)
second' (i -> a -> b
f i
i) (a
a,a
a)

{-# INLINE (<<%@~) #-}

-- | Adjust the target of an 'IndexedLens' returning a supplementary result, or

-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' and return a monoidal summary

-- of the supplementary results and the answer.

--

-- @

-- ('%%@~') ≡ 'Control.Lens.Indexed.withIndex'

-- @

--

-- @

-- ('%%@~') :: 'Functor' f => 'IndexedLens' i s t a b      -> (i -> a -> f b) -> s -> f t

-- ('%%@~') :: 'Applicative' f => 'Control.Lens.Traversal.IndexedTraversal' i s t a b -> (i -> a -> f b) -> s -> f t

-- @

--

-- In particular, it is often useful to think of this function as having one of these even more

-- restricted type signatures:

--

-- @

-- ('%%@~') ::             'IndexedLens' i s t a b      -> (i -> a -> (r, b)) -> s -> (r, t)

-- ('%%@~') :: 'Monoid' r => 'Control.Lens.Traversal.IndexedTraversal' i s t a b -> (i -> a -> (r, b)) -> s -> (r, t)

-- @

(%%@~) :: Over (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t
%%@~ :: forall {k} i (f :: k -> *) s (t :: k) a (b :: k).
Over (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t
(%%@~) Over (Indexed i) f s t a b
l = Over (Indexed i) f s t a b
l forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall i a b. (i -> a -> b) -> Indexed i a b
Indexed
{-# INLINE (%%@~) #-}

-- | Adjust the target of an 'IndexedLens' returning a supplementary result, or

-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' within the current state, and

-- return a monoidal summary of the supplementary results.

--

-- @

-- l '%%@=' f ≡ 'state' (l '%%@~' f)

-- @

--

-- @

-- ('%%@=') :: 'MonadState' s m                 => 'IndexedLens' i s s a b      -> (i -> a -> (r, b)) -> s -> m r

-- ('%%@=') :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Traversal.IndexedTraversal' i s s a b -> (i -> a -> (r, b)) -> s -> m r

-- @

(%%@=) :: MonadState s m => Over (Indexed i) ((,) r) s s a b -> (i -> a -> (r, b)) -> m r
Over (Indexed i) ((,) r) s s a b
l %%@= :: forall s (m :: * -> *) i r a b.
MonadState s m =>
Over (Indexed i) ((,) r) s s a b -> (i -> a -> (r, b)) -> m r
%%@= i -> a -> (r, b)
f = forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
State.state (Over (Indexed i) ((,) r) s s a b
l forall {k} i (f :: k -> *) s (t :: k) a (b :: k).
Over (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t
%%@~ i -> a -> (r, b)
f)
{-# INLINE (%%@=) #-}

-- | Adjust the target of an 'IndexedLens' returning the intermediate result, or

-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' within the current state, and

-- return a monoidal summary of the intermediate results.

--

-- @

-- ('<%@=') :: 'MonadState' s m                 => 'IndexedLens' i s s a b      -> (i -> a -> b) -> m b

-- ('<%@=') :: ('MonadState' s m, 'Monoid' b) => 'Control.Lens.Traversal.IndexedTraversal' i s s a b -> (i -> a -> b) -> m b

-- @

(<%@=) :: MonadState s m => Over (Indexed i) ((,) b) s s a b -> (i -> a -> b) -> m b
Over (Indexed i) ((,) b) s s a b
l <%@= :: forall s (m :: * -> *) i b a.
MonadState s m =>
Over (Indexed i) ((,) b) s s a b -> (i -> a -> b) -> m b
<%@= i -> a -> b
f = Over (Indexed i) ((,) b) s s a b
l forall s (m :: * -> *) i r a b.
MonadState s m =>
Over (Indexed i) ((,) r) s s a b -> (i -> a -> (r, b)) -> m r
%%@= \ i
i a
a -> let b :: b
b = i -> a -> b
f i
i a
a in (b
b, b
b)
{-# INLINE (<%@=) #-}

-- | Adjust the target of an 'IndexedLens' returning the old value, or

-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' within the current state, and

-- return a monoidal summary of the old values.

--

-- @

-- ('<<%@=') :: 'MonadState' s m                 => 'IndexedLens' i s s a b      -> (i -> a -> b) -> m a

-- ('<<%@=') :: ('MonadState' s m, 'Monoid' b) => 'Control.Lens.Traversal.IndexedTraversal' i s s a b -> (i -> a -> b) -> m a

-- @

(<<%@=) :: MonadState s m => Over (Indexed i) ((,) a) s s a b -> (i -> a -> b) -> m a
Over (Indexed i) ((,) a) s s a b
l <<%@= :: forall s (m :: * -> *) i a b.
MonadState s m =>
Over (Indexed i) ((,) a) s s a b -> (i -> a -> b) -> m a
<<%@= i -> a -> b
f = forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
State.state (Over (Indexed i) ((,) a) s s a b
l (forall i a b. (i -> a -> b) -> Indexed i a b
Indexed forall a b. (a -> b) -> a -> b
$ \ i
i a
a -> (a
a, i -> a -> b
f i
i a
a)))
{-# INLINE (<<%@=) #-}

------------------------------------------------------------------------------

-- ALens Combinators

------------------------------------------------------------------------------


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

--

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

-- "world"

(^#) :: s -> ALens s t a b -> a
s
s ^# :: forall s t a b. s -> ALens s t a b -> a
^# ALens s t a b
l = forall (w :: * -> * -> * -> *) a c t.
IndexedComonadStore w =>
w a c t -> a
ipos (ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s)
{-# INLINE (^#) #-}

-- | A version of 'Control.Lens.Setter.set' that works on 'ALens'.

--

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

-- ("hello","world")

storing :: ALens s t a b -> b -> s -> t
storing :: forall s t a b. ALens s t a b -> b -> s -> t
storing ALens s t a b
l b
b s
s = forall (w :: * -> * -> * -> *) c a t.
IndexedComonadStore w =>
c -> w a c t -> t
ipeek b
b (ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s)
{-# INLINE storing #-}

-- | A version of ('Control.Lens.Setter..~') that works on 'ALens'.

--

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

-- ("hello","world")

(#~) :: ALens s t a b -> b -> s -> t
#~ :: forall s t a b. ALens s t a b -> b -> s -> t
(#~) ALens s t a b
l b
b s
s = forall (w :: * -> * -> * -> *) c a t.
IndexedComonadStore w =>
c -> w a c t -> t
ipeek b
b (ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s)
{-# INLINE (#~) #-}

-- | A version of ('Control.Lens.Setter.%~') that works on 'ALens'.

--

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

-- ("hello",5)

(#%~) :: ALens s t a b -> (a -> b) -> s -> t
#%~ :: forall s t a b. ALens s t a b -> (a -> b) -> s -> t
(#%~) ALens s t a b
l a -> b
f s
s = forall (w :: * -> * -> * -> *) a c t.
IndexedComonadStore w =>
(a -> c) -> w a c t -> t
ipeeks a -> b
f (ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s)
{-# INLINE (#%~) #-}

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

--

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

-- (5,("hello","world!"))

(#%%~) :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t
#%%~ :: forall (f :: * -> *) s t a b.
Functor f =>
ALens s t a b -> (a -> f b) -> s -> f t
(#%%~) ALens s t a b
l a -> f b
f s
s = forall (p :: * -> * -> *) a b t.
Pretext p a b t
-> forall (f :: * -> *). Functor f => p a (f b) -> f t
runPretext (ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s) a -> f b
f
{-# INLINE (#%%~) #-}

-- | A version of ('Control.Lens.Setter..=') that works on 'ALens'.

(#=) :: MonadState s m => ALens s s a b -> b -> m ()
ALens s s a b
l #= :: forall s (m :: * -> *) a b.
MonadState s m =>
ALens s s a b -> b -> m ()
#= b
f = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (ALens s s a b
l forall s t a b. ALens s t a b -> b -> s -> t
#~ b
f)
{-# INLINE (#=) #-}

-- | A version of ('Control.Lens.Setter.%=') that works on 'ALens'.

(#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m ()
ALens s s a b
l #%= :: forall s (m :: * -> *) a b.
MonadState s m =>
ALens s s a b -> (a -> b) -> m ()
#%= a -> b
f = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (ALens s s a b
l forall s t a b. ALens s t a b -> (a -> b) -> s -> t
#%~ a -> b
f)
{-# INLINE (#%=) #-}

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

--

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

-- (5,("hello",5))

(<#%~) :: ALens s t a b -> (a -> b) -> s -> (b, t)
ALens s t a b
l <#%~ :: forall s t a b. ALens s t a b -> (a -> b) -> s -> (b, t)
<#%~ a -> b
f = \s
s -> forall (p :: * -> * -> *) a b t.
Pretext p a b t
-> forall (f :: * -> *). Functor f => p a (f b) -> f t
runPretext (ALens s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s) forall a b. (a -> b) -> a -> b
$ \a
a -> let b :: b
b = a -> b
f a
a in (b
b, b
b)
{-# INLINE (<#%~) #-}

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

(<#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m b
ALens s s a b
l <#%= :: forall s (m :: * -> *) a b.
MonadState s m =>
ALens s s a b -> (a -> b) -> m b
<#%= a -> b
f = ALens s s a b
l forall s (m :: * -> *) a b r.
MonadState s m =>
ALens s s a b -> (a -> (r, b)) -> m r
#%%= \a
a -> let b :: b
b = a -> b
f a
a in (b
b, b
b)
{-# INLINE (<#%=) #-}

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

(#%%=) :: MonadState s m => ALens s s a b -> (a -> (r, b)) -> m r
ALens s s a b
l #%%= :: forall s (m :: * -> *) a b r.
MonadState s m =>
ALens s s a b -> (a -> (r, b)) -> m r
#%%= a -> (r, b)
f = forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
State.state forall a b. (a -> b) -> a -> b
$ \s
s -> forall (p :: * -> * -> *) a b t.
Pretext p a b t
-> forall (f :: * -> *). Functor f => p a (f b) -> f t
runPretext (ALens s s a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s) a -> (r, b)
f
{-# INLINE (#%%=) #-}

-- | A version of ('Control.Lens.Setter.<.~') that works on 'ALens'.

--

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

-- ("world",("hello","world"))

(<#~) :: ALens s t a b -> b -> s -> (b, t)
ALens s t a b
l <#~ :: forall s t a b. ALens s t a b -> b -> s -> (b, t)
<#~ b
b = \s
s -> (b
b, forall s t a b. ALens s t a b -> b -> s -> t
storing ALens s t a b
l b
b s
s)
{-# INLINE (<#~) #-}

-- | A version of ('Control.Lens.Setter.<.=') that works on 'ALens'.

(<#=) :: MonadState s m => ALens s s a b -> b -> m b
ALens s s a b
l <#= :: forall s (m :: * -> *) a b.
MonadState s m =>
ALens s s a b -> b -> m b
<#= b
b = do
  ALens s s a b
l forall s (m :: * -> *) a b.
MonadState s m =>
ALens s s a b -> b -> m ()
#= b
b
  forall (m :: * -> *) a. Monad m => a -> m a
return b
b
{-# INLINE (<#=) #-}

-- | There is a field for every type in the 'Void'. Very zen.

--

-- >>> [] & mapped.devoid +~ 1

-- []

--

-- >>> Nothing & mapped.devoid %~ abs

-- Nothing

--

-- @

-- 'devoid' :: 'Lens'' 'Void' a

-- @

devoid :: Over p f Void Void a b
devoid :: forall {k} (p :: k -> * -> *) (f :: * -> *) (a :: k) b.
Over p f Void Void a b
devoid p a (f b)
_ = forall a. Void -> a
absurd
{-# INLINE devoid #-}

-- | We can always retrieve a @()@ from any type.

--

-- >>> "hello"^.united

-- ()

--

-- >>> "hello" & united .~ ()

-- "hello"

united :: Lens' a ()
united :: forall a. Lens' a ()
united () -> f ()
f a
v = () -> f ()
f () forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \ () -> a
v
{-# INLINE united #-}

data First1 f a = First1 (f a) a

instance (Functor f) => Functor (First1 f) where
  fmap :: forall a b. (a -> b) -> First1 f a -> First1 f b
fmap a -> b
f (First1 f a
fa a
a) = forall (f :: * -> *) a. f a -> a -> First1 f a
First1 (a -> b
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
fa) (a -> b
f a
a)
  {-# INLINE fmap #-}

instance (Functor f) => Apply (First1 f) where
  First1 f (a -> b)
ff a -> b
f <.> :: forall a b. First1 f (a -> b) -> First1 f a -> First1 f b
<.> First1 f a
_ a
x = forall (f :: * -> *) a. f a -> a -> First1 f a
First1 ((forall a b. (a -> b) -> a -> b
$ a
x) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (a -> b)
ff) (a -> b
f a
x)
  {-# INLINE (<.>) #-}

getFirst1 :: First1 f a -> f a
getFirst1 :: forall (f :: * -> *) a. First1 f a -> f a
getFirst1 (First1 f a
fa a
_) = f a
fa
{-# INLINE getFirst1 #-}

-- | A 'Lens' focusing on the first element of a 'Traversable1' container.

--

-- >>> 2 :| [3, 4] & head1 +~ 10

-- 12 :| [3,4]

--

-- >>> Identity True ^. head1

-- True

head1 :: (Traversable1 t) => Lens' (t a) a
head1 :: forall (t :: * -> *) a. Traversable1 t => Lens' (t a) a
head1 a -> f a
f = forall (f :: * -> *) a. First1 f a -> f a
getFirst1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 (\a
a -> forall (f :: * -> *) a. f a -> a -> First1 f a
First1 (a -> f a
f a
a) a
a)
{-# INLINE head1 #-}

-- | A 'Lens' focusing on the last element of a 'Traversable1' container.

--

-- >>> 2 :| [3, 4] & last1 +~ 10

-- 2 :| [3,14]

--

-- >>> Node 'a' [Node 'b' [], Node 'c' []] ^. last1

-- 'c'

last1 :: (Traversable1 t) => Lens' (t a) a
last1 :: forall (t :: * -> *) a. Traversable1 t => Lens' (t a) a
last1 a -> f a
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} (f :: k -> *) (a :: k). Reverse f a -> f a
getReverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Traversable1 t => Lens' (t a) a
head1 a -> f a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). f a -> Reverse f a
Reverse
{-# INLINE last1 #-}

-- | Fuse a composition of lenses using 'Yoneda' to provide 'fmap' fusion.

--

-- In general, given a pair of lenses 'foo' and 'bar'

--

-- @

-- fusing (foo.bar) = foo.bar

-- @

--

-- however, @foo@ and @bar@ are either going to 'fmap' internally or they are trivial.

--

-- 'fusing' exploits the 'Yoneda' lemma to merge these separate uses into a single 'fmap'.

--

-- This is particularly effective when the choice of functor 'f' is unknown at compile

-- time or when the 'Lens' @foo.bar@ in the above description is recursive or complex

-- enough to prevent inlining.

--

-- @

-- 'fusing' :: 'Lens' s t a b -> 'Lens' s t a b

-- @

fusing :: Functor f => LensLike (Yoneda f) s t a b -> LensLike f s t a b
fusing :: forall (f :: * -> *) s t a b.
Functor f =>
LensLike (Yoneda f) s t a b -> LensLike f s t a b
fusing LensLike (Yoneda f) s t a b
t = \a -> f b
f -> forall (f :: * -> *) a. Yoneda f a -> f a
lowerYoneda forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike (Yoneda f) s t a b
t (forall (f :: * -> *) a. Functor f => f a -> Yoneda f a
liftYoneda forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f)
{-# INLINE fusing #-}