{-# LANGUAGE Rank2Types #-}
-- | 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.Family2.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
  , Stock.alongside
  , Stock.backwards
  , Stock.beside, Stock.beside', Stock.beside_
  , Stock.choosing
  , Stock.from
-- * Types
  , Stock.AlongsideLeft, Stock.AlongsideRight
  , Stock.FromF, Stock.FromG
-- * Re-exports
  , Lens, Lens'
  , Grate, Grate'
  , Traversal, Traversal'
  , Setter
  , Stock.AdapterLike, Stock.AdapterLike'
  , Stock.LensLike, Stock.LensLike'
  , Stock.Identical, Stock.Backwards
  , Stock.FiniteBits
-- * Deprecated names
  , lft, rgt
  , some, none
  , lft_, rgt_
  , some_, none_
  ) where

import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.IntMap as IntMap
import qualified Data.IntSet as IntSet
import qualified Lens.Family.Stock as Stock
import Lens.Family2

-- | Lens on the first element of a pair.
_1 :: Lens (a, r) (b, r) a b
_1 :: LensLike f (a, r) (b, r) a b
_1 = LensLike f (a, r) (b, r) a b
forall (f :: * -> *) a r b.
Functor f =>
LensLike f (a, r) (b, r) a b
Stock._1

-- | Lens on the second element of a pair.
_2 :: Lens (r, a) (r, b) a b
_2 :: LensLike f (r, a) (r, b) a b
_2 = LensLike f (r, a) (r, b) a b
forall (f :: * -> *) r a b.
Functor f =>
LensLike f (r, a) (r, b) a b
Stock._2

-- | Lens on the Left or Right element of an ('Either' a a).
chosen :: Lens (Either a a) (Either b b) a b
chosen :: LensLike f (Either a a) (Either b b) a b
chosen = LensLike f (Either a a) (Either b b) a b
forall (f :: * -> *) a b.
Functor f =>
LensLike f (Either a a) (Either b b) a b
Stock.chosen

-- | Lens on a given point of a function.
ix :: Eq k => k -> Lens' (k -> v) v
ix :: k -> Lens' (k -> v) v
ix k
k = k -> LensLike' f (k -> v) v
forall k (f :: * -> *) v.
(Eq k, Functor f) =>
k -> LensLike' f (k -> v) v
Stock.ix k
k

-- | Lens on a given point of a 'Map.Map'.
at :: Ord k => k -> Lens' (Map.Map k v) (Maybe v)
at :: k -> Lens' (Map k v) (Maybe v)
at k
k = k -> LensLike' f (Map k v) (Maybe v)
forall k (f :: * -> *) v.
(Ord k, Functor f) =>
k -> LensLike' f (Map k v) (Maybe v)
Stock.at k
k

-- | Lens on a given point of a 'IntMap.IntMap'.
intAt :: Int -> Lens' (IntMap.IntMap v) (Maybe v)
intAt :: Int -> Lens' (IntMap v) (Maybe v)
intAt Int
i = Int -> LensLike' f (IntMap v) (Maybe v)
forall (f :: * -> *) v.
Functor f =>
Int -> LensLike' f (IntMap v) (Maybe v)
Stock.intAt Int
i

-- | Lens providing strict access to a given point of a 'Map.Map'.
at' :: Ord k => k -> Lens' (Map.Map k v) (Maybe v)
at' :: k -> Lens' (Map k v) (Maybe v)
at' k
k = k -> LensLike' f (Map k v) (Maybe v)
forall k (f :: * -> *) v.
(Ord k, Functor f) =>
k -> LensLike' f (Map k v) (Maybe v)
Stock.at' k
k

-- | Lens providing strict access to a given point of a 'IntMap.IntMap'.
intAt' :: Int -> Lens' (IntMap.IntMap v) (Maybe v)
intAt' :: Int -> Lens' (IntMap v) (Maybe v)
intAt' Int
i = Int -> LensLike' f (IntMap v) (Maybe v)
forall (f :: * -> *) v.
Functor f =>
Int -> LensLike' f (IntMap v) (Maybe v)
Stock.intAt' Int
i

-- | Lens on a given point of a 'Set.Set'.
contains :: Ord k => k -> Lens' (Set.Set k) Bool
contains :: k -> Lens' (Set k) Bool
contains k
k = k -> LensLike' f (Set k) Bool
forall k (f :: * -> *).
(Ord k, Functor f) =>
k -> LensLike' f (Set k) Bool
Stock.contains k
k

