-- | This module contains lenses, prisms, grids, grates and traversals for common structures in Haskell.
-- It also contains the combinators for various kinds of optics.
--
-- A Function name with @'@ is a grate variant of a grid, and a function name with @_@ is a traversal variants of a grid or prism.
-- For example, 'both'' is the grate variant of 'both' while 'both_' is the traversal variant.
module Lens.Family.Stock (
-- * Stock Lenses
    _1, _2
  , chosen
  , ix
  , at, intAt
  , at', intAt'
  , contains, intContains
-- * Stock Prisms
  , left, right
  , just, nothing
-- * Stock Grids
  , both
  , bend, lend
-- * Stock Grates
  , cod
  , both'
  , bend', lend'
-- * Stock Traversals
  , both_
  , bend_, lend_
  , left_, right_
  , just_, nothing_
  , ignored
-- * Stock SECs
  , mapped
-- * Lens Combinators
  , alongside
  , backwards
  , beside, beside', beside_
  , choosing
  , from
-- * Types
  , AlongsideLeft, AlongsideRight
  , FromF, FromG
-- * Re-exports
  , AdapterLike, AdapterLike'
  , LensLike, LensLike'
  , GrateLike, GrateLike'
  , Identical, Backwards
  , FiniteBits
-- * Deprecated names
  , lft, rgt
  , some, none
  , lft_, rgt_
  , some_, none_
  ) where

import Control.Arrow (first, second)
import Control.Applicative.Backwards (Backwards(..))
import Control.Applicative (liftA2)
import Data.Bits (FiniteBits, (.|.), bit, finiteBitSize, testBit, zeroBits)
import qualified Data.IntMap as IntMap
import qualified Data.IntMap.Strict as IntMap'
import qualified Data.IntSet as IntSet
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map'
import Data.Proxy (asProxyTypeOf)
import qualified Data.Set as Set
import Lens.Family
import Lens.Family.Phantom
import Lens.Family.Unchecked

choosing :: Functor f => LensLike f s0 t0 a b -> LensLike f s1 t1 a b -> LensLike f (Either s0 s1) (Either t0 t1) a b
-- ^ @
-- choosing :: Lens s0 t0 a b -> Lens s1 t1 a b -> Lens (Either s0 s1) (Either t0 t1) a b
-- @
--
-- @
-- choosing :: Traversal s0 t0 a b -> Traversal s1 t1 a b -> Traversal (Either s0 s1) (Either t0 t1) a b
-- @
--
-- @
-- choosing :: Getter s0 t0 a b -> Getter s1 t1 a b -> Getter (Either s0 s1) (Either t0 t1) a b
-- @
--
-- @
-- choosing :: Fold s0 t0 a b -> Fold s1 t1 a b -> Fold (Either s0 s1) (Either t0 t1) a b
-- @
--
-- @
-- choosing :: Setter s0 t0 a b -> Setter s1 t1 a b -> Setter (Either s0 s1) (Either t0 t1) a b
-- @
--
-- Given two lens\/traversal\/getter\/fold\/setter families with the same substructure, make a new lens\/traversal\/getter\/fold\/setter on 'Either'.
choosing :: forall (f :: * -> *) s0 t0 a b s1 t1.
Functor f =>
LensLike f s0 t0 a b
-> LensLike f s1 t1 a b
-> LensLike f (Either s0 s1) (Either t0 t1) a b
choosing LensLike f s0 t0 a b
la LensLike f s1 t1 a b
_  a -> f b
f (Left s0
a)  = forall a b. a -> Either a b
Left  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LensLike f s0 t0 a b
la a -> f b
f s0
a
choosing LensLike f s0 t0 a b
_  LensLike f s1 t1 a b
lb a -> f b
f (Right s1
b) = forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LensLike f s1 t1 a b
lb a -> f b
f s1
b

