-- |
-- Module      : Toml.Lens
-- Description : Lenses for toml-parser
-- Copyright   : (c) 2017-2024, Henry Till
-- License     : ISC
-- Maintainer  : henrytill@gmail.com
-- Stability   : experimental
--
-- Lenses for <https://hackage.haskell.org/package/toml-parser toml-parser>.
module Toml.Lens
  ( -- * Unannotated
    _Table,
    _List,
    _Double,
    _Integer,
    _Text,
    _Bool,
    _ZonedTime,
    _LocalTime,
    _Day,
    _TimeOfDay,

    -- * Annotated
    _Table',
    _List',
    _Double',
    _Integer',
    _Text',
    _Bool',
    _ZonedTime',
    _LocalTime',
    _Day',
    _TimeOfDay',
  )
where

import Data.Profunctor
import Data.Text (Text)
import qualified Data.Time as Time
import Toml

--
-- With help from:
-- <https://github.com/ekmett/lens/wiki/How-can-I-write-lenses-without-depending-on-lens%3F>
--
-- @
-- type Prism s t a b = (Choice p, Applicative f) => p a (f b) -> p s (f t)
-- @
--
-- @
-- type Prism' s a = Prism s s a a
-- @
--

prism ::
  (Choice p, Applicative f) =>
  (b -> t) ->
  (s -> Either t a) ->
  p a (f b) ->
  p s (f t)