-- | Lens on a given point of a 'IntSet.IntSet'.
intContains :: Int -> Lens' IntSet.IntSet Bool
intContains :: Int -> Lens' IntSet Bool
intContains Int
i = Int -> LensLike' f IntSet Bool
forall (f :: * -> *). Functor f => Int -> LensLike' f IntSet Bool
Stock.intContains Int
i

-- | A grate accessing the codomain of a function.
cod :: Grate (r -> a) (r -> b) a b
cod :: GrateLike g (r -> a) (r -> b) a b
cod = GrateLike g (r -> a) (r -> b) a b
forall (g :: * -> *) r a b.
Functor g =>
GrateLike g (r -> a) (r -> b) a b
Stock.cod

-- | A prism on the 'Left' element of an 'Either'.
left :: Prism (Either a r) (Either b r) a b
left :: AdapterLike f g (Either a r) (Either b r) a b
left = AdapterLike f g (Either a r) (Either b r) a b
forall (f :: * -> *) (g :: * -> *) a r b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either a r) (Either b r) a b
Stock.left

-- | Traversal on the 'Left' element of an 'Either'.
left_ :: Traversal (Either a r) (Either b r) a b
left_ :: LensLike f (Either a r) (Either b r) a b
left_ = LensLike f (Either a r) (Either b r) a b
forall (f :: * -> *) a r b.
Applicative f =>
LensLike f (Either a r) (Either b r) a b
Stock.left_

-- | A prism on the 'Right' element of an 'Either'.
right :: Prism (Either r a) (Either r b) a b
right :: AdapterLike f g (Either r a) (Either r b) a b
right = AdapterLike f g (Either r a) (Either r b) a b
forall (f :: * -> *) (g :: * -> *) r a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Either r a) (Either r b) a b
Stock.right

-- | Traversal on the 'Right' element of an 'Either'.
right_ :: Traversal (Either r a) (Either r b) a b
right_ :: LensLike f (Either r a) (Either r b) a b
right_ = LensLike f (Either r a) (Either r b) a b
forall (f :: * -> *) r a b.
Applicative f =>
LensLike f (Either r a) (Either r b) a b
Stock.right_

-- | A prism on the 'Just' element of a 'Maybe'.
just :: Prism (Maybe a) (Maybe b) a b
just :: AdapterLike f g (Maybe a) (Maybe b) a b
just = AdapterLike f g (Maybe a) (Maybe b) a b
forall (f :: * -> *) (g :: * -> *) a b.
(Applicative f, Traversable g) =>
AdapterLike f g (Maybe a) (Maybe b) a b
Stock.just

-- | Traversal on the 'Just' element of a 'Maybe'.
just_ :: Traversal (Maybe a) (Maybe b) a b
just_ :: LensLike f (Maybe a) (Maybe b) a b
just_ = LensLike f (Maybe a) (Maybe b) a b
forall (f :: * -> *) a b.
Applicative f =>
LensLike f (Maybe a) (Maybe b) a b
Stock.just_

-- | A prism on the 'Nothing' element of a 'Maybe'.
nothing :: Prism' (Maybe a) ()
nothing :: AdapterLike' f g (Maybe a) ()
nothing = AdapterLike' f g (Maybe a) ()
forall (f :: * -> *) (g :: * -> *) a.
(Applicative f, Traversable g) =>
AdapterLike' f g (Maybe a) ()
Stock.nothing

-- | Traversal on the 'Nothing' element of a 'Maybe'.
nothing_ :: Traversal' (Maybe a) ()
nothing_ :: LensLike' f (Maybe a) ()
nothing_ = LensLike' f (Maybe a) ()
forall (f :: * -> *) a. Applicative f => LensLike' f (Maybe a) ()
Stock.nothing_

-- | A grid on both elements of a pair @(a,a)@.
both :: Grid (a,a) (b,b) a b
both :: AdapterLike f g (a, a) (b, b) a b
both = AdapterLike f g (a, a) (b, b) a b
forall (f :: * -> *) (g :: * -> *) a b.
(Applicative f, Functor g) =>
AdapterLike f g (a, a) (b, b) a b
Stock.both