_1 :: Functor f => LensLike f (a, r) (b, r) a b
-- ^ @
-- _1 :: Lens (a, r) (b, r) a b
-- @
--
-- Lens on the first element of a pair.
_1 :: forall (f :: * -> *) a r b.
Functor f =>
LensLike f (a, r) (b, r) a b
_1 a -> f b
f (a
a, r
r) = (\b
b -> (b
b, r
r)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a

_2 :: Functor f => LensLike f (r, a) (r, b) a b
-- ^ @
-- _2 :: Lens (r, a) (r, b) a b
-- @
--
-- Lens on the second element of a pair.
_2 :: forall (f :: * -> *) r a b.
Functor f =>
LensLike f (r, a) (r, b) a b
_2 a -> f b
f (r
r, a
a) = (\b
b -> (r
r, b
b)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a

chosen :: Functor f => LensLike f (Either a a) (Either b b) a b
-- ^ @
-- chosen :: Lens (Either a a) (Either b b) a b
-- @
--
-- Lens on the Left or Right element of an ('Either' a a).
chosen :: forall (f :: * -> *) a b.
Functor f =>
LensLike f (Either a a) (Either b b) a b
chosen = forall (f :: * -> *) s0 t0 a b s1 t1.
Functor f =>
LensLike f s0 t0 a b
-> LensLike f s1 t1 a b
-> LensLike f (Either s0 s1) (Either t0 t1) a b
choosing forall a. a -> a
id forall a. a -> a
id

ix :: (Eq k, Functor f) => k -> LensLike' f (k -> v) v
-- ^ @
-- ix :: Eq k => k -> Lens' (k -> v) v
-- @
--
-- Lens on a given point of a function.
ix :: forall k (f :: * -> *) v.
(Eq k, Functor f) =>
k -> LensLike' f (k -> v) v
ix k
k v -> f v
f k -> v
g = (\v
v' k
x -> if (k
k forall a. Eq a => a -> a -> Bool
== k
x) then v
v' else k -> v
g k
x) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> v -> f v
f (k -> v
g k
k)

at :: (Ord k, Functor f) => k -> LensLike' f (Map.Map k v) (Maybe v)
-- ^ @
-- at :: Ord k => k -> Lens' (Map.Map k v) (Maybe v)
-- @
--
-- Lens on a given point of a 'Map.Map'.
at :: forall k (f :: * -> *) v.
(Ord k, Functor f) =>
k -> LensLike' f (Map k v) (Maybe v)
at = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (f :: * -> *) k a.
(Functor f, Ord k) =>
(Maybe a -> f (Maybe a)) -> k -> Map k a -> f (Map k a)
Map.alterF

intAt :: Functor f => Int -> LensLike' f (IntMap.IntMap v) (Maybe v)
-- ^ @
-- intAt :: Int -> Lens (IntMap.IntMap v) (Maybe v)
-- @
--
-- Lens on a given point of a 'IntMap.IntMap'.
intAt :: forall (f :: * -> *) v.
Functor f =>
Int -> LensLike' f (IntMap v) (Maybe v)
intAt = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (f :: * -> *) a.
Functor f =>
(Maybe a -> f (Maybe a)) -> Int -> IntMap a -> f (IntMap a)
IntMap.alterF

at' :: (Ord k, Functor f) => k -> LensLike' f (Map.Map k v) (Maybe v)
-- ^ @
-- at :: Ord k => k -> Lens' (Map.Map k v) (Maybe v)
-- @
--
-- Lens providing strict access to a given point of a 'Map.Map'.
at' :: forall k (f :: * -> *) v.
(Ord k, Functor f) =>
k -> LensLike' f (Map k v) (Maybe v)
at' = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (f :: * -> *) k a.
(Functor f, Ord k) =>
(Maybe a -> f (Maybe a)) -> k -> Map k a -> f (Map k a)
Map'.alterF

intAt' :: Functor f => Int -> LensLike' f (IntMap.IntMap v) (Maybe v)
-- ^ @
-- intAt :: Int -> Lens (IntMap.IntMap v) (Maybe v)
-- @
--
-- Lens providing strict access to a given point of a 'IntMap.IntMap'.
intAt' :: forall (f :: * -> *) v.
Functor f =>
Int -> LensLike' f (IntMap v) (Maybe v)
intAt' = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (f :: * -> *) a.
Functor f =>
(Maybe a -> f (Maybe a)) -> Int -> IntMap a -> f (IntMap a)
IntMap'.alterF

contains :: (Ord k, Functor f) => k -> LensLike' f (Set.Set k) Bool
-- ^ @
-- contains :: Ord => k -> Lens' (Set.Set k) Bool
-- @
--
-- Lens on a given point of a 'Set.Set'.
contains :: forall k (f :: * -> *).
(Ord k, Functor f) =>
k -> LensLike' f (Set k) Bool
contains k
k = forall (f :: * -> *) s a b t.
Functor f =>
(s -> a) -> (s -> b -> t) -> LensLike f s t a b
lens (forall a. Ord a => a -> Set a -> Bool
Set.member k
k) (\Set k
m Bool
nv -> if Bool
nv then forall a. Ord a => a -> Set a -> Set a
Set.insert k
k Set k
m else forall a. Ord a => a -> Set a -> Set a
Set.delete k
k Set k
m)

intContains :: Functor f => Int -> LensLike' f IntSet.IntSet Bool
-- ^ @
-- intContains :: Int -> Lens' IntSet.IntSet Bool
-- @
--
-- Lens on a given point of a 'IntSet.IntSet'.
intContains :: forall (f :: * -> *). Functor f => Int -> LensLike' f IntSet Bool
intContains Int
k = forall (f :: * -> *) s a b t.
Functor f =>
(s -> a) -> (s -> b -> t) -> LensLike f s t a b
lens (Int -> IntSet -> Bool
IntSet.member Int
k) (\IntSet
m Bool
nv -> if Bool
nv then Int -> IntSet -> IntSet
IntSet.insert Int
k IntSet
m else Int -> IntSet -> IntSet
IntSet.delete Int
k IntSet
m)

cod :: Functor g => GrateLike g (r -> a) (r -> b) a b
-- ^ @
-- cod :: Grate (r -> a) (r -> b) a b
-- @
--
-- A grate accessing the codomain of a function.
cod :: forall (g :: * -> *) r a b.
Functor g =>
GrateLike g (r -> a) (r -> b) a b
cod g a -> b
f g (r -> a)
h r
r = g a -> b
f forall a b. (a -> b) -> a -> b
$ (forall a b. (a -> b) -> a -> b
$ r
r) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g (r -> a)
h

left :: (Applicative f, Traversable g) => AdapterLike f g (Either a r) (Either b r) a b
-- ^ @
-- left :: Prism (Either a r) (Either b r) a b
-- @
--
-- A prism on the 'Left' element of an 'Either'.
left :: forall (f :: * -> *) (g :: * -> *) a r b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either a r) (Either b r) a b
left g a -> f b
f = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> Either a b
Right) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. a -> Either a b
Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. g a -> f b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall {a} {a}. Either a a -> Either a a
switch
 where
  switch :: Either a a -> Either a a