prism :: forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism b -> t
bt s -> Either t a
seta = (s -> Either t a)
-> (Either t (f b) -> f t)
-> p (Either t a) (Either t (f b))
-> p s (f t)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap s -> Either t a
seta ((t -> f t) -> (f b -> f t) -> Either t (f b) -> f t
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either t -> f t
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((b -> t) -> f b -> f t
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> t
bt)) (p (Either t a) (Either t (f b)) -> p s (f t))
-> (p a (f b) -> p (Either t a) (Either t (f b)))
-> p a (f b)
-> p s (f t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a (f b) -> p (Either t a) (Either t (f b))
forall a b c. p a b -> p (Either c a) (Either c b)
forall (p :: * -> * -> *) a b c.
Choice p =>
p a b -> p (Either c a) (Either c b)
right'
{-# INLINE prism #-}

-- | @_Table :: Prism' Value Table@
_Table ::
  (Choice p, Applicative f) =>
  p Table (f Table) ->
  p Value (f Value)
_Table :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p Table (f Table) -> p Value (f Value)
_Table =
  (Table -> Value)
-> (Value -> Either Value Table)
-> p Table (f Table)
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism Table -> Value
Table ((Value -> Either Value Table)
 -> p Table (f Table) -> p Value (f Value))
-> (Value -> Either Value Table)
-> p Table (f Table)
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    Table Table
v -> Table -> Either Value Table
forall a b. b -> Either a b
Right Table
v
    Value
_ -> Value -> Either Value Table
forall a b. a -> Either a b
Left Value
n
{-# INLINE _Table #-}

-- | @_List :: Prism' Value [Value]@
_List ::
  (Choice p, Applicative f) =>
  p [Value] (f [Value]) ->
  p Value (f Value)
_List :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p [Value] (f [Value]) -> p Value (f Value)
_List =
  ([Value] -> Value)
-> (Value -> Either Value [Value])
-> p [Value] (f [Value])
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism [Value] -> Value
List ((Value -> Either Value [Value])
 -> p [Value] (f [Value]) -> p Value (f Value))
-> (Value -> Either Value [Value])
-> p [Value] (f [Value])
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    List [Value]
v -> [Value] -> Either Value [Value]
forall a b. b -> Either a b
Right [Value]
v
    Value
_ -> Value -> Either Value [Value]
forall a b. a -> Either a b
Left Value
n
{-# INLINE _List #-}

-- | @_Double :: Prism' Value Double@
_Double ::
  (Choice p, Applicative f) =>
  p Double (f Double) ->
  p Value (f Value)
_Double :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p Double (f Double) -> p Value (f Value)
_Double =
  (Double -> Value)
-> (Value -> Either Value Double)
-> p Double (f Double)
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism Double -> Value
Double ((Value -> Either Value Double)
 -> p Double (f Double) -> p Value (f Value))
-> (Value -> Either Value Double)
-> p Double (f Double)
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    Double Double
v -> Double -> Either Value Double
forall a b. b -> Either a b
Right Double
v
    Value
_ -> Value -> Either Value Double
forall a b. a -> Either a b
Left Value
n
{-# INLINE _Double #-}

-- | @_Integer :: Prism' Value Integer@
_Integer ::
  (Choice p, Applicative f) =>
  p Integer (f Integer) ->
  p Value (f Value)
_Integer :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p Integer (f Integer) -> p Value (f Value)
_Integer =
  (Integer -> Value)
-> (Value -> Either Value Integer)
-> p Integer (f Integer)
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism Integer -> Value
Integer ((Value -> Either Value Integer)
 -> p Integer (f Integer) -> p Value (f Value))
-> (Value -> Either Value Integer)
-> p Integer (f Integer)
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    Integer Integer
v -> Integer -> Either Value Integer
forall a b. b -> Either a b
Right Integer
v
    Value
_ -> Value -> Either Value Integer
forall a b. a -> Either a b
Left Value
n
{-# INLINE _Integer #-}

-- | @_Text :: Prism' Value Text@
_Text ::
  (Choice p, Applicative f) =>
  p Text (f Text) ->
  p Value (f Value)
_Text :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p Text (f Text) -> p Value (f Value)
_Text =
  (Text -> Value)
-> (Value -> Either Value Text)
-> p Text (f Text)
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism Text -> Value
Text ((Value -> Either Value Text)
 -> p Text (f Text) -> p Value (f Value))
-> (Value -> Either Value Text)
-> p Text (f Text)
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    Text Text
v -> Text -> Either Value Text
forall a b. b -> Either a b
Right Text
v
    Value
_ -> Value -> Either Value Text
forall a b. a -> Either a b
Left Value
n
{-# INLINE _Text #-}

-- | @_Bool :: Prism' Value Bool@
_Bool ::
  (Choice p, Applicative f) =>
  p Bool (f Bool) ->
  p Value (f Value)
_Bool :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p Bool (f Bool) -> p Value (f Value)
_Bool =
  (Bool -> Value)
-> (Value -> Either Value Bool)
-> p Bool (f Bool)
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism Bool -> Value
Bool ((Value -> Either Value Bool)
 -> p Bool (f Bool) -> p Value (f Value))
-> (Value -> Either Value Bool)
-> p Bool (f Bool)
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    Bool Bool
v -> Bool -> Either Value Bool
forall a b. b -> Either a b
Right Bool
v
    Value
_ -> Value -> Either Value Bool
forall a b. a -> Either a b
Left Value
n
{-# INLINE _Bool #-}

-- | @_ZonedTime :: Prism' Value Time.ZonedTime@
_ZonedTime ::
  (Choice p, Applicative f) =>
  p Time.ZonedTime (f Time.ZonedTime) ->
  p Value (f Value)
_ZonedTime :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p ZonedTime (f ZonedTime) -> p Value (f Value)
_ZonedTime =
  (ZonedTime -> Value)
-> (Value -> Either Value ZonedTime)
-> p ZonedTime (f ZonedTime)
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ZonedTime -> Value
ZonedTime ((Value -> Either Value ZonedTime)
 -> p ZonedTime (f ZonedTime) -> p Value (f Value))
-> (Value -> Either Value ZonedTime)
-> p ZonedTime (f ZonedTime)
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    ZonedTime ZonedTime
v -> ZonedTime -> Either Value ZonedTime
forall a b. b -> Either a b
Right ZonedTime
v
    Value
_ -> Value -> Either Value ZonedTime
forall a b. a -> Either a b
Left Value
n
{-# INLINE _ZonedTime #-}

-- | @_LocalTime :: Prism' Value Time.LocalTime@
_LocalTime ::
  (Choice p, Applicative f) =>
  p Time.LocalTime (f Time.LocalTime) ->
  p Value (f Value)
_LocalTime :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p LocalTime (f LocalTime) -> p Value (f Value)
_LocalTime =
  (LocalTime -> Value)
-> (Value -> Either Value LocalTime)
-> p LocalTime (f LocalTime)
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism LocalTime -> Value
LocalTime ((Value -> Either Value LocalTime)
 -> p LocalTime (f LocalTime) -> p Value (f Value))
-> (Value -> Either Value LocalTime)
-> p LocalTime (f LocalTime)
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    LocalTime LocalTime
v -> LocalTime -> Either Value LocalTime
forall a b. b -> Either a b
Right LocalTime
v
    Value
_ -> Value -> Either Value LocalTime
forall a b. a -> Either a b
Left Value
n
{-# INLINE _LocalTime #-}

-- | @_Day :: Prism' Value Time.Day@
_Day ::
  (Choice p, Applicative f) =>
  p Time.Day (f Time.Day) ->
  p Value (f Value)
_Day :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p Day (f Day) -> p Value (f Value)
_Day =
  (Day -> Value)
-> (Value -> Either Value Day)
-> p Day (f Day)
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism Day -> Value
Day ((Value -> Either Value Day) -> p Day (f Day) -> p Value (f Value))
-> (Value -> Either Value Day)
-> p Day (f Day)
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    Day Day
v -> Day -> Either Value Day
forall a b. b -> Either a b
Right Day
v
    Value
_ -> Value -> Either Value Day
forall a b. a -> Either a b
Left Value
n
{-# INLINE _Day #-}

-- | @_TimeOfDay :: Prism' Value Time.TimeOfDay@
_TimeOfDay ::
  (Choice p, Applicative f) =>
  p Time.TimeOfDay (f Time.TimeOfDay) ->
  p Value (f Value)
_TimeOfDay :: forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p TimeOfDay (f TimeOfDay) -> p Value (f Value)
_TimeOfDay =
  (TimeOfDay -> Value)
-> (Value -> Either Value TimeOfDay)
-> p TimeOfDay (f TimeOfDay)
-> p Value (f Value)
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism TimeOfDay -> Value
TimeOfDay ((Value -> Either Value TimeOfDay)
 -> p TimeOfDay (f TimeOfDay) -> p Value (f Value))
-> (Value -> Either Value TimeOfDay)
-> p TimeOfDay (f TimeOfDay)
-> p Value (f Value)
forall a b. (a -> b) -> a -> b
$ \Value
n -> case Value
n of
    TimeOfDay TimeOfDay
v -> TimeOfDay -> Either Value TimeOfDay
forall a b. b -> Either a b
Right TimeOfDay
v
    Value
_ -> Value -> Either Value TimeOfDay
forall a b. a -> Either a b
Left Value
n
{-# INLINE _TimeOfDay #-}

-- | @_Table' :: Prism' (Value' a) (a, Table' a)@
_Table' ::
  (Choice p, Applicative f) =>
  p (a, Table' a) (f (a, Table' a)) ->
  p (Value' a) (f (Value' a))
_Table' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, Table' a) (f (a, Table' a)) -> p (Value' a) (f (Value' a))
_Table' =
  ((a, Table' a) -> Value' a)
-> (Value' a -> Either (Value' a) (a, Table' a))
-> p (a, Table' a) (f (a, Table' a))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> Table' a -> Value' a) -> (a, Table' a) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> Table' a -> Value' a
forall a. a -> Table' a -> Value' a
Table') ((Value' a -> Either (Value' a) (a, Table' a))
 -> p (a, Table' a) (f (a, Table' a))
 -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, Table' a))
-> p (a, Table' a) (f (a, Table' a))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    Table' a
a Table' a
v -> (a, Table' a) -> Either (Value' a) (a, Table' a)
forall a b. b -> Either a b
Right (a
a, Table' a
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, Table' a)
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _Table' #-}

-- | @_Array' :: Prism' (Value' a) (a, [Value' a])@
_List' ::
  (Choice p, Applicative f) =>
  p (a, [Value' a]) (f (a, [Value' a])) ->
  p (Value' a) (f (Value' a))
_List' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, [Value' a]) (f (a, [Value' a]))
-> p (Value' a) (f (Value' a))
_List' =
  ((a, [Value' a]) -> Value' a)
-> (Value' a -> Either (Value' a) (a, [Value' a]))
-> p (a, [Value' a]) (f (a, [Value' a]))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> [Value' a] -> Value' a) -> (a, [Value' a]) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> [Value' a] -> Value' a
forall a. a -> [Value' a] -> Value' a
List') ((Value' a -> Either (Value' a) (a, [Value' a]))
 -> p (a, [Value' a]) (f (a, [Value' a]))
 -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, [Value' a]))
-> p (a, [Value' a]) (f (a, [Value' a]))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    List' a
a [Value' a]
v -> (a, [Value' a]) -> Either (Value' a) (a, [Value' a])
forall a b. b -> Either a b
Right (a
a, [Value' a]
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, [Value' a])
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _List' #-}

-- | @_Double' :: Prism' (Value' a) (a, Double)@
_Double' ::
  (Choice p, Applicative f) =>
  p (a, Double) (f (a, Double)) ->
  p (Value' a) (f (Value' a))
_Double' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, Double) (f (a, Double)) -> p (Value' a) (f (Value' a))
_Double' =
  ((a, Double) -> Value' a)
-> (Value' a -> Either (Value' a) (a, Double))
-> p (a, Double) (f (a, Double))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> Double -> Value' a) -> (a, Double) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> Double -> Value' a
forall a. a -> Double -> Value' a
Double') ((Value' a -> Either (Value' a) (a, Double))
 -> p (a, Double) (f (a, Double)) -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, Double))
-> p (a, Double) (f (a, Double))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    Double' a
a Double
v -> (a, Double) -> Either (Value' a) (a, Double)
forall a b. b -> Either a b
Right (a
a, Double
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, Double)
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _Double' #-}

-- | @_Integer' :: Prism' (Value' a) (a, Integer)@
_Integer' ::
  (Choice p, Applicative f) =>
  p (a, Integer) (f (a, Integer)) ->
  p (Value' a) (f (Value' a))
_Integer' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, Integer) (f (a, Integer)) -> p (Value' a) (f (Value' a))
_Integer' =
  ((a, Integer) -> Value' a)
-> (Value' a -> Either (Value' a) (a, Integer))
-> p (a, Integer) (f (a, Integer))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> Integer -> Value' a) -> (a, Integer) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> Integer -> Value' a
forall a. a -> Integer -> Value' a
Integer') ((Value' a -> Either (Value' a) (a, Integer))
 -> p (a, Integer) (f (a, Integer)) -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, Integer))
-> p (a, Integer) (f (a, Integer))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    Integer' a
a Integer
v -> (a, Integer) -> Either (Value' a) (a, Integer)
forall a b. b -> Either a b
Right (a
a, Integer
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, Integer)
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _Integer' #-}

-- | @_Text' :: Prism' (Value' a) (a, Text)@
_Text' ::
  (Choice p, Applicative f) =>
  p (a, Text) (f (a, Text)) ->
  p (Value' a) (f (Value' a))
_Text' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, Text) (f (a, Text)) -> p (Value' a) (f (Value' a))
_Text' =
  ((a, Text) -> Value' a)
-> (Value' a -> Either (Value' a) (a, Text))
-> p (a, Text) (f (a, Text))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> Text -> Value' a) -> (a, Text) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> Text -> Value' a
forall a. a -> Text -> Value' a
Text') ((Value' a -> Either (Value' a) (a, Text))
 -> p (a, Text) (f (a, Text)) -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, Text))
-> p (a, Text) (f (a, Text))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    Text' a
a Text
v -> (a, Text) -> Either (Value' a) (a, Text)
forall a b. b -> Either a b
Right (a
a, Text
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, Text)
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _Text' #-}

-- | @_Bool' :: Prism' (Value' a) (a, Bool)@
_Bool' ::
  (Choice p, Applicative f) =>
  p (a, Bool) (f (a, Bool)) ->
  p (Value' a) (f (Value' a))
_Bool' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, Bool) (f (a, Bool)) -> p (Value' a) (f (Value' a))
_Bool' =
  ((a, Bool) -> Value' a)
-> (Value' a -> Either (Value' a) (a, Bool))
-> p (a, Bool) (f (a, Bool))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> Bool -> Value' a) -> (a, Bool) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> Bool -> Value' a
forall a. a -> Bool -> Value' a
Bool') ((Value' a -> Either (Value' a) (a, Bool))
 -> p (a, Bool) (f (a, Bool)) -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, Bool))
-> p (a, Bool) (f (a, Bool))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    Bool' a
a Bool
v -> (a, Bool) -> Either (Value' a) (a, Bool)
forall a b. b -> Either a b
Right (a
a, Bool
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, Bool)
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _Bool' #-}

-- | @_ZonedTime' :: Prism' (Value' a) (a, Time.ZonedTime)@
_ZonedTime' ::
  (Choice p, Applicative f) =>
  p (a, Time.ZonedTime) (f (a, Time.ZonedTime)) ->
  p (Value' a) (f (Value' a))
_ZonedTime' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, ZonedTime) (f (a, ZonedTime)) -> p (Value' a) (f (Value' a))
_ZonedTime' =
  ((a, ZonedTime) -> Value' a)
-> (Value' a -> Either (Value' a) (a, ZonedTime))
-> p (a, ZonedTime) (f (a, ZonedTime))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> ZonedTime -> Value' a) -> (a, ZonedTime) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> ZonedTime -> Value' a
forall a. a -> ZonedTime -> Value' a
ZonedTime') ((Value' a -> Either (Value' a) (a, ZonedTime))
 -> p (a, ZonedTime) (f (a, ZonedTime))
 -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, ZonedTime))
-> p (a, ZonedTime) (f (a, ZonedTime))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    ZonedTime' a
a ZonedTime
v -> (a, ZonedTime) -> Either (Value' a) (a, ZonedTime)
forall a b. b -> Either a b
Right (a
a, ZonedTime
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, ZonedTime)
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _ZonedTime' #-}

-- | @_LocalTime' :: Prism' (Value' a) (a, Time.LocalTime)@
_LocalTime' ::
  (Choice p, Applicative f) =>
  p (a, Time.LocalTime) (f (a, Time.LocalTime)) ->
  p (Value' a) (f (Value' a))
_LocalTime' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, LocalTime) (f (a, LocalTime)) -> p (Value' a) (f (Value' a))
_LocalTime' =
  ((a, LocalTime) -> Value' a)
-> (Value' a -> Either (Value' a) (a, LocalTime))
-> p (a, LocalTime) (f (a, LocalTime))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> LocalTime -> Value' a) -> (a, LocalTime) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> LocalTime -> Value' a
forall a. a -> LocalTime -> Value' a
LocalTime') ((Value' a -> Either (Value' a) (a, LocalTime))
 -> p (a, LocalTime) (f (a, LocalTime))
 -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, LocalTime))
-> p (a, LocalTime) (f (a, LocalTime))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    LocalTime' a
a LocalTime
v -> (a, LocalTime) -> Either (Value' a) (a, LocalTime)
forall a b. b -> Either a b
Right (a
a, LocalTime
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, LocalTime)
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _LocalTime' #-}

-- | @_Day' :: Prism' (Value' a) (a, Time.Day)@
_Day' ::
  (Choice p, Applicative f) =>
  p (a, Time.Day) (f (a, Time.Day)) ->
  p (Value' a) (f (Value' a))
_Day' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, Day) (f (a, Day)) -> p (Value' a) (f (Value' a))
_Day' =
  ((a, Day) -> Value' a)
-> (Value' a -> Either (Value' a) (a, Day))
-> p (a, Day) (f (a, Day))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> Day -> Value' a) -> (a, Day) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> Day -> Value' a
forall a. a -> Day -> Value' a
Day') ((Value' a -> Either (Value' a) (a, Day))
 -> p (a, Day) (f (a, Day)) -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, Day))
-> p (a, Day) (f (a, Day))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    Day' a
a Day
v -> (a, Day) -> Either (Value' a) (a, Day)
forall a b. b -> Either a b
Right (a
a, Day
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, Day)
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _Day' #-}

-- | @_TimeOfDay' :: Prism' (Value' a) (a, Time.TimeOfDay)@
_TimeOfDay' ::
  (Choice p, Applicative f) =>
  p (a, Time.TimeOfDay) (f (a, Time.TimeOfDay)) ->
  p (Value' a) (f (Value' a))
_TimeOfDay' :: forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
p (a, TimeOfDay) (f (a, TimeOfDay)) -> p (Value' a) (f (Value' a))
_TimeOfDay' =
  ((a, TimeOfDay) -> Value' a)
-> (Value' a -> Either (Value' a) (a, TimeOfDay))
-> p (a, TimeOfDay) (f (a, TimeOfDay))
-> p (Value' a) (f (Value' a))
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Choice p, Applicative f) =>
(b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
prism ((a -> TimeOfDay -> Value' a) -> (a, TimeOfDay) -> Value' a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> TimeOfDay -> Value' a
forall a. a -> TimeOfDay -> Value' a
TimeOfDay') ((Value' a -> Either (Value' a) (a, TimeOfDay))
 -> p (a, TimeOfDay) (f (a, TimeOfDay))
 -> p (Value' a) (f (Value' a)))
-> (Value' a -> Either (Value' a) (a, TimeOfDay))
-> p (a, TimeOfDay) (f (a, TimeOfDay))
-> p (Value' a) (f (Value' a))
forall a b. (a -> b) -> a -> b
$ \Value' a
n -> case Value' a
n of
    TimeOfDay' a
a TimeOfDay
v -> (a, TimeOfDay) -> Either (Value' a) (a, TimeOfDay)
forall a b. b -> Either a b
Right (a
a, TimeOfDay
v)
    Value' a
_ -> Value' a -> Either (Value' a) (a, TimeOfDay)
forall a b. a -> Either a b
Left Value' a
n
{-# INLINE _TimeOfDay' #-}