-- | A grate on both elements of a pair @(a,a)@.
both' :: Grate (a,a) (b,b) a b
both' :: GrateLike g (a, a) (b, b) a b
both' = GrateLike g (a, a) (b, b) a b
forall (g :: * -> *) a b.
Functor g =>
GrateLike g (a, a) (b, b) a b
Stock.both'

-- | Traversals on both elements of a pair @(a,a)@.
both_ :: Traversal (a,a) (b,b) a b
both_ :: LensLike f (a, a) (b, b) a b
both_ = LensLike f (a, a) (b, b) a b
forall (f :: * -> *) a b.
Applicative f =>
LensLike f (a, a) (b, b) a b
Stock.both_

-- | A grid from the least significant bit to the most significant bit of a 'FiniteBits' type.
--
-- Little endian order.
lend :: Stock.FiniteBits b => Grid' b Bool
lend :: Grid' b Bool
lend = AdapterLike' f g b Bool
forall b (f :: * -> *) (g :: * -> *).
(FiniteBits b, Applicative f, Functor g) =>
AdapterLike' f g b Bool
Stock.lend

-- | A grate from the least significant bit to the most significant bit of a 'FiniteBits' type.
--
-- Little endian order.
lend' :: Stock.FiniteBits b => Grate' b Bool
lend' :: Grate' b Bool
lend' = GrateLike' g b Bool
forall b (g :: * -> *).
(FiniteBits b, Functor g) =>
GrateLike' g b Bool
Stock.lend'

-- | A traversal from the least significant bit to the most significant bit of a 'FiniteBits' type.
--
-- Little endian order.
lend_ :: Stock.FiniteBits b => Traversal' b Bool
lend_ :: Traversal' b Bool
lend_ = LensLike' f b Bool
forall b (f :: * -> *).
(FiniteBits b, Applicative f) =>
LensLike' f b Bool
Stock.lend_

-- | A grid from the most significant bit to the least significant bit of a 'FiniteBits' type.
--
-- Big endian order.
bend :: Stock.FiniteBits b => Grid' b Bool
bend :: Grid' b Bool
bend = AdapterLike' f g b Bool
forall b (f :: * -> *) (g :: * -> *).
(FiniteBits b, Applicative f, Functor g) =>
AdapterLike' f g b Bool
Stock.bend

-- | A grate from the most significant bit to the least significant bit of a 'FiniteBits' type.
--
-- Big endian order.
bend' :: Stock.FiniteBits b => Grate' b Bool
bend' :: Grate' b Bool
bend' = GrateLike' g b Bool
forall b (g :: * -> *).
(FiniteBits b, Functor g) =>
GrateLike' g b Bool
Stock.bend'

-- | A traversal from the most significant bit to the least significant bit of a 'FiniteBits' type.
--
-- Big endian order.
bend_ :: Stock.FiniteBits b => Traversal' b Bool
bend_ :: Traversal' b Bool
bend_ = LensLike' f b Bool
forall b (f :: * -> *).
(FiniteBits b, Applicative f) =>
LensLike' f b Bool
Stock.bend_

-- | The empty traveral on any type.
ignored :: Traversal a a b b'
ignored :: LensLike f a a b b'
ignored = LensLike f a a b b'
forall (f :: * -> *) null s. Applicative f => null -> s -> f s
Stock.ignored

-- | An SEC referencing the parameter of a functor.
mapped :: Functor f => Setter (f a) (f a') a a'
mapped :: Setter (f a) (f a') a a'
mapped = LensLike f (f a) (f a') a a'
forall (f :: * -> *) (h :: * -> *) a b.
(Identical f, Functor h) =>
LensLike f (h a) (h b) a b
Stock.mapped

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

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

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

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

{-# DEPRECATED some "Renamed as 'just'." #-}
some :: Prism (Maybe a) (Maybe b) a b
some :: AdapterLike f g (Maybe a) (Maybe b) a b
some = AdapterLike f g (Maybe a) (Maybe b) a b
forall a b. Prism (Maybe a) (Maybe b) a b
just

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

{-# DEPRECATED none "Renamed as 'nothing'." #-}
none :: Prism' (Maybe a) ()
none :: AdapterLike' f g (Maybe a) ()
none = AdapterLike' f g (Maybe a) ()
forall a. Prism' (Maybe a) ()
nothing

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