switch = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a b. b -> Either a b
Right forall a b. a -> Either a b
Left

left_ :: Applicative f => LensLike f (Either a r) (Either b r) a b
-- ^ @
-- left_ :: Traversal (Either a r) (Either b r) a b
-- @
--
-- Traversal on the 'Left' element of an 'Either'.
--
-- @
-- left_ = under left
-- @
left_ :: forall (f :: * -> *) a r b.
Applicative f =>
LensLike f (Either a r) (Either b r) a b
left_ = forall s t a b. AResetter s t a b -> (a -> b) -> s -> t
under forall (f :: * -> *) (g :: * -> *) a r b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either a r) (Either b r) a b
left

right :: (Applicative f, Traversable g) => AdapterLike f g (Either r a) (Either r b) a b
-- ^ @
-- right :: Prism (Either r a) (Either r b) a b
-- @
--
-- A prism on the 'Right' element of an 'Either'.
right :: forall (f :: * -> *) (g :: * -> *) r a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either r a) (Either r b) a b
right g a -> f b
f = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. g a -> f b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA

right_ :: Applicative f => LensLike f (Either r a) (Either r b) a b
-- ^ @
-- right_ :: Traversal (Either r a) (Either r b) a b
-- @
--
-- Traversal on the 'Right' element of an 'Either'.
--
-- @
-- right_ = under right
-- @
right_ :: forall (f :: * -> *) r a b.
Applicative f =>
LensLike f (Either r a) (Either r b) a b
right_ = forall s t a b. AResetter s t a b -> (a -> b) -> s -> t
under forall (f :: * -> *) (g :: * -> *) r a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either r a) (Either r b) a b
right

just :: (Applicative f, Traversable g) => AdapterLike f g (Maybe a) (Maybe b) a b
-- ^ @
-- just :: Prism (Maybe a) (Maybe b) a b
-- @
--
-- A prism on the 'Just' element of a 'Maybe'.
just :: forall (f :: * -> *) (g :: * -> *) a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Maybe a) (Maybe b) a b
just g a -> f b
f = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. g a -> f b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA

just_ :: Applicative f => LensLike f (Maybe a) (Maybe b) a b
-- ^ @
-- just_ :: Traversal (Maybe a) (Maybe b) a b
-- @
--
-- Traversal on the 'Just' element of a 'Maybe'.
just_ :: forall (f :: * -> *) a b.
Applicative f =>
LensLike f (Maybe a) (Maybe b) a b
just_ = forall s t a b. AResetter s t a b -> (a -> b) -> s -> t
under forall (f :: * -> *) (g :: * -> *) a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Maybe a) (Maybe b) a b
just

nothing :: (Applicative f, Traversable g) => AdapterLike' f g (Maybe a) ()
-- ^ @
-- nothing :: Prism' (Maybe a) ()
-- @
--
-- A prism on the 'Nothing' element of a 'Maybe'.
nothing :: forall (f :: * -> *) (g :: * -> *) a.
(Applicative f, Traversable g) =>
AdapterLike' f g (Maybe a) ()
nothing = forall (f :: * -> *) (g :: * -> *) s t a b.
(Applicative f, Traversable g) =>
(s -> Either t a) -> (b -> t) -> AdapterLike f g s t a b
prism (forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. b -> Either a b
Right ()) (forall a b. a -> Either a b
Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just)) (forall a b. a -> b -> a
const forall a. Maybe a
Nothing)

nothing_ :: Applicative f => LensLike' f (Maybe a) ()
-- ^ @
-- nothing_ :: Traversal' (Maybe a) ()
-- @
--
-- Traversal on the 'Nothing' element of a 'Maybe'.
nothing_ :: forall (f :: * -> *) a. Applicative f => LensLike' f (Maybe a) ()
nothing_ = forall s t a b. AResetter s t a b -> (a -> b) -> s -> t
under forall (f :: * -> *) (g :: * -> *) a.
(Applicative f, Traversable g) =>
AdapterLike' f g (Maybe a) ()
nothing

both :: (Applicative f, Functor g) => AdapterLike f g (a,a) (b,b) a b
-- ^ @
-- both :: Grid (a,a) (b,b) a b
-- @
--
-- A grid on both elements of a pair @(a,a)@.
both :: forall (f :: * -> *) (g :: * -> *) a b.
(Applicative f, Functor g) =>
AdapterLike f g (a, a) (b, b) a b
both = forall (f :: * -> *) (g :: * -> *) s0 t0 a b s1 t1.
(Applicative f, Functor g) =>
AdapterLike f g s0 t0 a b
-> AdapterLike f g s1 t1 a b
-> AdapterLike f g (s0, s1) (t0, t1) a b
beside forall a. a -> a
id forall a. a -> a
id

both' :: Functor g => GrateLike g (a,a) (b,b) a b
-- ^ @
-- both' :: Grate (a,a) (b,b) a b
-- @
--
-- A grate on both elements of a pair @(a,a)@.
--
-- @
-- both' = over both
-- @
both' :: forall (g :: * -> *) a b.
Functor g =>
GrateLike g (a, a) (b, b) a b
both' = forall (g :: * -> *) s0 t0 a b s1 t1.
Functor g =>
GrateLike g s0 t0 a b
-> GrateLike g s1 t1 a b -> GrateLike g (s0, s1) (t0, t1) a b
beside' forall a. a -> a
id forall a. a -> a
id

both_ :: Applicative f => LensLike f (a,a) (b,b) a b
-- ^ @
-- both_ :: Traversal (a,a) (b,b) a b
-- @
--
-- Traversals on both elements of a pair @(a,a)@.
--
-- @
-- both_ = under both
-- @
both_ :: forall (f :: * -> *) a b.
Applicative f =>
LensLike f (a, a) (b, b) a b
both_ = forall (f :: * -> *) s0 t0 a b s1 t1.
Applicative f =>
LensLike f s0 t0 a b
-> LensLike f s1 t1 a b -> LensLike f (s0, s1) (t0, t1) a b
beside_ forall a. a -> a
id forall a. a -> a
id

lend :: (FiniteBits b, Applicative f, Functor g) => AdapterLike' f g b Bool
-- ^ @
-- lend :: FiniteBits b => Grid' b Bool
-- @
--
-- A grid from the least significant bit to the most significant bit of a 'FiniteBits' type.
--
-- Little endian order.
lend :: forall b (f :: * -> *) (g :: * -> *).
(FiniteBits b, Applicative f, Functor g) =>
AdapterLike' f g b Bool
lend g Bool -> f Bool
f g b
s = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Bits a => a -> a -> a
(.|.)) (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Bits a => a
zeroBits) [forall {a}. Bits a => Int -> Bool -> a
mask Int
i forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g Bool -> f Bool
f (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Bits a => a -> Int -> Bool
testBit Int
i forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g b
s) | Int
i <- [Int
0..forall b. FiniteBits b => b -> Int
finiteBitSize b
bforall a. Num a => a -> a -> a
-Int
1]]
 where
  mask :: Int -> Bool -> a
mask Int
i Bool
True = forall a. Bits a => Int -> a
bit Int
i
  mask Int
_ Bool
False = forall a. Bits a => a
zeroBits
  b :: b
b = b
b forall a (proxy :: * -> *). a -> proxy a -> a
`asProxyTypeOf` g b
s

lend' :: (FiniteBits b, Functor g) => GrateLike' g b Bool
-- ^ @
-- lend' :: FiniteBits b => Grate' b Bool
-- @
--
-- A grate from the least significant bit to the most significant bit of a 'FiniteBits' type.
--
-- Little endian order.
--
-- @
-- lend' = over lend
-- @
lend' :: forall b (g :: * -> *).
(FiniteBits b, Functor g) =>
GrateLike' g b Bool
lend' = forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over forall b (f :: * -> *) (g :: * -> *).
(FiniteBits b, Applicative f, Functor g) =>
AdapterLike' f g b Bool
lend

lend_ :: (FiniteBits b, Applicative f) => LensLike' f b Bool
-- ^ @
-- lend_ :: FiniteBits b => Traversal' b Bool
-- @
--
-- A traversal from the least significant bit to the most significant bit of a 'FiniteBits' type.
--
-- Little endian order.
--
-- @
-- lend_ = under lend
-- @
lend_ :: forall b (f :: * -> *).
(FiniteBits b, Applicative f) =>
LensLike' f b Bool
lend_ = forall s t a b. AResetter s t a b -> (a -> b) -> s -> t
under forall b (f :: * -> *) (g :: * -> *).
(FiniteBits b, Applicative f, Functor g) =>
AdapterLike' f g b Bool
lend

bend :: (FiniteBits b, Applicative f, Functor g) => AdapterLike' f g b Bool
-- ^ @
-- bend :: FiniteBits b => Grid' b Bool
-- @
--
-- A grid from the most significant bit to the least significant bit of a 'FiniteBits' type.
--
-- Big endian order.
bend :: forall b (f :: * -> *) (g :: * -> *).
(FiniteBits b, Applicative f, Functor g) =>
AdapterLike' f g b Bool
bend = forall (f :: * -> *) s t a b.
LensLike (Backwards f) s t a b -> LensLike f s t a b
backwards forall b (f :: * -> *) (g :: * -> *).
(FiniteBits b, Applicative f, Functor g) =>
AdapterLike' f g b Bool
lend

bend' :: (FiniteBits b, Functor g) => GrateLike' g b Bool
-- ^ @
-- bend' :: FiniteBits b => Grate' b Bool
-- @
--
-- A grate from the most significant bit to the least significant bit of a 'FiniteBits' type.
--
-- Big endian order.
--
-- @
-- bend' = over bend
-- @
bend' :: forall b (g :: * -> *).
(FiniteBits b, Functor g) =>
GrateLike' g b Bool
bend' = forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over forall b (f :: * -> *) (g :: * -> *).
(FiniteBits b, Applicative f, Functor g) =>
AdapterLike' f g b Bool
bend

bend_ :: (FiniteBits b, Applicative f) => LensLike' f b Bool
-- ^ @
-- bend_ :: FiniteBits b => Traversal' b Bool
-- @
--
-- A traversal from the most significant bit to the least significant bit of a 'FiniteBits' type.
--
-- Big endian order.
--
-- @
-- bend_ = under bend
-- @
bend_ :: forall b (f :: * -> *).
(FiniteBits b, Applicative f) =>
LensLike' f b Bool
bend_ = forall s t a b. AResetter s t a b -> (a -> b) -> s -> t
under forall b (f :: * -> *) (g :: * -> *).
(FiniteBits b, Applicative f, Functor g) =>
AdapterLike' f g b Bool
bend

beside :: (Applicative f, Functor g) => AdapterLike f g s0 t0 a b -> AdapterLike f g s1 t1 a b -> AdapterLike f g (s0, s1) (t0, t1) a b
-- ^ @
-- beside :: Grid s1 t1 a b -> Grid s2 t2 a b -> Grid (s1, s2) (t1, t2) a b
-- @
--
-- Given two grids referencing a type 'c', create a grid on the pair referencing 'c'.
beside :: forall (f :: * -> *) (g :: * -> *) s0 t0 a b s1 t1.
(Applicative f, Functor g) =>
AdapterLike f g s0 t0 a b
-> AdapterLike f g s1 t1 a b
-> AdapterLike f g (s0, s1) (t0, t1) a b
beside AdapterLike f g s0 t0 a b
la AdapterLike f g s1 t1 a b
lb g a -> f b
f g (s0, s1)
s = (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AdapterLike f g s0 t0 a b
la g a -> f b
f (forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g (s0, s1)
s) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AdapterLike f g s1 t1 a b
lb g a -> f b
f (forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g (s0, s1)
s)

beside' :: Functor g => GrateLike g s0 t0 a b -> GrateLike g s1 t1 a b -> GrateLike g (s0, s1) (t0, t1) a b
-- ^ @
-- beside' :: Grate s0 t0 a b -> Grate s1 t1 a b -> Grate (s0, s1) (t0, t1) a b
-- @
--
-- @
-- beside' :: Resetter s0 t0 a b -> Resetter s1 t1 a b -> Resetter (s0, s1) (t0, t1) a b
-- @
--
-- Given two grates\/resetters referencing a type 'c', create a grate\/resetter on the pair referencing 'c'.
beside' :: forall (g :: * -> *) s0 t0 a b s1 t1.
Functor g =>
GrateLike g s0 t0 a b
-> GrateLike g s1 t1 a b -> GrateLike g (s0, s1) (t0, t1) a b
beside' GrateLike g s0 t0 a b
la GrateLike g s1 t1 a b
lb = forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) (g :: * -> *) s0 t0 a b s1 t1.
(Applicative f, Functor g) =>
AdapterLike f g s0 t0 a b
-> AdapterLike f g s1 t1 a b
-> AdapterLike f g (s0, s1) (t0, t1) a b
beside (forall (f :: * -> *) a b s t.
Identical f =>
((a -> b) -> s -> t) -> LensLike f s t a b
setting GrateLike g s0 t0 a b
la) (forall (f :: * -> *) a b s t.
Identical f =>
((a -> b) -> s -> t) -> LensLike f s t a b
setting GrateLike g s1 t1 a b
lb)

beside_ :: Applicative f => LensLike f s0 t0 a b -> LensLike f s1 t1 a b -> LensLike f (s0, s1) (t0, t1) a b
-- ^ @
-- beside_ :: Traversal s0 t0 a b -> Traversal s1 t1 a b -> Traversal (s0, s1) (t0, t1) a b
-- @
--
-- @
-- beside_ :: Fold s0 t0 a b -> Fold s1 t1 a b -> Fold (s0, s1) (t0, t1) a b
-- @
--
-- @
-- beside_ :: Setter s0 t0 a b -> Setter s1 t1 a b -> Setter (s0, s1) (t0, t1) a b
-- @
--
-- Given two traversals\/folds\/setters referencing a type 'c', create a traversal\/fold\/setter on the pair referencing 'c'.
beside_ :: forall (f :: * -> *) s0 t0 a b s1 t1.
Applicative f =>
LensLike f s0 t0 a b
-> LensLike f s1 t1 a b -> LensLike f (s0, s1) (t0, t1) a b
beside_ LensLike f s0 t0 a b
la LensLike f s1 t1 a b
lb = forall s t a b. AResetter s t a b -> (a -> b) -> s -> t
under forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) (g :: * -> *) s0 t0 a b s1 t1.
(Applicative f, Functor g) =>
AdapterLike f g s0 t0 a b
-> AdapterLike f g s1 t1 a b
-> AdapterLike f g (s0, s1) (t0, t1) a b
beside (forall (g :: * -> *) a b s t.
Identical g =>
((a -> b) -> s -> t) -> GrateLike g s t a b
resetting LensLike f s0 t0 a b
la) (forall (g :: * -> *) a b s t.
Identical g =>
((a -> b) -> s -> t) -> GrateLike g s t a b
resetting LensLike f s1 t1 a b
lb)

ignored :: Applicative f => null -> s -> f s
-- ^ @
-- ignored :: Traversal s s a b
-- @
--
-- The empty traversal on any type.
ignored :: forall (f :: * -> *) null s. Applicative f => null -> s -> f s
ignored null
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure

mapped :: (Identical f, Functor h) => LensLike f (h a) (h b) a b
-- ^ @
-- mapped :: Functor h => Setter (h a) (h b) a b
-- @
--
-- An SEC referencing the parameter of a functor.
mapped :: forall (f :: * -> *) (h :: * -> *) a b.
(Identical f, Functor h) =>
LensLike f (h a) (h b) a b
mapped = forall (f :: * -> *) a b s t.
Identical f =>
((a -> b) -> s -> t) -> LensLike f s t a b
setting forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

backwards :: LensLike (Backwards f) s t a b -> LensLike f s t a b
-- ^ @
-- backwards :: Traversal s t a b -> Traversal s t a b
-- backwards :: Fold s t a b -> Fold s t a b
-- @
--
-- Given a traversal or fold, reverse the order that elements are traversed.
--
-- @
-- backwards :: Lens s t a b -> Lens s t a b
-- backwards :: Getter s t a b -> Getter s t a b
-- backwards :: Setter s t a b -> Setter s t a b
-- @
--
-- No effect on lenses, getters or setters.
backwards :: forall (f :: * -> *) s t a b.
LensLike (Backwards f) s t a b -> LensLike f s t a b
backwards LensLike (Backwards f) s t a b
l a -> f b
f = forall {k} (f :: k -> *) (a :: k). Backwards f a -> f a
forwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike (Backwards f) s t a b
l (forall {k} (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f)

{- Alongside -}

newtype AlongsideLeft f b a = AlongsideLeft (f (a, b))

instance Functor f => Functor (AlongsideLeft f a) where
  fmap :: forall a b. (a -> b) -> AlongsideLeft f a a -> AlongsideLeft f a b
fmap a -> b
f (AlongsideLeft f (a, a)
x) = forall (f :: * -> *) b a. f (a, b) -> AlongsideLeft f b a
AlongsideLeft (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first a -> b
f) f (a, a)
x)

instance Phantom f => Phantom (AlongsideLeft f a) where
  coerce :: forall a b. AlongsideLeft f a a -> AlongsideLeft f a b
coerce (AlongsideLeft f (a, a)
x) = forall (f :: * -> *) b a. f (a, b) -> AlongsideLeft f b a
AlongsideLeft (forall (f :: * -> *) a b. Phantom f => f a -> f b
coerce f (a, a)
x)

newtype AlongsideRight f a b = AlongsideRight (f (a, b))

instance Functor f => Functor (AlongsideRight f a) where
  fmap :: forall a b.
(a -> b) -> AlongsideRight f a a -> AlongsideRight f a b
fmap a -> b
f (AlongsideRight f (a, a)
x) = forall (f :: * -> *) a b. f (a, b) -> AlongsideRight f a b
AlongsideRight (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second a -> b
f) f (a, a)
x)

instance Phantom f => Phantom (AlongsideRight f a) where
  coerce :: forall a b. AlongsideRight f a a -> AlongsideRight f a b
coerce (AlongsideRight f (a, a)
x) = forall (f :: * -> *) a b. f (a, b) -> AlongsideRight f a b
AlongsideRight (forall (f :: * -> *) a b. Phantom f => f a -> f b
coerce f (a, a)
x)

alongside :: Functor f => LensLike (AlongsideLeft f b1) s0 t0 a0 b0
                       -> LensLike (AlongsideRight f t0) s1 t1 a1 b1
                       -> LensLike f (s0, s1) (t0, t1) (a0, a1) (b0, b1)
-- ^ @
-- alongside :: Lens s0 t0 a0 b0 -> Lens s1 t1 a1 b1 -> Lens (s0, s1) (t0, t1) (a0, a1) (b0, b1)
-- @
--
-- @
-- alongside :: Getter s0 t0 a0 b0 -> Getter s1 t1 a1 b1 -> Getter (s0, s1) (t0, t1) (a0, a1) (b0, b1)
-- @
--
-- Given two lens\/getter families, make a new lens\/getter on their product.
alongside :: forall (f :: * -> *) b1 s0 t0 a0 b0 s1 t1 a1.
Functor f =>
LensLike (AlongsideLeft f b1) s0 t0 a0 b0
-> LensLike (AlongsideRight f t0) s1 t1 a1 b1
-> LensLike f (s0, s1) (t0, t1) (a0, a1) (b0, b1)
alongside LensLike (AlongsideLeft f b1) s0 t0 a0 b0
l0 LensLike (AlongsideRight f t0) s1 t1 a1 b1
l1 (a0, a1) -> f (b0, b1)
f (s0
s0, s1
s1) = f (t0, t1)
ft0t1
 where
  AlongsideRight f (t0, t1)
ft0t1 = LensLike (AlongsideRight f t0) s1 t1 a1 b1
l1 a1 -> AlongsideRight f t0 b1
f1 s1
s1
  f1 :: a1 -> AlongsideRight f t0 b1
f1 a1
a1 = forall (f :: * -> *) a b. f (a, b) -> AlongsideRight f a b
AlongsideRight f (t0, b1)
ft0a1
   where
    AlongsideLeft f (t0, b1)
ft0a1 = LensLike (AlongsideLeft f b1) s0 t0 a0 b0
l0 a0 -> AlongsideLeft f b1 b0
f0 s0
s0
    f0 :: a0 -> AlongsideLeft f b1 b0
f0 a0
a0 = forall (f :: * -> *) b a. f (a, b) -> AlongsideLeft f b a
AlongsideLeft ((a0, a1) -> f (b0, b1)
f (a0
a0, a1
a1))

{- From -}

newtype FromF i j g x = FromF ((g x -> j) -> i)

instance Functor g => Functor (FromF i j g) where
  fmap :: forall a b. (a -> b) -> FromF i j g a -> FromF i j g b
fmap a -> b
f (FromF (g a -> j) -> i
h) = forall i j (g :: * -> *) x. ((g x -> j) -> i) -> FromF i j g x
FromF forall a b. (a -> b) -> a -> b
$ \g b -> j
k -> (g a -> j) -> i
h (g b -> j
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f)

instance Phantom g => Phantom (FromF i j g) where
  coerce :: forall a b. FromF i j g a -> FromF i j g b
coerce (FromF (g a -> j) -> i
h) = forall i j (g :: * -> *) x. ((g x -> j) -> i) -> FromF i j g x
FromF forall a b. (a -> b) -> a -> b
$ \g b -> j
k -> (g a -> j) -> i
h (g b -> j
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Phantom f => f a -> f b
coerce)

newtype FromG e f x = FromG (e -> f x)

instance Functor f => Functor (FromG e f) where
  fmap :: forall a b. (a -> b) -> FromG e f a -> FromG e f b
fmap a -> b
f (FromG e -> f a
h) = forall e (f :: * -> *) x. (e -> f x) -> FromG e f x
FromG forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> f a
h

instance Phantom g => Phantom (FromG e g) where
  coerce :: forall a b. FromG e g a -> FromG e g b
coerce (FromG e -> g a
h) = forall e (f :: * -> *) x. (e -> f x) -> FromG e f x
FromG forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Phantom f => f a -> f b
coerce forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> g a
h

from :: (Functor f, Functor g)
     => AdapterLike (FromF (g s -> f t) (f b) g) (FromG (f b) f) b a t s
     -> AdapterLike f g s t a b
-- ^ @
-- from :: Adapter b a t s -> Adapter s t a b
-- @
--
-- Reverses the direction of an adapter.
--
-- @
-- from :: Getter b a t s -> Reviewer s t a b
-- from :: Reviewer b a t s -> Getter s t a b
-- @
--
-- Changes a Getter into a Reviewer and vice versa.
from :: forall (f :: * -> *) (g :: * -> *) s t b a.
(Functor f, Functor g) =>
AdapterLike (FromF (g s -> f t) (f b) g) (FromG (f b) f) b a t s
-> AdapterLike f g s t a b
from AdapterLike (FromF (g s -> f t) (f b) g) (FromG (f b) f) b a t s
l = (g a -> f b) -> g s -> f t
l'
 where
  FromF (g a -> f b) -> g s -> f t
l' = AdapterLike (FromF (g s -> f t) (f b) g) (FromG (f b) f) b a t s
l (\(FromG f b -> f t
h1) -> forall i j (g :: * -> *) x. ((g x -> j) -> i) -> FromF i j g x
FromF forall a b. (a -> b) -> a -> b
$ forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) f b -> f t
h1) (forall e (f :: * -> *) x. (e -> f x) -> FromG e f x
FromG forall a. a -> a
id)

{-# DEPRECATED lft "Renamed as 'left'." #-}
lft :: (Applicative f, Traversable g) => AdapterLike f g (Either a r) (Either b r) a b
lft :: forall (f :: * -> *) (g :: * -> *) a r b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either a r) (Either b r) a b
lft = forall (f :: * -> *) (g :: * -> *) a r b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either a r) (Either b r) a b
left

{-# DEPRECATED lft_ "Renamed as 'left_'." #-}
lft_ :: Applicative f => LensLike f (Either a r) (Either b r) a b
lft_ :: forall (f :: * -> *) a r b.
Applicative f =>
LensLike f (Either a r) (Either b r) a b
lft_ = forall (f :: * -> *) a r b.
Applicative f =>
LensLike f (Either a r) (Either b r) a b
left_

{-# DEPRECATED rgt "Renamed as 'right'." #-}
rgt :: (Applicative f, Traversable g) => AdapterLike f g (Either r a) (Either r b) a b
rgt :: forall (f :: * -> *) (g :: * -> *) r a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either r a) (Either r b) a b
rgt = forall (f :: * -> *) (g :: * -> *) r a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either r a) (Either r b) a b
right

{-# DEPRECATED rgt_ "Renamed as 'right_'." #-}
rgt_ :: Applicative f => LensLike f (Either r a) (Either r b) a b
rgt_ :: forall (f :: * -> *) r a b.
Applicative f =>
LensLike f (Either r a) (Either r b) a b
rgt_ = forall (f :: * -> *) r a b.
Applicative f =>
LensLike f (Either r a) (Either r b) a b
right_

{-# DEPRECATED some "Renamed as 'just'." #-}
some :: (Applicative f, Traversable g) => AdapterLike f g (Maybe a) (Maybe b) a b
some :: forall (f :: * -> *) (g :: * -> *) a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Maybe a) (Maybe b) a b
some = forall (f :: * -> *) (g :: * -> *) a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Maybe a) (Maybe b) a b
just

{-# DEPRECATED some_ "Renamed as 'just_'." #-}
some_ :: Applicative f => LensLike f (Maybe a) (Maybe b) a b
some_ :: forall (f :: * -> *) a b.
Applicative f =>
LensLike f (Maybe a) (Maybe b) a b
some_ = forall (f :: * -> *) a b.
Applicative f =>
LensLike f (Maybe a) (Maybe b) a b
just_

{-# DEPRECATED none "Renamed as 'nothing'." #-}
none :: (Applicative f, Traversable g) => AdapterLike' f g (Maybe a) ()
none :: forall (f :: * -> *) (g :: * -> *) a.
(Applicative f, Traversable g) =>
AdapterLike' f g (Maybe a) ()
none = forall (f :: * -> *) (g :: * -> *) a.
(Applicative f, Traversable g) =>
AdapterLike' f g (Maybe a) ()
nothing

{-# DEPRECATED none_ "Renamed as 'nothing_'." #-}
none_ :: Applicative f => LensLike' f (Maybe a) ()
none_ :: forall (f :: * -> *) a. Applicative f => LensLike' f (Maybe a) ()
none_ = forall (f :: * -> *) a. Applicative f => LensLike' f (Maybe a) ()
nothing_