{-# LANGUAGE OverloadedStrings, RequiredTypeArguments #-}

{- |
Module      : Control.Lens.Grammar.Json
Description : JSON grammars, compatible with aeson & typed in TypeScript
Copyright   : (C) 2026 - Eitan Chatav
License     : BSD-style (see the file LICENSE)
Maintainer  : Eitan Chatav <eitan.chatav@gmail.com>
Stability   : provisional
Portability : non-portable

A `Json` grammar of a type parses, prints & encodes its JSON,
compatibly with @aeson@, & types it in TypeScript, all at once.

= Deriving

A `GHC.Generic` type derives its grammar, by @aeson@'s default options.

>>> :{
data Person = Person {name :: Text, age :: Int, email :: Maybe Text}
  deriving stock (Show, Generic)
  deriving anyclass Json
:}

>>> LByteString.putStrLn (encodingToLazyByteString (jsonEncode (Person "Ada" 36 Nothing)))
{"name":"Ada","age":36,"email":null}
>>> jsonDecode @Person "{\"name\":\"Ada\",\"age\":36}"
Right (Person {name = "Ada", age = 36, email = Nothing})

Failures are located, & name what they expected.

>>> either explain show (jsonDecode @Person "{\"name\":\"Ada\",\"age\":\"36\"}")
"Error in $.age: expected Int, but found \"36\""

= @aeson@

t'ViaJson' derives @aeson@'s instances, & `jsonGeneric` takes
@aeson@'s `Aeson.Options`.

>>> :{
data Pet = Cat | Dog
  deriving stock (Show, Generic)
  deriving (Aeson.ToJSON, Aeson.FromJSON) via ViaJson Pet
instance Json Pet where
  json = jsonGeneric Aeson.defaultOptions {Aeson.constructorTagModifier = map toLower}
:}

>>> Aeson.encode [Cat, Dog]
"[\"cat\",\"dog\"]"

= Grammars

A grammar is written once, with the combinators of `JsonVal`,
`JsonObj`, `JsonTup` & `JsonStr`, & `ruleTyped` names its type.

>>> :{
data Point = Point Double Double
  deriving stock Show
instance Json Point where
  json = ruleTyped $ iso (\(Point x y) -> (x, y)) (uncurry Point)
    >~ jsonObject ("x" !: json >*< "y" ?: json != 0)
:}

>>> jsonDecode @Point "{\"x\":1}"
Right (Point 1.0 0.0)
>>> jsonPrint (Point 1 0)
Object (fromList [("x",Number 1.0)])

A tuple is an array of elements, & a sum is the alternative grammars
of its constructors, here tagged by string literals.

>>> :{
data Shape = Circle Double | Rectangle Double Double
  deriving stock Show
_Circle :: Prism' Shape Double
_Circle = prism' Circle (\case Circle r -> Just r; _ -> Nothing)
_Rectangle :: Prism' Shape (Double, Double)
_Rectangle = prism' (uncurry Rectangle) (\case Rectangle w h -> Just (w, h); _ -> Nothing)
instance Json Shape where
  json = ruleTyped $ orP
    [ _Circle >? jsonObject ("kind" !: "circle" >* "radius" !: json)
    , _Rectangle >? jsonObject ("kind" !: "rectangle" >* "size" !: jsonTuple (jsonElem json >*< jsonElem json))
    ]
:}

>>> LByteString.putStrLn (encodingToLazyByteString (jsonEncode [Circle 1, Rectangle 2 3]))
[{"kind":"circle","radius":1.0},{"kind":"rectangle","size":[2.0,3.0]}]

= Types

`jsonTsPut` puts the TypeScript declarations of types' JSON,
which `jsonTsDeclarations` declares, by "Control.Lens.Grammar.TypeScript",
& `jsonType` types.

>>> jsonTsPut (type '[Person, Point, Shape]) stdout
export type Double = number | null | "+inf" | "-inf";
export type Int = number;
export type Person = { name: string; age: Int; email?: null | string };
export type Point = { x: Double; y?: Double };
export type Shape = { kind: "circle"; radius: Double } | { kind: "rectangle"; size: [Double, Double] };
-}

module Control.Lens.Grammar.Json
  ( -- * Json
    Json (..)
  , jsonGeneric
  , jsonParse
  , jsonDecode
  , jsonPrint
  , jsonErrorPrint
  , jsonEncode
  , jsonErrorEncode
  , ViaJson (..)
    -- * Grammar
  , JsonVal (..)
  , JsonObj (..), (!=)
  , JsonTup (..)
  , JsonStr (..), jsonEnum
    -- * Types
  , jsonType
  , jsonTsDeclarations
  , jsonTsPut
  , JsonType (..)
  , JsonElements (..)
  , JsonProperty (..)
    -- * Errors
  , JsonError (..)
  , JsonErrorSort (..)
  , jsonErrorMessage
  ) where

import Control.Applicative
import Control.Lens
import Control.Lens.Grammar
import Control.Lens.Comonocle (AComonocle, withComonocle)
import Control.Monad
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Reader (ReaderT, ask, local, runReaderT)
import Control.Monad.Trans.State.Strict
import Data.Aeson qualified as Aeson
import Data.Aeson.Encoding (Encoding)
import Data.Aeson.Encoding qualified as Encoding
import Data.Aeson.Encoding.Internal qualified as EncodingInternal
import Data.Aeson.Key (Key)
import Data.Aeson.Key qualified as Key
import Data.Aeson.KeyMap (KeyMap)
import Data.Aeson.KeyMap qualified as KeyMap
import Data.Aeson.Text (encodeToLazyText)
import Data.Aeson.Types
  (DotNetTime (..), JSONPathElement (..), Object, Value (..))
import Data.Aeson.Types qualified as Aeson (Parser, parserThrowError)
import Data.Char (isAlpha, isAlphaNum, isDigit, isUpper)
import Data.ByteString.Builder qualified as Builder
import Data.ByteString.Lazy qualified as LByteString
import Data.Coerce
import Data.DList (DList)
import Data.DList qualified as DList
import Data.DList.DNonEmpty (DNonEmpty)
import Data.DList.DNonEmpty qualified as DNonEmpty
import Data.Fix (Fix (..), Mu, Nu, foldMu, foldNu, unfoldMu, unfoldNu)
import Data.Fixed (Fixed, HasResolution (..), Nano)
import Data.Foldable (toList)
import Data.Function (fix)
import Data.Functor.Compose (Compose (..))
import Data.Functor.Product qualified as Functor
import Data.Functor.Sum qualified as Functor
import Data.Functor.These (These1 (..))
import Data.HashMap.Strict (HashMap)
import Data.HashMap.Strict qualified as HashMap
import Data.HashSet (HashSet)
import Data.HashSet qualified as HashSet
import Data.Hashable (Hashable)
import Data.Int (Int8, Int16, Int32, Int64)
import Data.IntMap (IntMap)
import Data.IntMap qualified as IntMap
import Data.IntSet (IntSet)
import Data.IntSet qualified as IntSet
import Data.Kind
import Data.Type.Bool (type (&&))
import Data.List
  (find, findIndices, intercalate, nub, sortOn, stripPrefix)
import Data.List.NonEmpty (NonEmpty, nonEmpty)
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Maybe
import Data.Monoid (Ap (..))
import Data.Monoid qualified as Monoid
import Data.Ord (Down (..))
import Data.Primitive.Array (Array, arrayFromList, indexArray)
import Data.Primitive.PrimArray (PrimArray)
import Data.Primitive.SmallArray (SmallArray)
import Data.Primitive.Types (Prim)
import Data.Profunctor
import Data.Profunctor.Unsafe ((#.), (.#))
import Data.Proxy (Proxy (..))
import Data.Ratio (Ratio, denominator, numerator, (%))
import Data.Scientific
import Data.SOP (All, K (..), NP, hcollapse, hcpure)
import Data.Semigroup qualified as Semigroup
import Data.Sequence (Seq)
import Data.Sequence qualified as Seq
import Data.Set (Set)
import Data.Set qualified as Set
import Data.Strict qualified as Strict
import Data.String (IsString (..))
import Data.Tagged (Tagged (..))
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Text.Encoding qualified as Text
import Data.Text.Read qualified as TextRead
import Data.Text.Unsafe qualified as Text (lengthWord8)
import Data.Text.Lazy qualified as LText
import Data.Text.Short (ShortText)
import Data.Text.Short qualified as ShortText
import Data.These (These (..))
import Data.Time
  ( CalendarDiffDays (..), CalendarDiffTime (..), Day, DayOfWeek (..)
  , DiffTime, LocalTime, NominalDiffTime, TimeOfDay, UTCTime, ZonedTime
  , defaultTimeLocale, formatTime, parseTimeM
  )
import Data.Time.Calendar.Month (Month)
import Data.Time.Calendar.Quarter (Quarter, QuarterOfYear (..))
import Data.Time.Clock.System (SystemTime (..))
import Data.Time.FromText qualified as TimeText
import Data.Traversable (for)
import Data.Tree (Forest, Tree (..))
import Data.Tuple (Solo (MkSolo), getSolo)
import Data.UUID.Types (UUID)
import Data.UUID.Types qualified as UUID
import Data.Vector (Vector)
import Data.Vector qualified as Vector
import Data.Vector.Mutable qualified as MVector
import Data.Vector.Generic qualified as VG
import Data.Vector.Primitive qualified as VP
import Data.Vector.Storable qualified as VS
import Data.Vector.Unboxed qualified as VU
import Data.Version (Version, parseVersion, showVersion)
import Data.Void (Void, absurd)
import Data.Word (Word8, Word16, Word32, Word64)
import Foreign.C.Types (CTime (..))
import Foreign.Storable (Storable)
import Control.Lens.Grammar.TypeScript
import GHC.Exts qualified as Exts
import GHC.Generics qualified as GHC
import Network.URI (URI)
import Network.URI qualified as URI
import Numeric.Natural (Natural)
import System.IO (Handle, hPutStr)
import Text.ParserCombinators.ReadP (readP_to_S)
import Type.Reflection
import Witherable qualified

-- $setup
-- >>> :set -XDeriveAnyClass -XDerivingStrategies -XDerivingVia
-- >>> :set -XOverloadedStrings -XRequiredTypeArguments -XTypeApplications
-- >>> import Control.Lens.Grammar
-- >>> import Data.Aeson qualified as Aeson
-- >>> import Data.Char (toLower)
-- >>> import Data.Text (Text)
-- >>> import GHC.Generics (Generic)
-- >>> import Data.Aeson.Encoding (encodingToLazyByteString)
-- >>> import Data.ByteString.Lazy.Char8 qualified as LByteString
-- >>> import Data.Aeson.Types (formatError)
-- >>> import System.IO (stdout)
-- >>> let explain err = formatError (jsonErrorPath err) (jsonErrorMessage err)

makePrisms ''Value
makePrisms ''These

-- Json grammars --

{- | A type with a JSON grammar, like @aeson@'s `Aeson.ToJSON`
& `Aeson.FromJSON` together, which every `JsonVal` interprets.
Its methods default to @aeson@'s defaults, & `json` to the
`GHC.Generic` grammar, by @aeson@'s default options.
-}
class Json a where

  -- | `Aeson.toJSON` & `Aeson.parseJSON`, as one grammar.
  json :: JsonVal p => p a a
  default json
    :: forall d f p
     . ( GHC.Generic a, GHC.Rep a ~ GHC.D1 d f, GSum f, Typeable a
       , EnumTag (AllNullary f) a, JsonVal p )
    => p a a
  json = Options -> p a a
forall a (d :: Meta) (f :: * -> *) (p :: * -> * -> *).
(Generic a, Rep a ~ D1 d f, GSum f, Typeable a,
 EnumTag (AllNullary f) a, JsonVal p) =>
Options -> p a a
jsonGeneric Options
Aeson.defaultOptions
  {-# INLINABLE json #-}

  {- | `Data.Aeson.toJSONList` & `Data.Aeson.parseJSONList`,
  as one grammar, an array of values by default.
  `Char` and wrappers override it, so that a t'String' is a JSON string.
  -}
  jsonList :: JsonVal p => p [a] [a]
  jsonList = p a a -> p [a] [a]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
  {-# INLINE jsonList #-}

  {- | `Data.Aeson.toJSONKey` & `Data.Aeson.parseJSONKey`
  as one grammar for the text keys of objects,
  or else `Nothing` for the keys of arrays of pairs.
  -}
  jsonKey :: Maybe (forall k. JsonStr k => k a a)
  jsonKey = Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
forall a. Maybe a
Nothing

  {- | `Data.Aeson.toJSONKeyList` & `Data.Aeson.parseJSONKeyList`
  as one grammar for keys of lists, like `jsonList`.
  `Char` and wrappers override it.
  -}
  jsonKeyList :: Maybe (forall k. JsonStr k => k [a] [a])
  jsonKeyList = Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
forall a. Maybe a
Nothing

  {- | `Data.Aeson.omitField` & `Data.Aeson.omittedField` together,
  as the value of a record's field which may be omitted, like `nearly`:
  it matches the value omitted by `Data.Aeson.omitNothingFields`,
  & reviews the value of a field omitted by `Data.Aeson.allowOmittedFields`.
  -}
  jsonOmitField :: Maybe (APrism' a ())
  jsonOmitField = Maybe (APrism' a ())
forall a. Maybe a
Nothing

-- Running Json grammars --

-- | `Data.Aeson.parseJSON`
jsonParse :: Json a => Value -> Either JsonError a
jsonParse :: forall a. Json a => Value -> Either JsonError a
jsonParse = JsonParsor a a -> Value -> Either JsonError a
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json

{- | `Data.Aeson.eitherDecode`, which reads the JSON text by @aeson@,
failing by its message for text which isn't JSON.
-}
jsonDecode :: Json a => LByteString.ByteString -> Either JsonError a
jsonDecode :: forall a. Json a => ByteString -> Either JsonError a
jsonDecode ByteString
bytes = case ByteString -> Either String Value
forall a. FromJSON a => ByteString -> Either String a
Aeson.eitherDecode ByteString
bytes of
  Left String
syntax -> JsonError -> Either JsonError a
forall a b. a -> Either a b
Left ([JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [] [] (Either String Value -> Maybe (Either String Value)
forall a. a -> Maybe a
Just (String -> Either String Value
forall a b. a -> Either a b
Left String
syntax)) JsonErrorSort
JsonMismatch [])
  Right Value
v -> Value -> Either JsonError a
forall a. Json a => Value -> Either JsonError a
jsonParse Value
v

-- | `Data.Aeson.toJSON`
jsonPrint :: Json a => a -> Value
jsonPrint :: forall a. Json a => a -> Value
jsonPrint = (JsonError -> Value)
-> (Value -> Value) -> Either JsonError Value -> Value
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\JsonError
_ -> Value
Null) Value -> Value
forall a. a -> a
id (Either JsonError Value -> Value)
-> (a -> Either JsonError Value) -> a -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either JsonError Value
forall a. Json a => a -> Either JsonError Value
jsonErrorPrint

{- | `jsonPrint`, failing where the grammar doesn't print a value,
like a key which repeats.

>>> jsonErrorPrint (1 :: Int)
Right (Number 1.0)
-}
jsonErrorPrint :: Json a => a -> Either JsonError Value
jsonErrorPrint :: forall a. Json a => a -> Either JsonError Value
jsonErrorPrint = JsonPrintor Value a a -> a -> Either JsonError Value
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
runJsonPrintor JsonPrintor Value a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json

-- | `Data.Aeson.toEncoding`
jsonEncode :: Json a => a -> Encoding
jsonEncode :: forall a. Json a => a -> Encoding
jsonEncode = (JsonError -> Encoding)
-> (Encoding -> Encoding) -> Either JsonError Encoding -> Encoding
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\JsonError
_ -> Encoding
Encoding.null_) Encoding -> Encoding
forall a. a -> a
id (Either JsonError Encoding -> Encoding)
-> (a -> Either JsonError Encoding) -> a -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either JsonError Encoding
forall a. Json a => a -> Either JsonError Encoding
jsonErrorEncode
{-# INLINE jsonEncode #-}

-- | `jsonEncode`, failing where the grammar doesn't print a value.
jsonErrorEncode :: Json a => a -> Either JsonError Encoding
jsonErrorEncode :: forall a. Json a => a -> Either JsonError Encoding
jsonErrorEncode = JsonPrintor Encoding a a -> a -> Either JsonError Encoding
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
runJsonPrintor JsonPrintor Encoding a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
{-# INLINE jsonErrorEncode #-}

{- | @aeson@'s instances, derived from a `Json` instance, failing to parse
at the path of a t'JsonError', by its message: `Aeson.ToJSON` &
`Aeson.FromJSON`, with their fields omitted by `jsonOmitField`, &
`Aeson.ToJSONKey` & `Aeson.FromJSONKey`, by `jsonKey` & `jsonKeyList`,
or else as values, in arrays of pairs.

> data Point = Point {x :: Int, y :: Int}
>   deriving stock Generic
>   deriving anyclass Json
>   deriving (ToJSON, FromJSON) via ViaJson Point
-}
newtype ViaJson a = ViaJson a
  deriving stock (ViaJson a -> ViaJson a -> Bool
(ViaJson a -> ViaJson a -> Bool)
-> (ViaJson a -> ViaJson a -> Bool) -> Eq (ViaJson a)
forall a. Eq a => ViaJson a -> ViaJson a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => ViaJson a -> ViaJson a -> Bool
== :: ViaJson a -> ViaJson a -> Bool
$c/= :: forall a. Eq a => ViaJson a -> ViaJson a -> Bool
/= :: ViaJson a -> ViaJson a -> Bool
Eq, Eq (ViaJson a)
Eq (ViaJson a) =>
(ViaJson a -> ViaJson a -> Ordering)
-> (ViaJson a -> ViaJson a -> Bool)
-> (ViaJson a -> ViaJson a -> Bool)
-> (ViaJson a -> ViaJson a -> Bool)
-> (ViaJson a -> ViaJson a -> Bool)
-> (ViaJson a -> ViaJson a -> ViaJson a)
-> (ViaJson a -> ViaJson a -> ViaJson a)
-> Ord (ViaJson a)
ViaJson a -> ViaJson a -> Bool
ViaJson a -> ViaJson a -> Ordering
ViaJson a -> ViaJson a -> ViaJson a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (ViaJson a)
forall a. Ord a => ViaJson a -> ViaJson a -> Bool
forall a. Ord a => ViaJson a -> ViaJson a -> Ordering
forall a. Ord a => ViaJson a -> ViaJson a -> ViaJson a
$ccompare :: forall a. Ord a => ViaJson a -> ViaJson a -> Ordering
compare :: ViaJson a -> ViaJson a -> Ordering
$c< :: forall a. Ord a => ViaJson a -> ViaJson a -> Bool
< :: ViaJson a -> ViaJson a -> Bool
$c<= :: forall a. Ord a => ViaJson a -> ViaJson a -> Bool
<= :: ViaJson a -> ViaJson a -> Bool
$c> :: forall a. Ord a => ViaJson a -> ViaJson a -> Bool
> :: ViaJson a -> ViaJson a -> Bool
$c>= :: forall a. Ord a => ViaJson a -> ViaJson a -> Bool
>= :: ViaJson a -> ViaJson a -> Bool
$cmax :: forall a. Ord a => ViaJson a -> ViaJson a -> ViaJson a
max :: ViaJson a -> ViaJson a -> ViaJson a
$cmin :: forall a. Ord a => ViaJson a -> ViaJson a -> ViaJson a
min :: ViaJson a -> ViaJson a -> ViaJson a
Ord, Int -> ViaJson a -> ShowS
[ViaJson a] -> ShowS
ViaJson a -> String
(Int -> ViaJson a -> ShowS)
-> (ViaJson a -> String)
-> ([ViaJson a] -> ShowS)
-> Show (ViaJson a)
forall a. Show a => Int -> ViaJson a -> ShowS
forall a. Show a => [ViaJson a] -> ShowS
forall a. Show a => ViaJson a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> ViaJson a -> ShowS
showsPrec :: Int -> ViaJson a -> ShowS
$cshow :: forall a. Show a => ViaJson a -> String
show :: ViaJson a -> String
$cshowList :: forall a. Show a => [ViaJson a] -> ShowS
showList :: [ViaJson a] -> ShowS
Show)

instance Json a => Aeson.ToJSON (ViaJson a) where
  toJSON :: ViaJson a -> Value
toJSON (ViaJson a
a) = a -> Value
forall a. Json a => a -> Value
jsonPrint a
a
  toEncoding :: ViaJson a -> Encoding
toEncoding (ViaJson a
a) = a -> Encoding
forall a. Json a => a -> Encoding
jsonEncode a
a
  toJSONList :: [ViaJson a] -> Value
toJSONList [ViaJson a]
vs = (JsonError -> Value)
-> (Value -> Value) -> Either JsonError Value -> Value
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\JsonError
_ -> Value
Null) Value -> Value
forall a. a -> a
id
    (JsonPrintor Value [a] [a] -> [a] -> Either JsonError Value
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
runJsonPrintor (forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a) ([ViaJson a] -> [a]
forall a b. Coercible a b => a -> b
coerce [ViaJson a]
vs))
  toEncodingList :: [ViaJson a] -> Encoding
toEncodingList [ViaJson a]
vs = (JsonError -> Encoding)
-> (Encoding -> Encoding) -> Either JsonError Encoding -> Encoding
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\JsonError
_ -> Encoding
Encoding.null_) Encoding -> Encoding
forall a. a -> a
id
    (JsonPrintor Encoding [a] [a] -> [a] -> Either JsonError Encoding
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
runJsonPrintor (forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a) ([ViaJson a] -> [a]
forall a b. Coercible a b => a -> b
coerce [ViaJson a]
vs))
  omitField :: ViaJson a -> Bool
omitField (ViaJson a
a) = case forall a. Json a => Maybe (APrism' a ())
jsonOmitField @a of
    Just APrism' a ()
omitted -> APrism' a () -> ((() -> a) -> (a -> Either a ()) -> Bool) -> Bool
forall s t a b r.
APrism s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r
withPrism APrism' a ()
omitted (((() -> a) -> (a -> Either a ()) -> Bool) -> Bool)
-> ((() -> a) -> (a -> Either a ()) -> Bool) -> Bool
forall a b. (a -> b) -> a -> b
$ \() -> a
_ a -> Either a ()
match ->
      (a -> Bool) -> (() -> Bool) -> Either a () -> Bool
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Bool -> a -> Bool
forall a b. a -> b -> a
const Bool
False) (Bool -> () -> Bool
forall a b. a -> b -> a
const Bool
True) (a -> Either a ()
match a
a)
    Maybe (APrism' a ())
Nothing -> Bool
False
instance Json a => Aeson.FromJSON (ViaJson a) where
  parseJSON :: Value -> Parser (ViaJson a)
parseJSON = (JsonError -> Parser (ViaJson a))
-> (a -> Parser (ViaJson a))
-> Either JsonError a
-> Parser (ViaJson a)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either JsonError -> Parser (ViaJson a)
forall x. JsonError -> Parser x
parseFailure (ViaJson a -> Parser (ViaJson a)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ViaJson a -> Parser (ViaJson a))
-> (a -> ViaJson a) -> a -> Parser (ViaJson a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ViaJson a
forall a. a -> ViaJson a
ViaJson) (Either JsonError a -> Parser (ViaJson a))
-> (Value -> Either JsonError a) -> Value -> Parser (ViaJson a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Either JsonError a
forall a. Json a => Value -> Either JsonError a
jsonParse
  parseJSONList :: Value -> Parser [ViaJson a]
parseJSONList =
    (JsonError -> Parser [ViaJson a])
-> ([a] -> Parser [ViaJson a])
-> Either JsonError [a]
-> Parser [ViaJson a]
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either JsonError -> Parser [ViaJson a]
forall x. JsonError -> Parser x
parseFailure ([ViaJson a] -> Parser [ViaJson a]
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ViaJson a] -> Parser [ViaJson a])
-> ([a] -> [ViaJson a]) -> [a] -> Parser [ViaJson a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [ViaJson a]
forall a b. Coercible a b => a -> b
coerce) (Either JsonError [a] -> Parser [ViaJson a])
-> (Value -> Either JsonError [a]) -> Value -> Parser [ViaJson a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonParsor [a] [a] -> Value -> Either JsonError [a]
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor (forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a)
  omittedField :: Maybe (ViaJson a)
omittedField = case forall a. Json a => Maybe (APrism' a ())
jsonOmitField @a of
    Just APrism' a ()
omitted -> APrism' a ()
-> ((() -> a) -> (a -> Either a ()) -> Maybe (ViaJson a))
-> Maybe (ViaJson a)
forall s t a b r.
APrism s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r
withPrism APrism' a ()
omitted (((() -> a) -> (a -> Either a ()) -> Maybe (ViaJson a))
 -> Maybe (ViaJson a))
-> ((() -> a) -> (a -> Either a ()) -> Maybe (ViaJson a))
-> Maybe (ViaJson a)
forall a b. (a -> b) -> a -> b
$ \() -> a
omit a -> Either a ()
_ -> ViaJson a -> Maybe (ViaJson a)
forall a. a -> Maybe a
Just (a -> ViaJson a
forall a. a -> ViaJson a
ViaJson (() -> a
omit ()))
    Maybe (APrism' a ())
Nothing -> Maybe (ViaJson a)
forall a. Maybe a
Nothing
instance Json a => Aeson.ToJSONKey (ViaJson a) where
  toJSONKey :: ToJSONKeyFunction (ViaJson a)
toJSONKey = case forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
jsonKey @a of
    Just forall (k :: * -> * -> *). JsonStr k => k a a
key -> (forall (k :: * -> * -> *). JsonStr k => k (ViaJson a) (ViaJson a))
-> ToJSONKeyFunction (ViaJson a)
forall a.
(forall (k :: * -> * -> *). JsonStr k => k a a)
-> ToJSONKeyFunction a
keyText (Exchange a a a (Identity a)
-> Exchange a a (ViaJson a) (Identity (ViaJson a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (ViaJson a) (ViaJson a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (ViaJson a) (Identity (ViaJson a)))
-> k a a -> k (ViaJson a) (ViaJson a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ k a a
forall (k :: * -> * -> *). JsonStr k => k a a
key)
    Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
Nothing -> (ViaJson a -> Value)
-> (ViaJson a -> Encoding) -> ToJSONKeyFunction (ViaJson a)
forall a. (a -> Value) -> (a -> Encoding) -> ToJSONKeyFunction a
Aeson.ToJSONKeyValue ViaJson a -> Value
forall a. ToJSON a => a -> Value
Aeson.toJSON ViaJson a -> Encoding
forall a. ToJSON a => a -> Encoding
Aeson.toEncoding
  toJSONKeyList :: ToJSONKeyFunction [ViaJson a]
toJSONKeyList = case forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
jsonKeyList @a of
    Just forall (k :: * -> * -> *). JsonStr k => k [a] [a]
key -> (forall (k :: * -> * -> *). JsonStr k => k [ViaJson a] [ViaJson a])
-> ToJSONKeyFunction [ViaJson a]
forall a.
(forall (k :: * -> * -> *). JsonStr k => k a a)
-> ToJSONKeyFunction a
keyText (Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [ViaJson a] (Identity [ViaJson a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [ViaJson a] [ViaJson a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [ViaJson a] (Identity [ViaJson a]))
-> k [a] [a] -> k [ViaJson a] [ViaJson a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ k [a] [a]
forall (k :: * -> * -> *). JsonStr k => k [a] [a]
key)
    Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
Nothing -> ([ViaJson a] -> Value)
-> ([ViaJson a] -> Encoding) -> ToJSONKeyFunction [ViaJson a]
forall a. (a -> Value) -> (a -> Encoding) -> ToJSONKeyFunction a
Aeson.ToJSONKeyValue [ViaJson a] -> Value
forall a. ToJSON a => a -> Value
Aeson.toJSON [ViaJson a] -> Encoding
forall a. ToJSON a => a -> Encoding
Aeson.toEncoding
instance Json a => Aeson.FromJSONKey (ViaJson a) where
  fromJSONKey :: FromJSONKeyFunction (ViaJson a)
fromJSONKey = case forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
jsonKey @a of
    Just forall (k :: * -> * -> *). JsonStr k => k a a
key -> (forall (k :: * -> * -> *). JsonStr k => k (ViaJson a) (ViaJson a))
-> FromJSONKeyFunction (ViaJson a)
forall a.
(forall (k :: * -> * -> *). JsonStr k => k a a)
-> FromJSONKeyFunction a
keyParser (Exchange a a a (Identity a)
-> Exchange a a (ViaJson a) (Identity (ViaJson a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (ViaJson a) (ViaJson a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (ViaJson a) (Identity (ViaJson a)))
-> k a a -> k (ViaJson a) (ViaJson a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ k a a
forall (k :: * -> * -> *). JsonStr k => k a a
key)
    Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
Nothing -> (Value -> Parser (ViaJson a)) -> FromJSONKeyFunction (ViaJson a)
forall a. (Value -> Parser a) -> FromJSONKeyFunction a
Aeson.FromJSONKeyValue Value -> Parser (ViaJson a)
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON
  fromJSONKeyList :: FromJSONKeyFunction [ViaJson a]
fromJSONKeyList = case forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
jsonKeyList @a of
    Just forall (k :: * -> * -> *). JsonStr k => k [a] [a]
key -> (forall (k :: * -> * -> *). JsonStr k => k [ViaJson a] [ViaJson a])
-> FromJSONKeyFunction [ViaJson a]
forall a.
(forall (k :: * -> * -> *). JsonStr k => k a a)
-> FromJSONKeyFunction a
keyParser (Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [ViaJson a] (Identity [ViaJson a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [ViaJson a] [ViaJson a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [ViaJson a] (Identity [ViaJson a]))
-> k [a] [a] -> k [ViaJson a] [ViaJson a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ k [a] [a]
forall (k :: * -> * -> *). JsonStr k => k [a] [a]
key)
    Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
Nothing -> (Value -> Parser [ViaJson a]) -> FromJSONKeyFunction [ViaJson a]
forall a. (Value -> Parser a) -> FromJSONKeyFunction a
Aeson.FromJSONKeyValue Value -> Parser [ViaJson a]
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON

-- | Print a key's text, by a key grammar.
keyText
  :: (forall k. JsonStr k => k a a) -> Aeson.ToJSONKeyFunction a
keyText :: forall a.
(forall (k :: * -> * -> *). JsonStr k => k a a)
-> ToJSONKeyFunction a
keyText forall (k :: * -> * -> *). JsonStr k => k a a
key =
  (a -> Key) -> (a -> Encoding' Key) -> ToJSONKeyFunction a
forall a. (a -> Key) -> (a -> Encoding' Key) -> ToJSONKeyFunction a
Aeson.ToJSONKeyText (KeyPrintor Key a a -> a -> Key
forall key a b. KeyPrintor key a b -> a -> key
runKeyPrintor KeyPrintor Key a a
forall (k :: * -> * -> *). JsonStr k => k a a
key) (KeyPrintor (Encoding' Key) a a -> a -> Encoding' Key
forall key a b. KeyPrintor key a b -> a -> key
runKeyPrintor KeyPrintor (Encoding' Key) a a
forall (k :: * -> * -> *). JsonStr k => k a a
key)

-- | Parse a key's text, by a key grammar.
keyParser
  :: (forall k. JsonStr k => k a a) -> Aeson.FromJSONKeyFunction a
keyParser :: forall a.
(forall (k :: * -> * -> *). JsonStr k => k a a)
-> FromJSONKeyFunction a
keyParser forall (k :: * -> * -> *). JsonStr k => k a a
key = (Text -> Parser a) -> FromJSONKeyFunction a
forall a. (Text -> Parser a) -> FromJSONKeyFunction a
Aeson.FromJSONKeyTextParser
  ((JsonError -> Parser a)
-> (a -> Parser a) -> Either JsonError a -> Parser a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either JsonError -> Parser a
forall x. JsonError -> Parser x
parseFailure a -> Parser a
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either JsonError a -> Parser a)
-> (Text -> Either JsonError a) -> Text -> Parser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonParsor a a -> Value -> Either JsonError a
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a a
forall (k :: * -> * -> *). JsonStr k => k a a
key (Value -> Either JsonError a)
-> (Text -> Value) -> Text -> Either JsonError a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Value
String)

-- | Fail to parse at the path of a t'JsonError', by its message.
parseFailure :: JsonError -> Aeson.Parser x
parseFailure :: forall x. JsonError -> Parser x
parseFailure JsonError
err =
  [JSONPathElement] -> String -> Parser x
forall a. [JSONPathElement] -> String -> Parser a
Aeson.parserThrowError (JsonError -> [JSONPathElement]
jsonErrorPath JsonError
err) (JsonError -> String
jsonErrorMessage JsonError
err)

{- | `JsonVal` grammars describe JSON values: @null@, booleans, numbers,
strings, by `JsonStr`, arrays & objects, by `JsonTup` & `JsonObj`.
As `CocartesianChoice`s & `Filtrator`s, they have alternatives
(`>+<`, `>|<`) & partial isomorphisms (`>?`, `?<`).
Its numbers are bounded, & its integers integral, as @aeson@'s are.
-}
class
  ( CocartesianChoice p
  , Filtrator p
  , JsonStr p
  ) => JsonVal p where
  jsonNull :: p () ()
  jsonBool :: p Bool Bool
  jsonNumber :: p Scientific Scientific
  jsonInt :: p Int Int
  jsonInt = p Int Int
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonInt8 :: p Int8 Int8
  jsonInt8 = p Int8 Int8
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonInt16 :: p Int16 Int16
  jsonInt16 = p Int16 Int16
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonInt32 :: p Int32 Int32
  jsonInt32 = p Int32 Int32
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonInt64 :: p Int64 Int64
  jsonInt64 = p Int64 Int64
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonWord :: p Word Word
  jsonWord = p Word Word
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonWord8 :: p Word8 Word8
  jsonWord8 = p Word8 Word8
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonWord16 :: p Word16 Word16
  jsonWord16 = p Word16 Word16
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonWord32 :: p Word32 Word32
  jsonWord32 = p Word32 Word32
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonWord64 :: p Word64 Word64
  jsonWord64 = p Word64 Word64
forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger
  jsonInteger :: p Integer Integer
  jsonInteger = Market Integer Integer Integer (Identity Integer)
-> Market Integer Integer Scientific (Identity Scientific)
Prism' Scientific Integer
_Integer (Market Integer Integer Integer (Identity Integer)
 -> Market Integer Integer Scientific (Identity Scientific))
-> p Scientific Scientific -> p Integer Integer
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Scientific Scientific
forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
jsonNumber
  jsonNatural :: p Natural Natural
  jsonNatural = Market Natural Natural Natural (Identity Natural)
-> Market Natural Natural Scientific (Identity Scientific)
Prism' Scientific Natural
_Natural (Market Natural Natural Natural (Identity Natural)
 -> Market Natural Natural Scientific (Identity Scientific))
-> p Scientific Scientific -> p Natural Natural
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Scientific Scientific
forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
jsonNumber
  jsonDouble :: p Double Double
  jsonDouble = (Double -> Scientific)
-> (Scientific -> Double)
-> Iso Double Double Scientific Scientific
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Double -> Scientific
forall a. RealFloat a => a -> Scientific
fromFloatDigits Scientific -> Double
forall a. RealFloat a => Scientific -> a
toRealFloat (Exchange Scientific Scientific Scientific (Identity Scientific)
 -> Exchange Scientific Scientific Double (Identity Double))
-> p Scientific Scientific -> p Double Double
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p Scientific Scientific
forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
jsonNumber
  {- | A homogeneous JSON array, like TypeScript's @T[]@, which is a tuple
  of a rest element, though interpreters may define it more efficiently.

  @jsonArray p = jsonTuple (manyP (jsonElem p))@
  -}
  jsonArray :: p a b -> p [a] [b]
  jsonArray p a b
p = (forall (q :: * -> * -> *). JsonTup p q => q [a] [b]) -> p [a] [b]
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple (q a b -> q [a] [b]
forall a b. q a b -> q [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP (p a b -> q a b
forall a b. p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonTup p q =>
p a b -> q a b
jsonElem p a b
p))
  {- | @null@ or a value, like @aeson@'s `Maybe`,
  though interpreters may define it more efficiently.

  @jsonNullable p = eotMaybe >~ jsonNull >+< p@
  -}
  jsonNullable :: p a b -> p (Maybe a) (Maybe b)
  jsonNullable p a b
p = Exchange
  (Either () a) (Either () b) (Either () a) (Identity (Either () b))
-> Exchange
     (Either () a) (Either () b) (Maybe a) (Identity (Maybe b))
forall a b (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Functor f) =>
p (Either () a) (f (Either () b)) -> p (Maybe a) (f (Maybe b))
eotMaybe (Exchange
   (Either () a) (Either () b) (Either () a) (Identity (Either () b))
 -> Exchange
      (Either () a) (Either () b) (Maybe a) (Identity (Maybe b)))
-> p (Either () a) (Either () b) -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p () ()
forall (p :: * -> * -> *). JsonVal p => p () ()
jsonNull p () () -> p a b -> p (Either () a) (Either () b)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p a b
p
  {- | A pair, as an array of its two elements,
  though interpreters may define it more efficiently.

  @jsonPair p q = jsonTuple (jsonElem p >*< jsonElem q)@
  -}
  jsonPair :: p a b -> p c d -> p (a, c) (b, d)
  jsonPair p a b
p p c d
q = (forall (q :: * -> * -> *). JsonTup p q => q (a, c) (b, d))
-> p (a, c) (b, d)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple (p a b -> q a b
forall a b. p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonTup p q =>
p a b -> q a b
jsonElem p a b
p q a b -> q c d -> q (a, c) (b, d)
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< p c d -> q c d
forall a b. p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonTup p q =>
p a b -> q a b
jsonElem p c d
q)
  {- | An object of a single property, as @aeson@ tags `Either`'s & sums'
  values, though interpreters may define it more efficiently.

  @jsonTag k p = jsonObjectStrict (k !: p)@
  -}
  jsonTag :: Text -> p a b -> p a b
  jsonTag Text
k p a b
p = (forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObjectStrict (Text
k Text -> p a b -> q a b
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p a b
p)
  {- | A `jsonDict` object of a `Map`, whose keys can't repeat,
  so that printing needn't check them.
  -}
  jsonMap
    :: Ord b
    => (forall k. JsonStr k => k a b)
    -> p c d -> p (Map a c) (Map b d)
  jsonMap forall (k :: * -> * -> *). JsonStr k => k a b
key p c d
p = (Map a c -> [(a, c)])
-> ([(b, d)] -> Map b d)
-> p [(a, c)] [(b, d)]
-> p (Map a c) (Map b d)
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 Map a c -> [(a, c)]
forall k a. Map k a -> [(k, a)]
Map.toList [(b, d)] -> Map b d
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ((forall (q :: * -> * -> *). JsonObj p q => q [(a, c)] [(b, d)])
-> p [(a, c)] [(b, d)]
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject ((forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
forall a b c d.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
forall (p :: * -> * -> *) (q :: * -> * -> *) a b c d.
JsonObj p q =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
jsonDict k a b
forall (k :: * -> * -> *). JsonStr k => k a b
key p c d
p))
  {- | A `jsonDict` object of a `HashMap`, whose keys can't repeat,
  so that printing needn't check them.
  -}
  jsonHashMap
    :: (Eq b, Hashable b)
    => (forall k. JsonStr k => k a b)
    -> p c d -> p (HashMap a c) (HashMap b d)
  jsonHashMap forall (k :: * -> * -> *). JsonStr k => k a b
key p c d
p =
    (HashMap a c -> [(a, c)])
-> ([(b, d)] -> HashMap b d)
-> p [(a, c)] [(b, d)]
-> p (HashMap a c) (HashMap b d)
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 HashMap a c -> [(a, c)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList [(b, d)] -> HashMap b d
forall k v. Hashable k => [(k, v)] -> HashMap k v
HashMap.fromList ((forall (q :: * -> * -> *). JsonObj p q => q [(a, c)] [(b, d)])
-> p [(a, c)] [(b, d)]
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject ((forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
forall a b c d.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
forall (p :: * -> * -> *) (q :: * -> * -> *) a b c d.
JsonObj p q =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
jsonDict k a b
forall (k :: * -> * -> *). JsonStr k => k a b
key p c d
p))
  jsonTuple :: (forall q. JsonTup p q => q a b) -> p a b
  jsonObject :: (forall q. JsonObj p q => q a b) -> p a b
  -- | A `jsonObject` which rejects the properties that it doesn't name.
  jsonObjectStrict :: (forall q. JsonObj p q => q a b) -> p a b
  jsonObjectStrict forall (q :: * -> * -> *). JsonObj p q => q a b
obj =
    (forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject (q a b
forall (q :: * -> * -> *). JsonObj p q => q a b
obj q a b -> q () () -> q a b
forall (p :: * -> * -> *) a b c.
Monoidal p =>
p a b -> p () c -> p a b
*< (() -> [(Text, Void)])
-> ([(Text, Void)] -> ())
-> q [(Text, Void)] [(Text, Void)]
-> q () ()
forall a b c d. (a -> b) -> (c -> d) -> q b c -> q a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap ([(Text, Void)] -> () -> [(Text, Void)]
forall a b. a -> b -> a
const []) (() -> [(Text, Void)] -> ()
forall a b. a -> b -> a
const ()) ((forall (k :: * -> * -> *). JsonStr k => k Text Text)
-> p Void Void -> q [(Text, Void)] [(Text, Void)]
forall a b c d.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
forall (p :: * -> * -> *) (q :: * -> * -> *) a b c d.
JsonObj p q =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
jsonDict k Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText p Void Void
forall (p :: * -> * -> *). CocartesianMonoidal p => p Void Void
zeroP))
  jsonValue :: p Value Value
  jsonValue = p Value Value -> p Value Value
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (p Value Value -> p Value Value) -> p Value Value -> p Value Value
forall a b. (a -> b) -> a -> b
$ [p Value Value] -> p Value Value
forall (f :: * -> *) a.
(Foldable f, DisjunctiveMonoid a) =>
f a -> a
orP
    [ Market () () () (Identity ())
-> Market () () Value (Identity Value)
Prism' Value ()
_Null (Market () () () (Identity ())
 -> Market () () Value (Identity Value))
-> p () () -> p Value Value
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? p () ()
forall (p :: * -> * -> *). JsonVal p => p () ()
jsonNull
    , Market Bool Bool Bool (Identity Bool)
-> Market Bool Bool Value (Identity Value)
Prism' Value Bool
_Bool (Market Bool Bool Bool (Identity Bool)
 -> Market Bool Bool Value (Identity Value))
-> p Bool Bool -> p Value Value
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? p Bool Bool
forall (p :: * -> * -> *). JsonVal p => p Bool Bool
jsonBool
    , Market Scientific Scientific Scientific (Identity Scientific)
-> Market Scientific Scientific Value (Identity Value)
Prism' Value Scientific
_Number (Market Scientific Scientific Scientific (Identity Scientific)
 -> Market Scientific Scientific Value (Identity Value))
-> p Scientific Scientific -> p Value Value
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? p Scientific Scientific
forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
jsonNumber
    , Market Text Text Text (Identity Text)
-> Market Text Text Value (Identity Value)
Prism' Value Text
_String (Market Text Text Text (Identity Text)
 -> Market Text Text Value (Identity Value))
-> p Text Text -> p Value Value
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
    , Market [Value] [Value] Array (Identity Array)
-> Market [Value] [Value] Value (Identity Value)
Prism' Value Array
_Array (Market [Value] [Value] Array (Identity Array)
 -> Market [Value] [Value] Value (Identity Value))
-> (Market [Value] [Value] [Value] (Identity [Value])
    -> Market [Value] [Value] Array (Identity Array))
-> Market [Value] [Value] [Value] (Identity [Value])
-> Market [Value] [Value] Value (Identity Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Array -> [Value])
-> ([Value] -> Array) -> Iso Array Array [Value] [Value]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Array -> [Value]
forall a. Vector a -> [a]
Vector.toList [Value] -> Array
forall a. [a] -> Vector a
Vector.fromList (Market [Value] [Value] [Value] (Identity [Value])
 -> Market [Value] [Value] Value (Identity Value))
-> p [Value] [Value] -> p Value Value
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? p Value Value -> p [Value] [Value]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p Value Value
forall (p :: * -> * -> *). JsonVal p => p Value Value
jsonValue
    , Market [(Key, Value)] [(Key, Value)] Object (Identity Object)
-> Market [(Key, Value)] [(Key, Value)] Value (Identity Value)
Prism' Value Object
_Object (Market [(Key, Value)] [(Key, Value)] Object (Identity Object)
 -> Market [(Key, Value)] [(Key, Value)] Value (Identity Value))
-> (Market
      [(Key, Value)]
      [(Key, Value)]
      [(Key, Value)]
      (Identity [(Key, Value)])
    -> Market [(Key, Value)] [(Key, Value)] Object (Identity Object))
-> Market
     [(Key, Value)]
     [(Key, Value)]
     [(Key, Value)]
     (Identity [(Key, Value)])
-> Market [(Key, Value)] [(Key, Value)] Value (Identity Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Object -> [(Key, Value)])
-> ([(Key, Value)] -> Object)
-> Iso Object Object [(Key, Value)] [(Key, Value)]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Object -> [(Key, Value)]
forall v. KeyMap v -> [(Key, v)]
KeyMap.toList [(Key, Value)] -> Object
forall v. [(Key, v)] -> KeyMap v
KeyMap.fromList
      (Market
   [(Key, Value)]
   [(Key, Value)]
   [(Key, Value)]
   (Identity [(Key, Value)])
 -> Market [(Key, Value)] [(Key, Value)] Value (Identity Value))
-> p [(Key, Value)] [(Key, Value)] -> p Value Value
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? (forall (q :: * -> * -> *).
 JsonObj p q =>
 q [(Key, Value)] [(Key, Value)])
-> p [(Key, Value)] [(Key, Value)]
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject ((forall (k :: * -> * -> *). JsonStr k => k Key Key)
-> p Value Value -> q [(Key, Value)] [(Key, Value)]
forall a b c d.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
forall (p :: * -> * -> *) (q :: * -> * -> *) a b c d.
JsonObj p q =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
jsonDict k Key Key
forall (k :: * -> * -> *). JsonStr k => k Key Key
jsonKeyText p Value Value
forall (p :: * -> * -> *). JsonVal p => p Value Value
jsonValue)
    ]

{- | A rule name's display, with its module-qualified words unqualified,
by the naming convention of `Control.Lens.Grammar.BackusNaur.ruleTyped`.
-}
unqualified :: String -> String
unqualified :: ShowS
unqualified = \case
  [] -> []
  s :: String
s@(Char
c : String
rest)
    | Char -> Bool
isUpper Char
c, (Char
_ : String
_, Char
'.' : after :: String
after@(Char
_ : String
_)) <- (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
span Char -> Bool
identifier String
s ->
        ShowS
unqualified String
after
    | Char -> Bool
identifier Char
c -> let (String
word, String
others) = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
span Char -> Bool
identifier String
s in
        String
word String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ShowS
unqualified String
others
    | Bool
otherwise -> Char
c Char -> ShowS
forall a. a -> [a] -> [a]
: ShowS
unqualified String
rest
  where
    identifier :: Char -> Bool
identifier Char
c = Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\''

{- |
@fromString s = only s ?< jsonString@

@jsonString = iso Text.pack Text.unpack >~ jsonText@
-}
class
  ( Cochoice p
  , forall x y. (x ~ (), y ~ ()) => IsString (p x y)
  , forall x y. BackusNaurForm (p x y)
  ) => JsonStr p where
  jsonText :: p Text Text
  jsonString :: p String String
  jsonString = (String -> Text) -> (Text -> String) -> Iso String String Text Text
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso String -> Text
Text.pack Text -> String
Text.unpack (Exchange Text Text Text (Identity Text)
 -> Exchange Text Text String (Identity String))
-> p Text Text -> p String String
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
  {- | A string matched from its `Text`, which is reviewed lazily
  as both its `Text` & an @aeson@ string `Encoding.Encoding'`,
  either of which an interpreter uses.
  -}
  jsonEncodedText
    :: APrism Text (Text, Encoding.Encoding' Text) a a -> p a a
  jsonEncodedText APrism Text (Text, Encoding' Text) a a
encoding = APrism Text (Text, Encoding' Text) a a
-> ((a -> (Text, Encoding' Text))
    -> (Text -> Either (Text, Encoding' Text) a) -> p a a)
-> p a a
forall s t a b r.
APrism s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r
withPrism APrism Text (Text, Encoding' Text) a a
encoding (((a -> (Text, Encoding' Text))
  -> (Text -> Either (Text, Encoding' Text) a) -> p a a)
 -> p a a)
-> ((a -> (Text, Encoding' Text))
    -> (Text -> Either (Text, Encoding' Text) a) -> p a a)
-> p a a
forall a b. (a -> b) -> a -> b
$ \a -> (Text, Encoding' Text)
encode Text -> Either (Text, Encoding' Text) a
match ->
    (a -> Text) -> (Text -> Maybe a) -> Prism Text Text a a
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((Text, Encoding' Text) -> Text
forall a b. (a, b) -> a
fst ((Text, Encoding' Text) -> Text)
-> (a -> (Text, Encoding' Text)) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> (Text, Encoding' Text)
encode) (((Text, Encoding' Text) -> Maybe a)
-> (a -> Maybe a) -> Either (Text, Encoding' Text) a -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe a -> (Text, Encoding' Text) -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing) a -> Maybe a
forall a. a -> Maybe a
Just (Either (Text, Encoding' Text) a -> Maybe a)
-> (Text -> Either (Text, Encoding' Text) a) -> Text -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either (Text, Encoding' Text) a
match) (Market a a a (Identity a) -> Market a a Text (Identity Text))
-> p Text Text -> p a a
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
  {- | An enumeration of strings, which a map's key may be,
  like TypeScript's union of string literals, @"a" | "b"@,
  by a table of strings & their values, & the index of each value in it,
  so that printing needn't search it.
  -}
  jsonEnumWith :: (a -> Int) -> [(Text, a)] -> p a a
  jsonEnumWith a -> Int
indexOf [(Text, a)]
table =
    (a -> Text) -> (Text -> Maybe a) -> Prism Text Text a a
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (Array Text -> Int -> Text
forall a. Array a -> Int -> a
indexArray Array Text
names (Int -> Text) -> (a -> Int) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int
indexOf) (Text -> [(Text, a)] -> Maybe a
forall a b. Eq a => a -> [(a, b)] -> Maybe b
`lookup` [(Text, a)]
table) (Market a a a (Identity a) -> Market a a Text (Identity Text))
-> p Text Text -> p a a
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
    where
      names :: Array Text
names = [Text] -> Array Text
forall a. [a] -> Array a
arrayFromList (((Text, a) -> Text) -> [(Text, a)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, a) -> Text
forall a b. (a, b) -> a
fst [(Text, a)]
table)

{- | An enumeration of strings, by `AComonocle`'s copies & their names,
which `jsonEnumWith` tables once, numbered as `fromEnumerable` numbers them.

>>> import Control.Lens (coerced)
>>> import Control.Lens.Comonocle (_BoundedEnum)
>>> import Data.Text qualified as Text
>>> newtype Order = Order Ordering deriving (Show)
>>> let name = Text.toLower . Text.pack . show @Ordering
>>> instance Json Order where json = coerced >~ jsonEnum _BoundedEnum name
>>> jsonPrint (Order GT)
String "gt"
>>> jsonParse @Order (Aeson.String "lt")
Right (Order LT)
-}
jsonEnum :: JsonStr p => AComonocle a a () () -> (a -> Text) -> p a a
jsonEnum :: forall (p :: * -> * -> *) a.
JsonStr p =>
AComonocle a a () () -> (a -> Text) -> p a a
jsonEnum AComonocle a a () ()
mon a -> Text
name = AComonocle a a () ()
-> (forall (f :: * -> *).
    Enumerable f =>
    (a -> f ()) -> (f () -> a) -> p a a)
-> p a a
forall s t a b r.
AComonocle s t a b
-> (forall (f :: * -> *).
    Enumerable f =>
    (s -> f a) -> (f b -> t) -> r)
-> r
withComonocle AComonocle a a () ()
mon ((forall (f :: * -> *).
  Enumerable f =>
  (a -> f ()) -> (f () -> a) -> p a a)
 -> p a a)
-> (forall (f :: * -> *).
    Enumerable f =>
    (a -> f ()) -> (f () -> a) -> p a a)
-> p a a
forall a b. (a -> b) -> a -> b
$ \a -> f ()
split f () -> a
merge ->
  let copies :: [f ()]
copies = [f ()] -> (f () -> [f ()]) -> Maybe (f ()) -> [f ()]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] f () -> [f ()]
forall (f :: * -> *) a. Enumerable f => f a -> [f a]
enumerateFrom (Getting (First (f ())) (Natural, ()) (f ())
-> (Natural, ()) -> Maybe (f ())
forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview Getting (First (f ())) (Natural, ()) (f ())
forall (f :: * -> *) a. Enumerable f => Prism' (Natural, a) (f a)
Prism' (Natural, ()) (f ())
fromEnumerable (Natural
0,()))
  in (a -> Int) -> [(Text, a)] -> p a a
forall a. (a -> Int) -> [(Text, a)] -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
(a -> Int) -> [(Text, a)] -> p a a
jsonEnumWith (Natural -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Natural -> Int) -> (a -> Natural) -> a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Natural, ()) -> Natural
forall a b. (a, b) -> a
fst ((Natural, ()) -> Natural) -> (a -> (Natural, ())) -> a -> Natural
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AReview (Natural, ()) (f ()) -> f () -> (Natural, ())
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview (Natural, ()) (f ())
forall (f :: * -> *) a. Enumerable f => Prism' (Natural, a) (f a)
Prism' (Natural, ()) (f ())
fromEnumerable (f () -> (Natural, ())) -> (a -> f ()) -> a -> (Natural, ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f ()
split)
    [(a -> Text
name a
a, a
a) | a
a <- (f () -> a) -> [f ()] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map f () -> a
merge [f ()]
copies]
{-# INLINE jsonEnum #-}

{- | `JsonTup` grammars describe the elements of a JSON array.
As `Alternator`s they have optional elements (`optionalP`, `optionP`),
rest elements (`manyP`, `someP`) and alternatives (`>+<`, `>|<`),
like TypeScript's variadic tuple types, @[A, B?, ...C[]]@.
Its elements are `JsonVal` grammars, which determine its type.
-}
class Alternator q => JsonTup p q | q -> p where
  jsonElem :: p a b -> q a b

{- | `JsonObj` grammars describe the properties of a JSON object.
Each key may be read or written at most once.
A required property, @k !: v@, is like TypeScript's @{k: T}@,
and an optional property, @k ?: v@, may be missing, like @{k?: T}@.
A property with a default, @"limit" ?: jsonInt != 10@,
like @aeson@'s @.:?@ & @.!=@, is missing exactly when it's the default.
Its properties are `JsonVal` grammars, which determine its type.
-}
class (Monoidal q, CocartesianChoice q) => JsonObj p q | q -> p where
  (!:) :: Text -> p a b -> q a b
  (?:) :: Text -> p a b -> q (Maybe a) (Maybe b)
  {- | The properties of an object which aren't named by `!:` or `?:`,
  as a list of key-value pairs, by a grammar of keys & a grammar of values.

  On its own, it's a dictionary.

  > jsonObject (jsonDict jsonText json)
  > -- {"a": 1, "b": 2}  <->  [("a", 1), ("b", 2)]

  Beside named properties, it's the rest of them.

  > jsonObject ("id" !: json >*< jsonDict jsonText json)
  > -- {"id": 1, "a": true, "b": false}  <->  (1, [("a", True), ("b", False)])

  Parsing fails unless every remaining property matches both grammars,
  so a narrower key grammar than `jsonText`, like `jsonEnumWith`,
  restricts the keys allowed. Printing fails on a key which repeats,
  or which is also named. An object has at most one `jsonDict`.

  In TypeScript, it's an index signature, @{ [key: string]: T }@,
  or, of an enumeration of keys, a mapped type, @{ [key in K]?: T }@.
  -}
  jsonDict :: (forall k. JsonStr k => k a b) -> p c d -> q [(a, c)] [(b, d)]
infixr 7 !:, ?:

-- Errors --

{- | A located failure to decode, parse or print a `Value`.
Its path is relative to that `Value`, root first.
It expected one of the alternatives, none meaning just "unexpected".
Parsing found a `Value`, or decoding found text which isn't JSON,
by @aeson@'s message; printing doesn't show the Haskell value it found.
It failed within `rule`s, outermost first, branching where alternatives
failed alike; a `rule` it failed for as a whole is its expectation instead.
-}
data JsonError = JsonError
  { JsonError -> [JSONPathElement]
jsonErrorPath :: [JSONPathElement]
  , JsonError -> [String]
jsonErrorExpected :: [String]
  , JsonError -> Maybe (Either String Value)
jsonErrorFound :: Maybe (Either String Value)
  , JsonError -> JsonErrorSort
jsonErrorSort :: JsonErrorSort
  , JsonError -> Forest String
jsonErrorRules :: Forest String
  } deriving stock (JsonError -> JsonError -> Bool
(JsonError -> JsonError -> Bool)
-> (JsonError -> JsonError -> Bool) -> Eq JsonError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JsonError -> JsonError -> Bool
== :: JsonError -> JsonError -> Bool
$c/= :: JsonError -> JsonError -> Bool
/= :: JsonError -> JsonError -> Bool
Eq, Int -> JsonError -> ShowS
[JsonError] -> ShowS
JsonError -> String
(Int -> JsonError -> ShowS)
-> (JsonError -> String)
-> ([JsonError] -> ShowS)
-> Show JsonError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JsonError -> ShowS
showsPrec :: Int -> JsonError -> ShowS
$cshow :: JsonError -> String
show :: JsonError -> String
$cshowList :: [JsonError] -> ShowS
showList :: [JsonError] -> ShowS
Show)

-- | How a t'JsonError' failed, so that alternatives report the closest.
data JsonErrorSort
  = JsonIlliteral
  -- ^ a string literal mismatch; the alternative doesn't apply
  | JsonMismatch
  -- ^ the value was rejected as a whole
  | JsonMissing
  -- ^ the value was rejected for what it contains, lacks or repeats
  deriving stock (JsonErrorSort -> JsonErrorSort -> Bool
(JsonErrorSort -> JsonErrorSort -> Bool)
-> (JsonErrorSort -> JsonErrorSort -> Bool) -> Eq JsonErrorSort
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JsonErrorSort -> JsonErrorSort -> Bool
== :: JsonErrorSort -> JsonErrorSort -> Bool
$c/= :: JsonErrorSort -> JsonErrorSort -> Bool
/= :: JsonErrorSort -> JsonErrorSort -> Bool
Eq, Eq JsonErrorSort
Eq JsonErrorSort =>
(JsonErrorSort -> JsonErrorSort -> Ordering)
-> (JsonErrorSort -> JsonErrorSort -> Bool)
-> (JsonErrorSort -> JsonErrorSort -> Bool)
-> (JsonErrorSort -> JsonErrorSort -> Bool)
-> (JsonErrorSort -> JsonErrorSort -> Bool)
-> (JsonErrorSort -> JsonErrorSort -> JsonErrorSort)
-> (JsonErrorSort -> JsonErrorSort -> JsonErrorSort)
-> Ord JsonErrorSort
JsonErrorSort -> JsonErrorSort -> Bool
JsonErrorSort -> JsonErrorSort -> Ordering
JsonErrorSort -> JsonErrorSort -> JsonErrorSort
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: JsonErrorSort -> JsonErrorSort -> Ordering
compare :: JsonErrorSort -> JsonErrorSort -> Ordering
$c< :: JsonErrorSort -> JsonErrorSort -> Bool
< :: JsonErrorSort -> JsonErrorSort -> Bool
$c<= :: JsonErrorSort -> JsonErrorSort -> Bool
<= :: JsonErrorSort -> JsonErrorSort -> Bool
$c> :: JsonErrorSort -> JsonErrorSort -> Bool
> :: JsonErrorSort -> JsonErrorSort -> Bool
$c>= :: JsonErrorSort -> JsonErrorSort -> Bool
>= :: JsonErrorSort -> JsonErrorSort -> Bool
$cmax :: JsonErrorSort -> JsonErrorSort -> JsonErrorSort
max :: JsonErrorSort -> JsonErrorSort -> JsonErrorSort
$cmin :: JsonErrorSort -> JsonErrorSort -> JsonErrorSort
min :: JsonErrorSort -> JsonErrorSort -> JsonErrorSort
Ord, Int -> JsonErrorSort -> ShowS
[JsonErrorSort] -> ShowS
JsonErrorSort -> String
(Int -> JsonErrorSort -> ShowS)
-> (JsonErrorSort -> String)
-> ([JsonErrorSort] -> ShowS)
-> Show JsonErrorSort
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JsonErrorSort -> ShowS
showsPrec :: Int -> JsonErrorSort -> ShowS
$cshow :: JsonErrorSort -> String
show :: JsonErrorSort -> String
$cshowList :: [JsonErrorSort] -> ShowS
showList :: [JsonErrorSort] -> ShowS
Show)

{- | The message of a t'JsonError', without its path, as @aeson@ words it.

>>> either jsonErrorMessage show (jsonParse @Bool (Aeson.String "yes"))
"expected boolean, but found \"yes\""
-}
jsonErrorMessage :: JsonError -> String
jsonErrorMessage :: JsonError -> String
jsonErrorMessage JsonError
err = case (JsonError -> Maybe (Either String Value)
jsonErrorFound JsonError
err, JsonError -> [String]
jsonErrorExpected JsonError
err) of
  (Just (Left String
syntax), [String]
_) -> String
syntax
  (Just (Right Value
found), []) -> String
"unexpected " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Value -> String
render Value
found
  (Just (Right Value
found), [String]
expected) ->
    String
"expected " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
alternatives [String]
expected String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
", but found " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Value -> String
render Value
found
  (Maybe (Either String Value)
Nothing, []) -> String
"cannot print"
  (Maybe (Either String Value)
Nothing, [String]
expected)
    | JsonError -> JsonErrorSort
jsonErrorSort JsonError
err JsonErrorSort -> JsonErrorSort -> Bool
forall a. Eq a => a -> a -> Bool
== JsonErrorSort
JsonMissing ->
        String
"cannot print " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
alternatives [String]
expected
    | Bool
otherwise -> String
"cannot print as " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
alternatives [String]
expected
  where
    render :: Value -> String
render = ShowS
abbreviate ShowS -> (Value -> String) -> Value -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
LText.unpack (Text -> String) -> (Value -> Text) -> Value -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Text
forall a. ToJSON a => a -> Text
encodeToLazyText
    abbreviate :: ShowS
abbreviate String
str = if String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
str Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
60 then Int -> ShowS
forall a. Int -> [a] -> [a]
take Int
57 String
str String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"..." else String
str
    alternatives :: [String] -> String
alternatives = \case
      [] -> String
""
      [String
e] -> String
e
      [String]
es -> String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
", " ([String] -> [String]
forall a. HasCallStack => [a] -> [a]
init [String]
es) String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" or " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
forall a. HasCallStack => [a] -> a
last [String]
es

jsonUnexpected :: Maybe Value -> Either JsonError a
jsonUnexpected :: forall a. Maybe Value -> Either JsonError a
jsonUnexpected Maybe Value
found =
  JsonError -> Either JsonError a
forall a b. a -> Either a b
Left ([JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [] [] (Value -> Either String Value
forall a b. b -> Either a b
Right (Value -> Either String Value)
-> Maybe Value -> Maybe (Either String Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Value
found) JsonErrorSort
JsonMismatch [])

jsonMismatch :: String -> Value -> Either JsonError a
jsonMismatch :: forall a. String -> Value -> Either JsonError a
jsonMismatch String
expected Value
found =
  JsonError -> Either JsonError a
forall a b. a -> Either a b
Left ([JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [] [String
expected] (Either String Value -> Maybe (Either String Value)
forall a. a -> Maybe a
Just (Value -> Either String Value
forall a b. b -> Either a b
Right Value
found)) JsonErrorSort
JsonMismatch [])

jsonMissing :: String -> Maybe Value -> Either JsonError a
jsonMissing :: forall a. String -> Maybe Value -> Either JsonError a
jsonMissing String
expected Maybe Value
found =
  JsonError -> Either JsonError a
forall a b. a -> Either a b
Left ([JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [] [String
expected] (Value -> Either String Value
forall a b. b -> Either a b
Right (Value -> Either String Value)
-> Maybe Value -> Maybe (Either String Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Value
found) JsonErrorSort
JsonMissing [])

countElements :: Int -> String
countElements :: Int -> String
countElements Int
n = Int -> String
forall a. Show a => a -> String
show Int
n String -> ShowS
forall a. Semigroup a => a -> a -> a
<> if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 then String
" element" else String
" elements"

jsonAt :: JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt :: forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt JSONPathElement
el = (JsonError -> JsonError)
-> Either JsonError a -> Either JsonError a
forall a.
(JsonError -> JsonError)
-> Either JsonError a -> Either JsonError a
onFailure (\JsonError
err -> JsonError
err {jsonErrorPath = el : jsonErrorPath err})

-- | Map a failure, sharing a success.
onFailure
  :: (JsonError -> JsonError) -> Either JsonError a -> Either JsonError a
onFailure :: forall a.
(JsonError -> JsonError)
-> Either JsonError a -> Either JsonError a
onFailure JsonError -> JsonError
f = \case
  Left JsonError
err -> JsonError -> Either JsonError a
forall a b. a -> Either a b
Left (JsonError -> JsonError
f JsonError
err)
  Either JsonError a
success -> Either JsonError a
success


-- | Map a success strictly, sharing a failure.
onSuccess :: (a -> b) -> Either JsonError a -> Either JsonError b
onSuccess :: forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
onSuccess a -> b
f = \case
  Left JsonError
err -> JsonError -> Either JsonError b
forall a b. a -> Either a b
Left JsonError
err
  Right a
a -> b -> Either JsonError b
forall a b. b -> Either a b
Right (b -> Either JsonError b) -> b -> Either JsonError b
forall a b. (a -> b) -> a -> b
$! a -> b
f a
a

{- | A `rule` labels its failures as a whole,
like @(\<?\>)@ for parser combinators, and encloses its other failures.
-}
jsonRelabel :: String -> JsonError -> JsonError
jsonRelabel :: String -> JsonError -> JsonError
jsonRelabel String
name JsonError
err
  | [JSONPathElement] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (JsonError -> [JSONPathElement]
jsonErrorPath JsonError
err)
  , JsonError -> JsonErrorSort
jsonErrorSort JsonError
err JsonErrorSort -> JsonErrorSort -> Bool
forall a. Eq a => a -> a -> Bool
/= JsonErrorSort
JsonMissing = JsonError
err {jsonErrorExpected = [name]}
  | Bool
otherwise = JsonError
err {jsonErrorRules = [Node name (jsonErrorRules err)]}

{- | Combine the failures of alternatives: the deepest failure wins,
failures on the same value merge their expectations & rules,
and a string literal mismatch loses to any other failure.
-}
jsonOrElse :: JsonError -> JsonError -> JsonError
jsonOrElse :: JsonError -> JsonError -> JsonError
jsonOrElse JsonError
err1 JsonError
err2
  | Int
depth1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
depth2 = if Int
depth1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
depth2 then JsonError
err1 else JsonError
err2
  | JsonError -> [JSONPathElement]
jsonErrorPath JsonError
err1 [JSONPathElement] -> [JSONPathElement] -> Bool
forall a. Eq a => a -> a -> Bool
== JsonError -> [JSONPathElement]
jsonErrorPath JsonError
err2
  , JsonError -> Maybe (Either String Value)
jsonErrorFound JsonError
err1 Maybe (Either String Value) -> Maybe (Either String Value) -> Bool
forall a. Eq a => a -> a -> Bool
== JsonError -> Maybe (Either String Value)
jsonErrorFound JsonError
err2 = JsonError
err2
    { jsonErrorExpected =
        nub (jsonErrorExpected err1 <> jsonErrorExpected err2)
    , jsonErrorSort = max (jsonErrorSort err1) (jsonErrorSort err2)
    , jsonErrorRules = jsonErrorRules err1 <> jsonErrorRules err2
    }
  | JsonError -> JsonErrorSort
jsonErrorSort JsonError
err2 JsonErrorSort -> JsonErrorSort -> Bool
forall a. Eq a => a -> a -> Bool
== JsonErrorSort
JsonIlliteral
  , JsonError -> JsonErrorSort
jsonErrorSort JsonError
err1 JsonErrorSort -> JsonErrorSort -> Bool
forall a. Eq a => a -> a -> Bool
/= JsonErrorSort
JsonIlliteral = JsonError
err1
  | Bool
otherwise = JsonError
err2
  where
    depth1 :: Int
depth1 = [JSONPathElement] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (JsonError -> [JSONPathElement]
jsonErrorPath JsonError
err1)
    depth2 :: Int
depth2 = [JSONPathElement] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (JsonError -> [JSONPathElement]
jsonErrorPath JsonError
err2)

-- Parsing interpreters --

{- | t'JsonParsor' parses a `Value`. It may also have a t'Dispatch',
when it only accepts string literals, as values or as the values of
a key of objects, so that alternatives are chosen by lookup,
rather than tried in turn.
-}
data JsonParsor a b = JsonParsor
  { forall a b. JsonParsor a b -> Maybe (Dispatch b)
jsonParsorDispatch :: Maybe (Dispatch b)
  , forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor :: Value -> Either JsonError b
  -- | A primitive parses an array of its values at once, when they all match.
  , forall a b. JsonParsor a b -> Maybe (Array -> Maybe [b])
jsonParsorArray :: Maybe (Vector Value -> Maybe [b])
  {- | A string's text, when it parses every string by a function of its text
  which keeps its order, so that a map's keys parse by mapping them.
  -}
  , forall a b. JsonParsor a b -> Maybe (Text -> b)
jsonParsorText :: Maybe (Text -> b)
  }

{- | Parsers by the string literal which they accept,
as the value itself, or as the value of a key.
-}
data Dispatch b = Dispatch
  { forall b. Dispatch b -> Maybe Key
dispatchKey :: Maybe Key
  , forall b. Dispatch b -> Map Text (Value -> Either JsonError b)
dispatchTable :: Map Text (Value -> Either JsonError b)
  }

jsonParsor :: (Value -> Either JsonError b) -> JsonParsor a b
jsonParsor :: forall b a. (Value -> Either JsonError b) -> JsonParsor a b
jsonParsor Value -> Either JsonError b
parse = Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
forall a b.
Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
JsonParsor Maybe (Dispatch b)
forall a. Maybe a
Nothing Value -> Either JsonError b
parse Maybe (Array -> Maybe [b])
forall a. Maybe a
Nothing Maybe (Text -> b)
forall a. Maybe a
Nothing

-- | A primitive t'JsonParsor', matching its values.
primitiveParsor
  :: String -> (Value -> Maybe b) -> JsonParsor a b
primitiveParsor :: forall b a. String -> (Value -> Maybe b) -> JsonParsor a b
primitiveParsor String
expected Value -> Maybe b
match = Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
forall a b.
Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
JsonParsor Maybe (Dispatch b)
forall a. Maybe a
Nothing Value -> Either JsonError b
parse ((Array -> Maybe [b]) -> Maybe (Array -> Maybe [b])
forall a. a -> Maybe a
Just Array -> Maybe [b]
array) Maybe (Text -> b)
forall a. Maybe a
Nothing
  where
    parse :: Value -> Either JsonError b
parse Value
v = Either JsonError b
-> (b -> Either JsonError b) -> Maybe b -> Either JsonError b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Value -> Either JsonError b
forall a. String -> Value -> Either JsonError a
jsonMismatch String
expected Value
v) b -> Either JsonError b
forall a b. b -> Either a b
Right (Value -> Maybe b
match Value
v)
    array :: Array -> Maybe [b]
array Array
arr
      | (Value -> Bool) -> Array -> Bool
forall a. (a -> Bool) -> Vector a -> Bool
Vector.all (Maybe b -> Bool
forall a. Maybe a -> Bool
isJust (Maybe b -> Bool) -> (Value -> Maybe b) -> Value -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Maybe b
match) Array
arr =
          [b] -> Maybe [b]
forall a. a -> Maybe a
Just ((Value -> Maybe b) -> [Value] -> [b]
forall a b. (a -> Maybe b) -> [a] -> [b]
Data.Maybe.mapMaybe Value -> Maybe b
match (Array -> [Value]
forall a. Vector a -> [a]
Vector.toList Array
arr))
      | Bool
otherwise = Maybe [b]
forall a. Maybe a
Nothing
{-# INLINE primitiveParsor #-}

-- | Transform a parser and its dispatch table alike.
mapParsing
  :: ((Value -> Either JsonError b) -> Value -> Either JsonError c)
  -> JsonParsor a b -> JsonParsor x c
mapParsing :: forall b c a x.
((Value -> Either JsonError b) -> Value -> Either JsonError c)
-> JsonParsor a b -> JsonParsor x c
mapParsing (Value -> Either JsonError b) -> Value -> Either JsonError c
f JsonParsor a b
parsor = JsonParsor
  { jsonParsorDispatch :: Maybe (Dispatch c)
jsonParsorDispatch = Dispatch b -> Dispatch c
retable (Dispatch b -> Dispatch c)
-> Maybe (Dispatch b) -> Maybe (Dispatch c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JsonParsor a b -> Maybe (Dispatch b)
forall a b. JsonParsor a b -> Maybe (Dispatch b)
jsonParsorDispatch JsonParsor a b
parsor
  , runJsonParsor :: Value -> Either JsonError c
runJsonParsor = (Value -> Either JsonError b) -> Value -> Either JsonError c
f (JsonParsor a b -> Value -> Either JsonError b
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a b
parsor)
  , jsonParsorArray :: Maybe (Array -> Maybe [c])
jsonParsorArray = Maybe (Array -> Maybe [c])
forall a. Maybe a
Nothing
  , jsonParsorText :: Maybe (Text -> c)
jsonParsorText = Maybe (Text -> c)
forall a. Maybe a
Nothing
  }
  where
    retable :: Dispatch b -> Dispatch c
retable Dispatch b
dispatch = Dispatch b
dispatch {dispatchTable = f <$> dispatchTable dispatch}

dispatching :: Dispatch b -> Value -> Either JsonError b
dispatching :: forall b. Dispatch b -> Value -> Either JsonError b
dispatching (Dispatch Maybe Key
Nothing Map Text (Value -> Either JsonError b)
table) = \case
  v :: Value
v@(String Text
t) | Just Value -> Either JsonError b
p <- Text
-> Map Text (Value -> Either JsonError b)
-> Maybe (Value -> Either JsonError b)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Text
t Map Text (Value -> Either JsonError b)
table -> Value -> Either JsonError b
p Value
v
  Value
v -> JsonError -> Either JsonError b
forall a b. a -> Either a b
Left ([JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [] (Map Text (Value -> Either JsonError b) -> [String]
forall a. Map Text a -> [String]
literals Map Text (Value -> Either JsonError b)
table) (Either String Value -> Maybe (Either String Value)
forall a. a -> Maybe a
Just (Value -> Either String Value
forall a b. b -> Either a b
Right Value
v)) JsonErrorSort
JsonIlliteral [])
dispatching (Dispatch (Just Key
key) Map Text (Value -> Either JsonError b)
table) = \case
  v :: Value
v@(Object Object
o) -> case Key -> Object -> Maybe Value
forall v. Key -> KeyMap v -> Maybe v
KeyMap.lookup Key
key Object
o of
    Maybe Value
Nothing -> String -> Maybe Value -> Either JsonError b
forall a. String -> Maybe Value -> Either JsonError a
jsonMissing (String
"key " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Key -> String
showKey Key
key) (Value -> Maybe Value
forall a. a -> Maybe a
Just Value
v)
    Just (String Text
t) | Just Value -> Either JsonError b
p <- Text
-> Map Text (Value -> Either JsonError b)
-> Maybe (Value -> Either JsonError b)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Text
t Map Text (Value -> Either JsonError b)
table -> Value -> Either JsonError b
p Value
v
    Just Value
tag ->
      JsonError -> Either JsonError b
forall a b. a -> Either a b
Left (JsonError -> Either JsonError b)
-> JsonError -> Either JsonError b
forall a b. (a -> b) -> a -> b
$ [JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [Key -> JSONPathElement
Key Key
key] (Map Text (Value -> Either JsonError b) -> [String]
forall a. Map Text a -> [String]
literals Map Text (Value -> Either JsonError b)
table) (Either String Value -> Maybe (Either String Value)
forall a. a -> Maybe a
Just (Value -> Either String Value
forall a b. b -> Either a b
Right Value
tag))
        JsonErrorSort
JsonIlliteral []
  Value
v -> String -> Value -> Either JsonError b
forall a. String -> Value -> Either JsonError a
jsonMismatch String
"object" Value
v

literals :: Map Text a -> [String]
literals :: forall a. Map Text a -> [String]
literals = (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
forall a. Show a => a -> String
show ([Text] -> [String])
-> (Map Text a -> [Text]) -> Map Text a -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Text a -> [Text]
forall k a. Map k a -> [k]
Map.keys

orElse
  :: (Value -> Either JsonError b) -> (Value -> Either JsonError b)
  -> Value -> Either JsonError b
orElse :: forall b.
(Value -> Either JsonError b)
-> (Value -> Either JsonError b) -> Value -> Either JsonError b
orElse Value -> Either JsonError b
p Value -> Either JsonError b
q Value
v = case Value -> Either JsonError b
p Value
v of
  Left JsonError
err1 -> (JsonError -> JsonError)
-> Either JsonError b -> Either JsonError b
forall a.
(JsonError -> JsonError)
-> Either JsonError a -> Either JsonError a
onFailure (JsonError -> JsonError -> JsonError
jsonOrElse JsonError
err1) (Value -> Either JsonError b
q Value
v)
  Either JsonError b
success -> Either JsonError b
success

{- | t'TupParsor' parses the elements of a JSON array from a position,
in every way it can, so that optional and rest elements backtrack.
A tuple of fixed length also parses its elements from known positions.
-}
data TupParsor a b = TupParsor
  { forall a b.
TupParsor a b -> Maybe (Int, Array -> Int -> Either JsonError b)
tupParsorFixed :: Maybe (Int, Vector Value -> Int -> Either JsonError b)
  , forall a b.
TupParsor a b -> Array -> Int -> [Either JsonError (b, Int)]
runTupParsor :: Vector Value -> Int -> [Either JsonError (b, Int)]
  }

{- | t'ObjParsor' reads keys of an t'Object', ignoring other keys,
unless it reads the rest of them, those which the object doesn't name.
Its keys are known before parsing, so overlapping keys are found once,
as are its tags, keys which only accept string literals,
& whether its keys are all required, so that it has all of a shape's keys.
-}
data ObjParsor a b = ObjParsor
  { forall a b. ObjParsor a b -> [[Key]]
objParsorShapes :: [[Key]]
  , forall a b. ObjParsor a b -> [(Key, Set Text)]
objParsorTags :: [(Key, Set Text)]
  , forall a b. ObjParsor a b -> Bool
objParsorRequired :: Bool
  , forall a b.
ObjParsor a b -> HashSet Key -> Object -> Either JsonError b
runObjParsor :: HashSet Key -> Object -> Either JsonError b
  }

instance Functor (JsonParsor a) where
  fmap :: forall a b. (a -> b) -> JsonParsor a a -> JsonParsor a b
fmap a -> b
f JsonParsor a a
p = (((Value -> Either JsonError a) -> Value -> Either JsonError b)
-> JsonParsor a a -> JsonParsor (ZonkAny 11) b
forall b c a x.
((Value -> Either JsonError b) -> Value -> Either JsonError c)
-> JsonParsor a b -> JsonParsor x c
mapParsing ((Either JsonError a -> Either JsonError b)
-> (Value -> Either JsonError a) -> Value -> Either JsonError b
forall a b. (a -> b) -> (Value -> a) -> Value -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> Either JsonError a -> Either JsonError b
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
onSuccess a -> b
f)) JsonParsor a a
p)
    {jsonParsorArray = fmap (fmap (map f) .) (jsonParsorArray p)}
instance Witherable.Filterable (JsonParsor a) where
  mapMaybe :: forall a b. (a -> Maybe b) -> JsonParsor a a -> JsonParsor a b
mapMaybe = (a -> Maybe a)
-> (a -> Maybe b) -> JsonParsor a a -> JsonParsor a b
forall (p :: * -> * -> *) s a b t.
(Choice p, Cochoice p) =>
(s -> Maybe a) -> (b -> Maybe t) -> p a b -> p s t
dimapMaybe a -> Maybe a
forall a. a -> Maybe a
Just
instance Filtrator JsonParsor
instance Profunctor JsonParsor where
  dimap :: forall a b c d.
(a -> b) -> (c -> d) -> JsonParsor b c -> JsonParsor a d
dimap a -> b
_ c -> d
g = (c -> d) -> JsonParsor a c -> JsonParsor a d
forall a b. (a -> b) -> JsonParsor a a -> JsonParsor a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> d
g (JsonParsor a c -> JsonParsor a d)
-> (JsonParsor b c -> JsonParsor a c)
-> JsonParsor b c
-> JsonParsor a d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonParsor b c -> JsonParsor a c
forall a b. Coercible a b => a -> b
coerce
  q b c
_ #. :: forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> JsonParsor a b -> JsonParsor a c
#. JsonParsor a b
p = JsonParsor a b -> JsonParsor a c
forall a b. Coercible a b => a -> b
coerce JsonParsor a b
p
  JsonParsor b c
p .# :: forall a b c (q :: * -> * -> *).
Coercible b a =>
JsonParsor b c -> q a b -> JsonParsor a c
.# q a b
_ = JsonParsor b c -> JsonParsor a c
forall a b. Coercible a b => a -> b
coerce JsonParsor b c
p
instance Choice JsonParsor where
  left' :: forall a b c.
JsonParsor a b -> JsonParsor (Either a c) (Either b c)
left' = ((Value -> Either JsonError b)
 -> Value -> Either JsonError (Either b c))
-> JsonParsor a b -> JsonParsor (Either a c) (Either b c)
forall b c a x.
((Value -> Either JsonError b) -> Value -> Either JsonError c)
-> JsonParsor a b -> JsonParsor x c
mapParsing ((Either JsonError b -> Either JsonError (Either b c))
-> (Value -> Either JsonError b)
-> Value
-> Either JsonError (Either b c)
forall a b. (a -> b) -> (Value -> a) -> Value -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((b -> Either b c)
-> Either JsonError b -> Either JsonError (Either b c)
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either b c
forall a b. a -> Either a b
Left))
  right' :: forall a b c.
JsonParsor a b -> JsonParsor (Either c a) (Either c b)
right' = ((Value -> Either JsonError b)
 -> Value -> Either JsonError (Either c b))
-> JsonParsor a b -> JsonParsor (Either c a) (Either c b)
forall b c a x.
((Value -> Either JsonError b) -> Value -> Either JsonError c)
-> JsonParsor a b -> JsonParsor x c
mapParsing ((Either JsonError b -> Either JsonError (Either c b))
-> (Value -> Either JsonError b)
-> Value
-> Either JsonError (Either c b)
forall a b. (a -> b) -> (Value -> a) -> Value -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((b -> Either c b)
-> Either JsonError b -> Either JsonError (Either c b)
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either c b
forall a b. b -> Either a b
Right))
-- | An array of values which all match parses at once.
instance Cochoice JsonParsor where
  unleft :: forall a d b.
JsonParsor (Either a d) (Either b d) -> JsonParsor a b
unleft JsonParsor (Either a d) (Either b d)
p = (((Value -> Either JsonError (Either b d))
 -> Value -> Either JsonError b)
-> JsonParsor (Either a d) (Either b d) -> JsonParsor (ZonkAny 9) b
forall b c a x.
((Value -> Either JsonError b) -> Value -> Either JsonError c)
-> JsonParsor a b -> JsonParsor x c
mapParsing (\Value -> Either JsonError (Either b d)
parse Value
v ->
    Value -> Either JsonError (Either b d)
parse Value
v Either JsonError (Either b d)
-> (Either b d -> Either JsonError b) -> Either JsonError b
forall a b.
Either JsonError a
-> (a -> Either JsonError b) -> Either JsonError b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (b -> Either JsonError b)
-> (d -> Either JsonError b) -> Either b d -> Either JsonError b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either b -> Either JsonError b
forall a. a -> Either JsonError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (\d
_ -> Maybe Value -> Either JsonError b
forall a. Maybe Value -> Either JsonError a
jsonUnexpected (Value -> Maybe Value
forall a. a -> Maybe a
Just Value
v))) JsonParsor (Either a d) (Either b d)
p)
    { jsonParsorArray = (traverse (either Just (const Nothing)) <=<)
        <$> jsonParsorArray p
    }
  unright :: forall d a b.
JsonParsor (Either d a) (Either d b) -> JsonParsor a b
unright JsonParsor (Either d a) (Either d b)
p = (((Value -> Either JsonError (Either d b))
 -> Value -> Either JsonError b)
-> JsonParsor (Either d a) (Either d b)
-> JsonParsor (ZonkAny 10) b
forall b c a x.
((Value -> Either JsonError b) -> Value -> Either JsonError c)
-> JsonParsor a b -> JsonParsor x c
mapParsing (\Value -> Either JsonError (Either d b)
parse Value
v ->
    Value -> Either JsonError (Either d b)
parse Value
v Either JsonError (Either d b)
-> (Either d b -> Either JsonError b) -> Either JsonError b
forall a b.
Either JsonError a
-> (a -> Either JsonError b) -> Either JsonError b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (d -> Either JsonError b)
-> (b -> Either JsonError b) -> Either d b -> Either JsonError b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\d
_ -> Maybe Value -> Either JsonError b
forall a. Maybe Value -> Either JsonError a
jsonUnexpected (Value -> Maybe Value
forall a. a -> Maybe a
Just Value
v)) b -> Either JsonError b
forall a. a -> Either JsonError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure) JsonParsor (Either d a) (Either d b)
p)
    { jsonParsorArray = (traverse (either (const Nothing) Just) <=<)
        <$> jsonParsorArray p
    }
instance CocartesianMonoidal JsonParsor where
  zeroP :: JsonParsor Void Void
zeroP = JsonParsor Void Void
forall a. DisjunctiveMonoid a => a
falseP
  JsonParsor a b
p >+< :: forall a b c d.
JsonParsor a b
-> JsonParsor c d -> JsonParsor (Either a c) (Either b d)
>+< JsonParsor c d
q = (b -> Either b d
forall a b. a -> Either a b
Left (b -> Either b d)
-> JsonParsor (Either a c) b
-> JsonParsor (Either a c) (Either b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JsonParsor a b -> JsonParsor (Either a c) b
forall a b. Coercible a b => a -> b
coerce JsonParsor a b
p) JsonParsor (Either a c) (Either b d)
-> JsonParsor (Either a c) (Either b d)
-> JsonParsor (Either a c) (Either b d)
forall a. DisjunctiveMonoid a => a -> a -> a
>|< (d -> Either b d
forall a b. b -> Either a b
Right (d -> Either b d)
-> JsonParsor (Either a c) d
-> JsonParsor (Either a c) (Either b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JsonParsor c d -> JsonParsor (Either a c) d
forall a b. Coercible a b => a -> b
coerce JsonParsor c d
q)
instance CocartesianChoice JsonParsor
instance DisjunctiveMonoid (JsonParsor a b) where
  falseP :: JsonParsor a b
falseP = (Value -> Either JsonError b) -> JsonParsor a b
forall b a. (Value -> Either JsonError b) -> JsonParsor a b
jsonParsor (Maybe Value -> Either JsonError b
forall a. Maybe Value -> Either JsonError a
jsonUnexpected (Maybe Value -> Either JsonError b)
-> (Value -> Maybe Value) -> Value -> Either JsonError b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Maybe Value
forall a. a -> Maybe a
Just)
  JsonParsor a b
p >|< :: JsonParsor a b -> JsonParsor a b -> JsonParsor a b
>|< JsonParsor a b
q = case (JsonParsor a b -> Maybe (Dispatch b)
forall a b. JsonParsor a b -> Maybe (Dispatch b)
jsonParsorDispatch JsonParsor a b
p, JsonParsor a b -> Maybe (Dispatch b)
forall a b. JsonParsor a b -> Maybe (Dispatch b)
jsonParsorDispatch JsonParsor a b
q) of
    (Just Dispatch b
dispatch0, Just Dispatch b
dispatch1)
      | Dispatch b -> Maybe Key
forall b. Dispatch b -> Maybe Key
dispatchKey Dispatch b
dispatch0 Maybe Key -> Maybe Key -> Bool
forall a. Eq a => a -> a -> Bool
== Dispatch b -> Maybe Key
forall b. Dispatch b -> Maybe Key
dispatchKey Dispatch b
dispatch1 ->
          let
            dispatch :: Dispatch b
dispatch = Maybe Key -> Map Text (Value -> Either JsonError b) -> Dispatch b
forall b.
Maybe Key -> Map Text (Value -> Either JsonError b) -> Dispatch b
Dispatch (Dispatch b -> Maybe Key
forall b. Dispatch b -> Maybe Key
dispatchKey Dispatch b
dispatch0) (Map Text (Value -> Either JsonError b) -> Dispatch b)
-> Map Text (Value -> Either JsonError b) -> Dispatch b
forall a b. (a -> b) -> a -> b
$ ((Value -> Either JsonError b)
 -> (Value -> Either JsonError b) -> Value -> Either JsonError b)
-> Map Text (Value -> Either JsonError b)
-> Map Text (Value -> Either JsonError b)
-> Map Text (Value -> Either JsonError b)
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (Value -> Either JsonError b)
-> (Value -> Either JsonError b) -> Value -> Either JsonError b
forall b.
(Value -> Either JsonError b)
-> (Value -> Either JsonError b) -> Value -> Either JsonError b
orElse
              (Dispatch b -> Map Text (Value -> Either JsonError b)
forall b. Dispatch b -> Map Text (Value -> Either JsonError b)
dispatchTable Dispatch b
dispatch0) (Dispatch b -> Map Text (Value -> Either JsonError b)
forall b. Dispatch b -> Map Text (Value -> Either JsonError b)
dispatchTable Dispatch b
dispatch1)
          in
            Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
forall a b.
Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
JsonParsor (Dispatch b -> Maybe (Dispatch b)
forall a. a -> Maybe a
Just Dispatch b
dispatch) (Dispatch b -> Value -> Either JsonError b
forall b. Dispatch b -> Value -> Either JsonError b
dispatching Dispatch b
dispatch) Maybe (Array -> Maybe [b])
array Maybe (Text -> b)
forall a. Maybe a
Nothing
    (Maybe (Dispatch b), Maybe (Dispatch b))
_ -> Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
forall a b.
Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
JsonParsor Maybe (Dispatch b)
forall a. Maybe a
Nothing ((Value -> Either JsonError b)
-> (Value -> Either JsonError b) -> Value -> Either JsonError b
forall b.
(Value -> Either JsonError b)
-> (Value -> Either JsonError b) -> Value -> Either JsonError b
orElse (JsonParsor a b -> Value -> Either JsonError b
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a b
p) (JsonParsor a b -> Value -> Either JsonError b
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a b
q))
      Maybe (Array -> Maybe [b])
array Maybe (Text -> b)
forall a. Maybe a
Nothing
    where
      -- An array which the first alternative parses, element by element.
      array :: Maybe (Array -> Maybe [b])
array = JsonParsor a b -> Maybe (Array -> Maybe [b])
forall a b. JsonParsor a b -> Maybe (Array -> Maybe [b])
jsonParsorArray JsonParsor a b
p
instance Ruled (JsonParsor a b) where
  rule :: String -> JsonParsor a b -> JsonParsor a b
rule String
name JsonParsor a b
p = (((Value -> Either JsonError b) -> Value -> Either JsonError b)
-> JsonParsor a b -> JsonParsor (ZonkAny 8) b
forall b c a x.
((Value -> Either JsonError b) -> Value -> Either JsonError c)
-> JsonParsor a b -> JsonParsor x c
mapParsing ((JsonError -> JsonError)
-> Either JsonError b -> Either JsonError b
forall a.
(JsonError -> JsonError)
-> Either JsonError a -> Either JsonError a
onFailure (String -> JsonError -> JsonError
jsonRelabel (ShowS
unqualified String
name)) (Either JsonError b -> Either JsonError b)
-> (Value -> Either JsonError b) -> Value -> Either JsonError b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) JsonParsor a b
p)
    {jsonParsorArray = jsonParsorArray p, jsonParsorText = jsonParsorText p}
instance BackusNaurForm (JsonParsor a b) where
  ruleRec :: String -> (JsonParsor a b -> JsonParsor a b) -> JsonParsor a b
ruleRec String
name JsonParsor a b -> JsonParsor a b
f = (JsonParsor a b -> JsonParsor a b) -> JsonParsor a b
forall a. (a -> a) -> a
fix (String -> JsonParsor a b -> JsonParsor a b
forall p. Ruled p => String -> p -> p
rule String
name (JsonParsor a b -> JsonParsor a b)
-> (JsonParsor a b -> JsonParsor a b)
-> JsonParsor a b
-> JsonParsor a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonParsor a b -> JsonParsor a b
f)
instance (x ~ (), y ~ ()) => IsString (JsonParsor x y) where
  fromString :: String -> JsonParsor x y
fromString String
s = Maybe (Dispatch ())
-> (Value -> Either JsonError ())
-> Maybe (Array -> Maybe [()])
-> Maybe (Text -> ())
-> JsonParsor x ()
forall a b.
Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
JsonParsor
    (Dispatch () -> Maybe (Dispatch ())
forall a. a -> Maybe a
Just (Maybe Key -> Map Text (Value -> Either JsonError ()) -> Dispatch ()
forall b.
Maybe Key -> Map Text (Value -> Either JsonError b) -> Dispatch b
Dispatch Maybe Key
forall a. Maybe a
Nothing (Text
-> (Value -> Either JsonError ())
-> Map Text (Value -> Either JsonError ())
forall k a. k -> a -> Map k a
Map.singleton Text
literal Value -> Either JsonError ()
parse))) Value -> Either JsonError ()
parse Maybe (Array -> Maybe [()])
forall a. Maybe a
Nothing
    Maybe (Text -> ())
forall a. Maybe a
Nothing
    where
      literal :: Text
literal = String -> Text
Text.pack String
s
      parse :: Value -> Either JsonError ()
parse = \case
        String Text
t | Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
literal -> () -> Either JsonError ()
forall a b. b -> Either a b
Right ()
        Value
v -> JsonError -> Either JsonError ()
forall a b. a -> Either a b
Left ([JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [] [ShowS
forall a. Show a => a -> String
show String
s] (Either String Value -> Maybe (Either String Value)
forall a. a -> Maybe a
Just (Value -> Either String Value
forall a b. b -> Either a b
Right Value
v)) JsonErrorSort
JsonIlliteral [])
instance JsonStr JsonParsor where
  jsonText :: JsonParsor Text Text
jsonText = (String -> (Value -> Maybe Text) -> JsonParsor (ZonkAny 7) Text
forall b a. String -> (Value -> Maybe b) -> JsonParsor a b
primitiveParsor String
"string" ((Value -> Maybe Text) -> JsonParsor (ZonkAny 7) Text)
-> (Value -> Maybe Text) -> JsonParsor (ZonkAny 7) Text
forall a b. (a -> b) -> a -> b
$ \case
    String Text
t -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
t
    Value
_ -> Maybe Text
forall a. Maybe a
Nothing) {jsonParsorText = Just id}
  -- | TsLiteral alternatives, dispatched by their string.
  jsonEnumWith :: forall a. (a -> Int) -> [(Text, a)] -> JsonParsor a a
jsonEnumWith a -> Int
indexOf [(Text, a)]
table = [JsonParsor a a] -> JsonParsor a a
forall (f :: * -> *) a.
(Foldable f, DisjunctiveMonoid a) =>
f a -> a
orP
    [ (a -> Int) -> (Int -> a) -> JsonParsor Int Int -> JsonParsor a a
forall a b c d.
(a -> b) -> (c -> d) -> JsonParsor b c -> JsonParsor a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> Int
indexOf (a -> Int -> a
forall a b. a -> b -> a
const a
a) (Int -> Prism' Int ()
forall a. Eq a => a -> Prism' a ()
only Int
i (Market () () () (Identity ()) -> Market () () Int (Identity Int))
-> JsonParsor () () -> JsonParsor Int Int
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? String -> JsonParsor () ()
forall a. IsString a => String -> a
fromString (Text -> String
Text.unpack Text
literal))
    | (Int
i, (Text
literal, a
a)) <- [Int] -> [(Text, a)] -> [(Int, (Text, a))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0 ..] [(Text, a)]
table
    ]
instance JsonVal JsonParsor where
  jsonNull :: JsonParsor () ()
jsonNull = (Value -> Either JsonError ()) -> JsonParsor () ()
forall b a. (Value -> Either JsonError b) -> JsonParsor a b
jsonParsor ((Value -> Either JsonError ()) -> JsonParsor () ())
-> (Value -> Either JsonError ()) -> JsonParsor () ()
forall a b. (a -> b) -> a -> b
$ \case
    Value
Null -> () -> Either JsonError ()
forall a b. b -> Either a b
Right ()
    Value
v -> String -> Value -> Either JsonError ()
forall a. String -> Value -> Either JsonError a
jsonMismatch String
"null" Value
v
  -- | As the default, but without trying @null@ before every value.
  jsonNullable :: forall a b. JsonParsor a b -> JsonParsor (Maybe a) (Maybe b)
jsonNullable JsonParsor a b
p = (Value -> Either JsonError (Maybe b))
-> JsonParsor (Maybe a) (Maybe b)
forall b a. (Value -> Either JsonError b) -> JsonParsor a b
jsonParsor ((Value -> Either JsonError (Maybe b))
 -> JsonParsor (Maybe a) (Maybe b))
-> (Value -> Either JsonError (Maybe b))
-> JsonParsor (Maybe a) (Maybe b)
forall a b. (a -> b) -> a -> b
$ \case
    Value
Null -> Maybe b -> Either JsonError (Maybe b)
forall a b. b -> Either a b
Right Maybe b
forall a. Maybe a
Nothing
    Value
v -> case JsonParsor a b -> Value -> Either JsonError b
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a b
p Value
v of
      Right b
b -> Maybe b -> Either JsonError (Maybe b)
forall a b. b -> Either a b
Right (b -> Maybe b
forall a. a -> Maybe a
Just b
b)
      Left JsonError
err -> JsonError -> Either JsonError (Maybe b)
forall a b. a -> Either a b
Left (JsonError -> JsonError -> JsonError
jsonOrElse JsonError
nullError JsonError
err)
        where
          nullError :: JsonError
nullError = [JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [] [String
"null"] (Either String Value -> Maybe (Either String Value)
forall a. a -> Maybe a
Just (Value -> Either String Value
forall a b. b -> Either a b
Right Value
v)) JsonErrorSort
JsonMismatch []
  jsonBool :: JsonParsor Bool Bool
jsonBool = String -> (Value -> Maybe Bool) -> JsonParsor Bool Bool
forall b a. String -> (Value -> Maybe b) -> JsonParsor a b
primitiveParsor String
"boolean" ((Value -> Maybe Bool) -> JsonParsor Bool Bool)
-> (Value -> Maybe Bool) -> JsonParsor Bool Bool
forall a b. (a -> b) -> a -> b
$ \case
    Bool Bool
b -> Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
b
    Value
_ -> Maybe Bool
forall a. Maybe a
Nothing
  jsonNumber :: JsonParsor Scientific Scientific
jsonNumber = String
-> (Value -> Maybe Scientific) -> JsonParsor Scientific Scientific
forall b a. String -> (Value -> Maybe b) -> JsonParsor a b
primitiveParsor String
"number" ((Value -> Maybe Scientific) -> JsonParsor Scientific Scientific)
-> (Value -> Maybe Scientific) -> JsonParsor Scientific Scientific
forall a b. (a -> b) -> a -> b
$ \case
    Number Scientific
n -> Scientific -> Maybe Scientific
forall a. a -> Maybe a
Just Scientific
n
    Value
_ -> Maybe Scientific
forall a. Maybe a
Nothing
  jsonValue :: JsonParsor Value Value
jsonValue = (Value -> Either JsonError Value) -> JsonParsor Value Value
forall b a. (Value -> Either JsonError b) -> JsonParsor a b
jsonParsor Value -> Either JsonError Value
forall a b. b -> Either a b
Right
  -- | As the default, but mapping text keys, rather than parsing them.
  jsonMap :: forall b a c d.
Ord b =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonParsor c d -> JsonParsor (Map a c) (Map b d)
jsonMap forall (k :: * -> * -> *). JsonStr k => k a b
key JsonParsor c d
p = case JsonParsor a b -> Maybe (Text -> b)
forall a b. JsonParsor a b -> Maybe (Text -> b)
jsonParsorText JsonParsor a b
forall (k :: * -> * -> *). JsonStr k => k a b
key of
    Just Text -> b
keyOf -> (Value -> Either JsonError (Map b d))
-> JsonParsor (Map a c) (Map b d)
forall b a. (Value -> Either JsonError b) -> JsonParsor a b
jsonParsor ((Value -> Either JsonError (Map b d))
 -> JsonParsor (Map a c) (Map b d))
-> (Value -> Either JsonError (Map b d))
-> JsonParsor (Map a c) (Map b d)
forall a b. (a -> b) -> a -> b
$ \case
      Object Object
o -> [(b, d)] -> Map b d
forall k a. [(k, a)] -> Map k a
Map.fromDistinctAscList ([(b, d)] -> Map b d)
-> Either JsonError [(b, d)] -> Either JsonError (Map b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Key, Value)] -> Either JsonError [(b, d)]
entries (Object -> [(Key, Value)]
forall v. KeyMap v -> [(Key, v)]
KeyMap.toAscList Object
o)
        where
          entries :: [(Key, Value)] -> Either JsonError [(b, d)]
entries = \case
            [] -> [(b, d)] -> Either JsonError [(b, d)]
forall a b. b -> Either a b
Right []
            (Key
k, Value
v) : [(Key, Value)]
rest -> case JsonParsor c d -> Value -> Either JsonError d
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor c d
p Value
v of
              Right d
b -> ((Text -> b
keyOf (Key -> Text
Key.toText Key
k), d
b) (b, d) -> [(b, d)] -> [(b, d)]
forall a. a -> [a] -> [a]
:) ([(b, d)] -> [(b, d)])
-> Either JsonError [(b, d)] -> Either JsonError [(b, d)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Key, Value)] -> Either JsonError [(b, d)]
entries [(Key, Value)]
rest
              Left JsonError
err -> JSONPathElement
-> Either JsonError [(b, d)] -> Either JsonError [(b, d)]
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Key -> JSONPathElement
Key Key
k) (JsonError -> Either JsonError [(b, d)]
forall a b. a -> Either a b
Left JsonError
err)
      Value
v -> String -> Value -> Either JsonError (Map b d)
forall a. String -> Value -> Either JsonError a
jsonMismatch String
"object" Value
v
    Maybe (Text -> b)
Nothing -> (Map a c -> [(a, c)])
-> ([(b, d)] -> Map b d)
-> JsonParsor [(a, c)] [(b, d)]
-> JsonParsor (Map a c) (Map b d)
forall a b c d.
(a -> b) -> (c -> d) -> JsonParsor b c -> JsonParsor a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Map a c -> [(a, c)]
forall k a. Map k a -> [(k, a)]
Map.toList [(b, d)] -> Map b d
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ((forall (q :: * -> * -> *).
 JsonObj JsonParsor q =>
 q [(a, c)] [(b, d)])
-> JsonParsor [(a, c)] [(b, d)]
forall a b.
(forall (q :: * -> * -> *). JsonObj JsonParsor q => q a b)
-> JsonParsor a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject ((forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonParsor c d -> q [(a, c)] [(b, d)]
forall a b c d.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonParsor c d -> q [(a, c)] [(b, d)]
forall (p :: * -> * -> *) (q :: * -> * -> *) a b c d.
JsonObj p q =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
jsonDict k a b
forall (k :: * -> * -> *). JsonStr k => k a b
key JsonParsor c d
p))
  jsonArray :: forall a b. JsonParsor a b -> JsonParsor [a] [b]
jsonArray JsonParsor a b
p = (Value -> Either JsonError [b]) -> JsonParsor [a] [b]
forall b a. (Value -> Either JsonError b) -> JsonParsor a b
jsonParsor ((Value -> Either JsonError [b]) -> JsonParsor [a] [b])
-> (Value -> Either JsonError [b]) -> JsonParsor [a] [b]
forall a b. (a -> b) -> a -> b
$ \case
    Array Array
arr | Just [b]
parsed <- JsonParsor a b -> Maybe (Array -> Maybe [b])
forall a b. JsonParsor a b -> Maybe (Array -> Maybe [b])
jsonParsorArray JsonParsor a b
p Maybe (Array -> Maybe [b])
-> ((Array -> Maybe [b]) -> Maybe [b]) -> Maybe [b]
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ((Array -> Maybe [b]) -> Array -> Maybe [b]
forall a b. (a -> b) -> a -> b
$ Array
arr) -> [b] -> Either JsonError [b]
forall a b. b -> Either a b
Right [b]
parsed
    Array Array
arr -> (Int -> Value -> Either JsonError b)
-> [Int] -> [Value] -> Either JsonError [b]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM
      (\Int
i Value
v -> JSONPathElement -> Either JsonError b -> Either JsonError b
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Int -> JSONPathElement
Index Int
i) (JsonParsor a b -> Value -> Either JsonError b
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a b
p Value
v)) [Int
0 ..] (Array -> [Value]
forall a. Vector a -> [a]
Vector.toList Array
arr)
    Value
v -> String -> Value -> Either JsonError [b]
forall a. String -> Value -> Either JsonError a
jsonMismatch String
"array" Value
v
  jsonTuple :: forall a b.
(forall (q :: * -> * -> *). JsonTup JsonParsor q => q a b)
-> JsonParsor a b
jsonTuple forall (q :: * -> * -> *). JsonTup JsonParsor q => q a b
tup = (Value -> Either JsonError b) -> JsonParsor a b
forall b a. (Value -> Either JsonError b) -> JsonParsor a b
jsonParsor ((Value -> Either JsonError b) -> JsonParsor a b)
-> (Value -> Either JsonError b) -> JsonParsor a b
forall a b. (a -> b) -> a -> b
$ \case
    Array Array
arr | Just (Int
n, Array -> Int -> Either JsonError b
fixed) <- TupParsor a b -> Maybe (Int, Array -> Int -> Either JsonError b)
forall a b.
TupParsor a b -> Maybe (Int, Array -> Int -> Either JsonError b)
tupParsorFixed TupParsor a b
parsor ->
      Array -> Int -> Either JsonError b
fixed Array
arr Int
0 Either JsonError b
-> (b -> Either JsonError b) -> Either JsonError b
forall a b.
Either JsonError a
-> (a -> Either JsonError b) -> Either JsonError b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \b
b ->
        if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Array -> Int
forall a. Vector a -> Int
Vector.length Array
arr then b -> Either JsonError b
forall a b. b -> Either a b
Right b
b
        else String -> Maybe Value -> Either JsonError b
forall a. String -> Maybe Value -> Either JsonError a
jsonMissing (Int -> String
countElements Int
n) (Value -> Maybe Value
forall a. a -> Maybe a
Just (Array -> Value
Array Array
arr))
    Array Array
arr ->
      let
        outcomes :: [Either JsonError (b, Int)]
outcomes = TupParsor a b -> Array -> Int -> [Either JsonError (b, Int)]
forall a b.
TupParsor a b -> Array -> Int -> [Either JsonError (b, Int)]
runTupParsor TupParsor a b
parsor Array
arr Int
0
        incomplete :: Either JsonError (b, Int) -> JsonError
incomplete = \case
          Left JsonError
err -> JsonError
err
          Right (b
_, Int
n) ->
            [JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [] [Int -> String
countElements Int
n] (Either String Value -> Maybe (Either String Value)
forall a. a -> Maybe a
Just (Value -> Either String Value
forall a b. b -> Either a b
Right (Array -> Value
Array Array
arr)))
              JsonErrorSort
JsonMissing []
      in
        case [b
b | Right (b
b, Int
n) <- [Either JsonError (b, Int)]
outcomes, Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Array -> Int
forall a. Vector a -> Int
Vector.length Array
arr] of
          b
b : [b]
_ -> b -> Either JsonError b
forall a b. b -> Either a b
Right b
b
          [] -> JsonError -> Either JsonError b
forall a b. a -> Either a b
Left ((JsonError -> JsonError -> JsonError)
-> JsonError -> [JsonError] -> JsonError
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl JsonError -> JsonError -> JsonError
jsonOrElse JsonError
unexpected ((Either JsonError (b, Int) -> JsonError)
-> [Either JsonError (b, Int)] -> [JsonError]
forall a b. (a -> b) -> [a] -> [b]
map Either JsonError (b, Int) -> JsonError
incomplete [Either JsonError (b, Int)]
outcomes))
            where
              unexpected :: JsonError
unexpected =
                [JSONPathElement]
-> [String]
-> Maybe (Either String Value)
-> JsonErrorSort
-> Forest String
-> JsonError
JsonError [] [] (Either String Value -> Maybe (Either String Value)
forall a. a -> Maybe a
Just (Value -> Either String Value
forall a b. b -> Either a b
Right (Array -> Value
Array Array
arr))) JsonErrorSort
JsonMismatch []
    Value
v -> String -> Value -> Either JsonError b
forall a. String -> Value -> Either JsonError a
jsonMismatch String
"array" Value
v
    where
      parsor :: TupParsor a b
parsor = forall (q :: * -> * -> *). JsonTup JsonParsor q => q a b
tup @TupParsor
  jsonObject :: forall a b.
(forall (q :: * -> * -> *). JsonObj JsonParsor q => q a b)
-> JsonParsor a b
jsonObject forall (q :: * -> * -> *). JsonObj JsonParsor q => q a b
obj = Bool -> ObjParsor a b -> JsonParsor a b
forall a b. Bool -> ObjParsor a b -> JsonParsor a b
objectParsor Bool
False ObjParsor a b
forall (q :: * -> * -> *). JsonObj JsonParsor q => q a b
obj
  jsonObjectStrict :: forall a b.
(forall (q :: * -> * -> *). JsonObj JsonParsor q => q a b)
-> JsonParsor a b
jsonObjectStrict forall (q :: * -> * -> *). JsonObj JsonParsor q => q a b
obj = Bool -> ObjParsor a b -> JsonParsor a b
forall a b. Bool -> ObjParsor a b -> JsonParsor a b
objectParsor Bool
True ObjParsor a b
forall (q :: * -> * -> *). JsonObj JsonParsor q => q a b
obj

{- | Parse an t'Object' by its properties, and, if it's rejecting,
reject the first property which isn't named, as `jsonObjectStrict`'s
default would, but without parsing the rest of the properties.
-}
objectParsor :: Bool -> ObjParsor a b -> JsonParsor a b
objectParsor :: forall a b. Bool -> ObjParsor a b -> JsonParsor a b
objectParsor Bool
rejecting ObjParsor a b
obj = Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
forall a b.
Maybe (Dispatch b)
-> (Value -> Either JsonError b)
-> Maybe (Array -> Maybe [b])
-> Maybe (Text -> b)
-> JsonParsor a b
JsonParsor Maybe (Dispatch b)
dispatch Value -> Either JsonError b
parse Maybe (Array -> Maybe [b])
forall a. Maybe a
Nothing Maybe (Text -> b)
forall a. Maybe a
Nothing
  where
    overlap :: Maybe Key
overlap = ([Key] -> Maybe Key -> Maybe Key)
-> Maybe Key -> [[Key]] -> Maybe Key
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Maybe Key -> Maybe Key -> Maybe Key
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) (Maybe Key -> Maybe Key -> Maybe Key)
-> ([Key] -> Maybe Key) -> [Key] -> Maybe Key -> Maybe Key
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Key] -> Maybe Key
duplicateKey) Maybe Key
forall a. Maybe a
Nothing (ObjParsor a b -> [[Key]]
forall a b. ObjParsor a b -> [[Key]]
objParsorShapes ObjParsor a b
obj)
    parse :: Value -> Either JsonError b
parse = \case
      Object Object
o -> case Maybe Key
overlap of
        Just Key
key ->
          String -> Maybe Value -> Either JsonError b
forall a. String -> Maybe Value -> Either JsonError a
jsonMissing (String
"another key " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Key -> String
showKey Key
key) (Value -> Maybe Value
forall a. a -> Maybe a
Just (Object -> Value
Object Object
o))
        Maybe Key
Nothing -> case ObjParsor a b -> HashSet Key -> Object -> Either JsonError b
forall a b.
ObjParsor a b -> HashSet Key -> Object -> Either JsonError b
runObjParsor ObjParsor a b
obj HashSet Key
named Object
o of
          Right b
_
            | Bool
rejecting
            , Maybe Int
exactSize Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int -> Maybe Int
forall a. a -> Maybe a
Just (Object -> Int
forall v. KeyMap v -> Int
KeyMap.size Object
o)
            , Just (Key
k, Value
v) <- ((Key, Value) -> Bool) -> [(Key, Value)] -> Maybe (Key, Value)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (Bool -> Bool
not (Bool -> Bool) -> ((Key, Value) -> Bool) -> (Key, Value) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key -> HashSet Key -> Bool
forall a. Hashable a => a -> HashSet a -> Bool
`HashSet.member` HashSet Key
named) (Key -> Bool) -> ((Key, Value) -> Key) -> (Key, Value) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key, Value) -> Key
forall a b. (a, b) -> a
fst)
                (Object -> [(Key, Value)]
forall v. KeyMap v -> [(Key, v)]
KeyMap.toList Object
o) ->
                JSONPathElement -> Either JsonError b -> Either JsonError b
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Key -> JSONPathElement
Key Key
k) (Maybe Value -> Either JsonError b
forall a. Maybe Value -> Either JsonError a
jsonUnexpected (Value -> Maybe Value
forall a. a -> Maybe a
Just Value
v))
          Either JsonError b
result -> Either JsonError b
result
      Value
v -> String -> Value -> Either JsonError b
forall a. String -> Value -> Either JsonError a
jsonMismatch String
"object" Value
v
    named :: HashSet Key
named = [Key] -> HashSet Key
forall a. Hashable a => [a] -> HashSet a
HashSet.fromList ([[Key]] -> [Key]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (ObjParsor a b -> [[Key]]
forall a b. ObjParsor a b -> [[Key]]
objParsorShapes ObjParsor a b
obj))
    -- The size of an object having only the keys of its parsed shape,
    -- when its keys are all required & its shapes are the same size.
    exactSize :: Maybe Int
exactSize = case [Int] -> [Int]
forall a. Eq a => [a] -> [a]
nub (([Key] -> Int) -> [[Key]] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map [Key] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (ObjParsor a b -> [[Key]]
forall a b. ObjParsor a b -> [[Key]]
objParsorShapes ObjParsor a b
obj)) of
      [Int
size] | ObjParsor a b -> Bool
forall a b. ObjParsor a b -> Bool
objParsorRequired ObjParsor a b
obj -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
size
      [Int]
_ -> Maybe Int
forall a. Maybe a
Nothing
    dispatch :: Maybe (Dispatch b)
dispatch = case ObjParsor a b -> [(Key, Set Text)]
forall a b. ObjParsor a b -> [(Key, Set Text)]
objParsorTags ObjParsor a b
obj of
      (Key
key, Set Text
tags) : [(Key, Set Text)]
_ ->
        Dispatch b -> Maybe (Dispatch b)
forall a. a -> Maybe a
Just (Maybe Key -> Map Text (Value -> Either JsonError b) -> Dispatch b
forall b.
Maybe Key -> Map Text (Value -> Either JsonError b) -> Dispatch b
Dispatch (Key -> Maybe Key
forall a. a -> Maybe a
Just Key
key) ((Text -> Value -> Either JsonError b)
-> Set Text -> Map Text (Value -> Either JsonError b)
forall k a. (k -> a) -> Set k -> Map k a
Map.fromSet ((Value -> Either JsonError b)
-> Text -> Value -> Either JsonError b
forall a b. a -> b -> a
const Value -> Either JsonError b
parse) Set Text
tags))
      [] -> Maybe (Dispatch b)
forall a. Maybe a
Nothing

instance Functor (TupParsor a) where
  fmap :: forall a b. (a -> b) -> TupParsor a a -> TupParsor a b
fmap a -> b
f (TupParsor Maybe (Int, Array -> Int -> Either JsonError a)
fixed Array -> Int -> [Either JsonError (a, Int)]
general) = Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
forall a b.
Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
TupParsor
    (((Array -> Int -> Either JsonError a)
 -> Array -> Int -> Either JsonError b)
-> (Int, Array -> Int -> Either JsonError a)
-> (Int, Array -> Int -> Either JsonError b)
forall a b. (a -> b) -> (Int, a) -> (Int, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Array -> Int -> Either JsonError a
p Array
arr Int
i -> (a -> b) -> Either JsonError a -> Either JsonError b
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
onSuccess a -> b
f (Array -> Int -> Either JsonError a
p Array
arr Int
i)) ((Int, Array -> Int -> Either JsonError a)
 -> (Int, Array -> Int -> Either JsonError b))
-> Maybe (Int, Array -> Int -> Either JsonError a)
-> Maybe (Int, Array -> Int -> Either JsonError b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Int, Array -> Int -> Either JsonError a)
fixed)
    (\Array
arr Int
i -> (Either JsonError (a, Int) -> Either JsonError (b, Int))
-> [Either JsonError (a, Int)] -> [Either JsonError (b, Int)]
forall a b. (a -> b) -> [a] -> [b]
map (((a, Int) -> (b, Int))
-> Either JsonError (a, Int) -> Either JsonError (b, Int)
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> (a, Int) -> (b, Int)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (a, c) (b, c)
first' a -> b
f)) (Array -> Int -> [Either JsonError (a, Int)]
general Array
arr Int
i))
instance Applicative (TupParsor a) where
  pure :: forall a. a -> TupParsor a a
pure a
b = Maybe (Int, Array -> Int -> Either JsonError a)
-> (Array -> Int -> [Either JsonError (a, Int)]) -> TupParsor a a
forall a b.
Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
TupParsor ((Int, Array -> Int -> Either JsonError a)
-> Maybe (Int, Array -> Int -> Either JsonError a)
forall a. a -> Maybe a
Just (Int
0, \Array
_ Int
_ -> a -> Either JsonError a
forall a b. b -> Either a b
Right a
b)) (\Array
_ Int
i -> [(a, Int) -> Either JsonError (a, Int)
forall a b. b -> Either a b
Right (a
b, Int
i)])
  TupParsor Maybe (Int, Array -> Int -> Either JsonError (a -> b))
fixed0 Array -> Int -> [Either JsonError (a -> b, Int)]
general0 <*> :: forall a b. TupParsor a (a -> b) -> TupParsor a a -> TupParsor a b
<*> TupParsor Maybe (Int, Array -> Int -> Either JsonError a)
fixed1 Array -> Int -> [Either JsonError (a, Int)]
general1 =
    Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
forall a b.
Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
TupParsor (((Int, Array -> Int -> Either JsonError (a -> b))
 -> (Int, Array -> Int -> Either JsonError a)
 -> (Int, Array -> Int -> Either JsonError b))
-> Maybe (Int, Array -> Int -> Either JsonError (a -> b))
-> Maybe (Int, Array -> Int -> Either JsonError a)
-> Maybe (Int, Array -> Int -> Either JsonError b)
forall a b c. (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (Int, Array -> Int -> Either JsonError (a -> b))
-> (Int, Array -> Int -> Either JsonError a)
-> (Int, Array -> Int -> Either JsonError b)
forall {a} {t} {a} {b}.
Num a =>
(a, t -> a -> Either JsonError (a -> b))
-> (a, t -> a -> Either JsonError a)
-> (a, t -> a -> Either JsonError b)
sequenced Maybe (Int, Array -> Int -> Either JsonError (a -> b))
fixed0 Maybe (Int, Array -> Int -> Either JsonError a)
fixed1) Array -> Int -> [Either JsonError (b, Int)]
backtracking
    where
      sequenced :: (a, t -> a -> Either JsonError (a -> b))
-> (a, t -> a -> Either JsonError a)
-> (a, t -> a -> Either JsonError b)
sequenced (a
n0, t -> a -> Either JsonError (a -> b)
p) (a
n1, t -> a -> Either JsonError a
q) = (a
n0 a -> a -> a
forall a. Num a => a -> a -> a
+ a
n1, \t
arr a
i -> case t -> a -> Either JsonError (a -> b)
p t
arr a
i of
        Left JsonError
err -> JsonError -> Either JsonError b
forall a b. a -> Either a b
Left JsonError
err
        Right a -> b
f -> (a -> b) -> Either JsonError a -> Either JsonError b
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
onSuccess a -> b
f (t -> a -> Either JsonError a
q t
arr (a -> Either JsonError a) -> a -> Either JsonError a
forall a b. (a -> b) -> a -> b
$! a
i a -> a -> a
forall a. Num a => a -> a -> a
+ a
n0))
      backtracking :: Array -> Int -> [Either JsonError (b, Int)]
backtracking Array
arr Int
i = Array -> Int -> [Either JsonError (a -> b, Int)]
general0 Array
arr Int
i [Either JsonError (a -> b, Int)]
-> (Either JsonError (a -> b, Int) -> [Either JsonError (b, Int)])
-> [Either JsonError (b, Int)]
forall a b. [a] -> (a -> [b]) -> [b]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        Left JsonError
err -> [JsonError -> Either JsonError (b, Int)
forall a b. a -> Either a b
Left JsonError
err]
        Right (a -> b
f, Int
j) -> (Either JsonError (a, Int) -> Either JsonError (b, Int))
-> [Either JsonError (a, Int)] -> [Either JsonError (b, Int)]
forall a b. (a -> b) -> [a] -> [b]
map (((a, Int) -> (b, Int))
-> Either JsonError (a, Int) -> Either JsonError (b, Int)
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> (a, Int) -> (b, Int)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (a, c) (b, c)
first' a -> b
f)) (Array -> Int -> [Either JsonError (a, Int)]
general1 Array
arr Int
j)
instance Profunctor TupParsor where
  dimap :: forall a b c d.
(a -> b) -> (c -> d) -> TupParsor b c -> TupParsor a d
dimap a -> b
_ c -> d
g = TupParsor b d -> TupParsor a d
forall a b. Coercible a b => a -> b
coerce (TupParsor b d -> TupParsor a d)
-> (TupParsor b c -> TupParsor b d)
-> TupParsor b c
-> TupParsor a d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> d) -> TupParsor b c -> TupParsor b d
forall a b. (a -> b) -> TupParsor b a -> TupParsor b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> d
g
  q b c
_ #. :: forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> TupParsor a b -> TupParsor a c
#. TupParsor a b
p = TupParsor a b -> TupParsor a c
forall a b. Coercible a b => a -> b
coerce TupParsor a b
p
  TupParsor b c
p .# :: forall a b c (q :: * -> * -> *).
Coercible b a =>
TupParsor b c -> q a b -> TupParsor a c
.# q a b
_ = TupParsor b c -> TupParsor a c
forall a b. Coercible a b => a -> b
coerce TupParsor b c
p
instance Choice TupParsor where
  left' :: forall a b c. TupParsor a b -> TupParsor (Either a c) (Either b c)
left' = Either (TupParsor a b) (TupParsor c c)
-> TupParsor (Either a c) (Either b c)
forall a b c d.
Either (TupParsor a b) (TupParsor c d)
-> TupParsor (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianChoice p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (Either (TupParsor a b) (TupParsor c c)
 -> TupParsor (Either a c) (Either b c))
-> (TupParsor a b -> Either (TupParsor a b) (TupParsor c c))
-> TupParsor a b
-> TupParsor (Either a c) (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupParsor a b -> Either (TupParsor a b) (TupParsor c c)
forall a b. a -> Either a b
Left
  right' :: forall a b c. TupParsor a b -> TupParsor (Either c a) (Either c b)
right' = Either (TupParsor c c) (TupParsor a b)
-> TupParsor (Either c a) (Either c b)
forall a b c d.
Either (TupParsor a b) (TupParsor c d)
-> TupParsor (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianChoice p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (Either (TupParsor c c) (TupParsor a b)
 -> TupParsor (Either c a) (Either c b))
-> (TupParsor a b -> Either (TupParsor c c) (TupParsor a b))
-> TupParsor a b
-> TupParsor (Either c a) (Either c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupParsor a b -> Either (TupParsor c c) (TupParsor a b)
forall a b. b -> Either a b
Right
instance CocartesianMonoidal TupParsor
instance CocartesianChoice TupParsor where
  alternate :: forall a b c d.
Either (TupParsor a b) (TupParsor c d)
-> TupParsor (Either a c) (Either b d)
alternate = (TupParsor a b -> TupParsor (Either a c) (Either b d))
-> (TupParsor c d -> TupParsor (Either a c) (Either b d))
-> Either (TupParsor a b) (TupParsor c d)
-> TupParsor (Either a c) (Either b d)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((b -> Either b d)
-> TupParsor (Either a c) b -> TupParsor (Either a c) (Either b d)
forall a b.
(a -> b) -> TupParsor (Either a c) a -> TupParsor (Either a c) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either b d
forall a b. a -> Either a b
Left (TupParsor (Either a c) b -> TupParsor (Either a c) (Either b d))
-> (TupParsor a b -> TupParsor (Either a c) b)
-> TupParsor a b
-> TupParsor (Either a c) (Either b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupParsor a b -> TupParsor (Either a c) b
forall a b. Coercible a b => a -> b
coerce) ((d -> Either b d)
-> TupParsor (Either a c) d -> TupParsor (Either a c) (Either b d)
forall a b.
(a -> b) -> TupParsor (Either a c) a -> TupParsor (Either a c) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap d -> Either b d
forall a b. b -> Either a b
Right (TupParsor (Either a c) d -> TupParsor (Either a c) (Either b d))
-> (TupParsor c d -> TupParsor (Either a c) d)
-> TupParsor c d
-> TupParsor (Either a c) (Either b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupParsor c d -> TupParsor (Either a c) d
forall a b. Coercible a b => a -> b
coerce)
instance DisjunctiveMonoid (TupParsor a b) where
  falseP :: TupParsor a b
falseP = Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
forall a b.
Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
TupParsor Maybe (Int, Array -> Int -> Either JsonError b)
forall a. Maybe a
Nothing (\Array
_ Int
_ -> [])
  TupParsor a b
p >|< :: TupParsor a b -> TupParsor a b -> TupParsor a b
>|< TupParsor a b
q = Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
forall a b.
Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
TupParsor Maybe (Int, Array -> Int -> Either JsonError b)
forall a. Maybe a
Nothing ((Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
forall a b. (a -> b) -> a -> b
$ \Array
arr Int
i ->
    TupParsor a b -> Array -> Int -> [Either JsonError (b, Int)]
forall a b.
TupParsor a b -> Array -> Int -> [Either JsonError (b, Int)]
runTupParsor TupParsor a b
p Array
arr Int
i [Either JsonError (b, Int)]
-> [Either JsonError (b, Int)] -> [Either JsonError (b, Int)]
forall a. Semigroup a => a -> a -> a
<> TupParsor a b -> Array -> Int -> [Either JsonError (b, Int)]
forall a b.
TupParsor a b -> Array -> Int -> [Either JsonError (b, Int)]
runTupParsor TupParsor a b
q Array
arr Int
i
-- | `manyP` tries longer repetitions first, never repeating an empty match.
instance Distributor TupParsor where
  manyP :: forall a b. TupParsor a b -> TupParsor [a] [b]
manyP (TupParsor Maybe (Int, Array -> Int -> Either JsonError b)
_ Array -> Int -> [Either JsonError (b, Int)]
p) = Maybe (Int, Array -> Int -> Either JsonError [b])
-> (Array -> Int -> [Either JsonError ([b], Int)])
-> TupParsor [a] [b]
forall a b.
Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
TupParsor Maybe (Int, Array -> Int -> Either JsonError [b])
forall a. Maybe a
Nothing Array -> Int -> [Either JsonError ([b], Int)]
go
    where
      go :: Array -> Int -> [Either JsonError ([b], Int)]
go Array
arr Int
i = (Either JsonError (b, Int) -> [Either JsonError ([b], Int)])
-> [Either JsonError (b, Int)] -> [Either JsonError ([b], Int)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Either JsonError (b, Int) -> [Either JsonError ([b], Int)]
step (Array -> Int -> [Either JsonError (b, Int)]
p Array
arr Int
i) [Either JsonError ([b], Int)]
-> [Either JsonError ([b], Int)] -> [Either JsonError ([b], Int)]
forall a. Semigroup a => a -> a -> a
<> [([b], Int) -> Either JsonError ([b], Int)
forall a b. b -> Either a b
Right ([], Int
i)]
        where
          step :: Either JsonError (b, Int) -> [Either JsonError ([b], Int)]
step = \case
            Left JsonError
err -> [JsonError -> Either JsonError ([b], Int)
forall a b. a -> Either a b
Left JsonError
err]
            Right (b
b, Int
j) | Int
j Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
i -> (Either JsonError ([b], Int) -> Either JsonError ([b], Int))
-> [Either JsonError ([b], Int)] -> [Either JsonError ([b], Int)]
forall a b. (a -> b) -> [a] -> [b]
map ((([b], Int) -> ([b], Int))
-> Either JsonError ([b], Int) -> Either JsonError ([b], Int)
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([b] -> [b]) -> ([b], Int) -> ([b], Int)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (a, c) (b, c)
first' (b
b b -> [b] -> [b]
forall a. a -> [a] -> [a]
:))) (Array -> Int -> [Either JsonError ([b], Int)]
go Array
arr Int
j)
            Right (b, Int)
_ -> []
instance Alternative (TupParsor a) where
  empty :: forall a. TupParsor a a
empty = TupParsor a a
forall a. DisjunctiveMonoid a => a
falseP
  <|> :: forall a. TupParsor a a -> TupParsor a a -> TupParsor a a
(<|>) = TupParsor a a -> TupParsor a a -> TupParsor a a
forall a. DisjunctiveMonoid a => a -> a -> a
(>|<)
  many :: forall a. TupParsor a a -> TupParsor a [a]
many = (a -> [a]) -> TupParsor [a] [a] -> TupParsor a [a]
forall a b c. (a -> b) -> TupParsor b c -> TupParsor a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> [a]
forall a. a -> [a]
repeat (TupParsor [a] [a] -> TupParsor a [a])
-> (TupParsor a a -> TupParsor [a] [a])
-> TupParsor a a
-> TupParsor a [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupParsor a a -> TupParsor [a] [a]
forall a b. TupParsor a b -> TupParsor [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP
  some :: forall a. TupParsor a a -> TupParsor a [a]
some = (a -> [a]) -> TupParsor [a] [a] -> TupParsor a [a]
forall a b c. (a -> b) -> TupParsor b c -> TupParsor a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> [a]
forall a. a -> [a]
repeat (TupParsor [a] [a] -> TupParsor a [a])
-> (TupParsor a a -> TupParsor [a] [a])
-> TupParsor a a
-> TupParsor a [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupParsor a a -> TupParsor [a] [a]
forall a b. TupParsor a b -> TupParsor [a] [b]
forall (p :: * -> * -> *) a b. Alternator p => p a b -> p [a] [b]
someP
instance Alternator TupParsor
instance JsonTup JsonParsor TupParsor where
  jsonElem :: forall a b. JsonParsor a b -> TupParsor a b
jsonElem JsonParsor a b
p = Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
forall a b.
Maybe (Int, Array -> Int -> Either JsonError b)
-> (Array -> Int -> [Either JsonError (b, Int)]) -> TupParsor a b
TupParsor
    ((Int, Array -> Int -> Either JsonError b)
-> Maybe (Int, Array -> Int -> Either JsonError b)
forall a. a -> Maybe a
Just (Int
1, Array -> Int -> Either JsonError b
jsonElement))
    (\Array
arr Int
i -> [(, Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (b -> (b, Int)) -> Either JsonError b -> Either JsonError (b, Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Array -> Int -> Either JsonError b
jsonElement Array
arr Int
i])
    where
      jsonElement :: Array -> Int -> Either JsonError b
jsonElement Array
arr Int
i = case Array
arr Array -> Int -> Maybe Value
forall a. Vector a -> Int -> Maybe a
Vector.!? Int
i of
        Maybe Value
Nothing ->
          String -> Maybe Value -> Either JsonError b
forall a. String -> Maybe Value -> Either JsonError a
jsonMissing (String
"at least " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> String
countElements (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)) (Value -> Maybe Value
forall a. a -> Maybe a
Just (Array -> Value
Array Array
arr))
        Just Value
v -> JSONPathElement -> Either JsonError b -> Either JsonError b
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Int -> JSONPathElement
Index Int
i) (JsonParsor a b -> Value -> Either JsonError b
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a b
p Value
v)

instance Functor (ObjParsor a) where
  fmap :: forall a b. (a -> b) -> ObjParsor a a -> ObjParsor a b
fmap a -> b
f (ObjParsor [[Key]]
keys [(Key, Set Text)]
tags Bool
required HashSet Key -> Object -> Either JsonError a
p) =
    [[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
forall a b.
[[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
ObjParsor [[Key]]
keys [(Key, Set Text)]
tags Bool
required (\HashSet Key
named Object
o -> (a -> b) -> Either JsonError a -> Either JsonError b
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
onSuccess a -> b
f (HashSet Key -> Object -> Either JsonError a
p HashSet Key
named Object
o))
instance Applicative (ObjParsor a) where
  pure :: forall a. a -> ObjParsor a a
pure a
b = [[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError a)
-> ObjParsor a a
forall a b.
[[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
ObjParsor [[]] [] Bool
True (\HashSet Key
_ Object
_ -> a -> Either JsonError a
forall a b. b -> Either a b
Right a
b)
  ObjParsor [[Key]]
keys0 [(Key, Set Text)]
tags0 Bool
required0 HashSet Key -> Object -> Either JsonError (a -> b)
p0 <*> :: forall a b. ObjParsor a (a -> b) -> ObjParsor a a -> ObjParsor a b
<*> ObjParsor [[Key]]
keys1 [(Key, Set Text)]
tags1 Bool
required1 HashSet Key -> Object -> Either JsonError a
p1 =
    [[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
forall a b.
[[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
ObjParsor (([Key] -> [Key] -> [Key]) -> [[Key]] -> [[Key]] -> [[Key]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 [Key] -> [Key] -> [Key]
forall a. Semigroup a => a -> a -> a
(<>) [[Key]]
keys0 [[Key]]
keys1) ([(Key, Set Text)]
tags0 [(Key, Set Text)] -> [(Key, Set Text)] -> [(Key, Set Text)]
forall a. Semigroup a => a -> a -> a
<> [(Key, Set Text)]
tags1)
      (Bool
required0 Bool -> Bool -> Bool
&& Bool
required1) ((HashSet Key -> Object -> Either JsonError b) -> ObjParsor a b)
-> (HashSet Key -> Object -> Either JsonError b) -> ObjParsor a b
forall a b. (a -> b) -> a -> b
$ \HashSet Key
named Object
o ->
      case HashSet Key -> Object -> Either JsonError (a -> b)
p0 HashSet Key
named Object
o of
        Left JsonError
err -> JsonError -> Either JsonError b
forall a b. a -> Either a b
Left JsonError
err
        Right a -> b
f -> (a -> b) -> Either JsonError a -> Either JsonError b
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
onSuccess a -> b
f (HashSet Key -> Object -> Either JsonError a
p1 HashSet Key
named Object
o)
instance Profunctor ObjParsor where
  dimap :: forall a b c d.
(a -> b) -> (c -> d) -> ObjParsor b c -> ObjParsor a d
dimap a -> b
_ c -> d
g (ObjParsor [[Key]]
keys [(Key, Set Text)]
tags Bool
required HashSet Key -> Object -> Either JsonError c
p) =
    [[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError d)
-> ObjParsor a d
forall a b.
[[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
ObjParsor [[Key]]
keys [(Key, Set Text)]
tags Bool
required (\HashSet Key
named Object
o -> (c -> d) -> Either JsonError c -> Either JsonError d
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
onSuccess c -> d
g (HashSet Key -> Object -> Either JsonError c
p HashSet Key
named Object
o))
  q b c
_ #. :: forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> ObjParsor a b -> ObjParsor a c
#. ObjParsor a b
p = ObjParsor a b -> ObjParsor a c
forall a b. Coercible a b => a -> b
coerce ObjParsor a b
p
  ObjParsor b c
p .# :: forall a b c (q :: * -> * -> *).
Coercible b a =>
ObjParsor b c -> q a b -> ObjParsor a c
.# q a b
_ = ObjParsor b c -> ObjParsor a c
forall a b. Coercible a b => a -> b
coerce ObjParsor b c
p
instance Choice ObjParsor where
  left' :: forall a b c. ObjParsor a b -> ObjParsor (Either a c) (Either b c)
left' = (b -> Either b c)
-> ObjParsor (Either a c) b -> ObjParsor (Either a c) (Either b c)
forall a b.
(a -> b) -> ObjParsor (Either a c) a -> ObjParsor (Either a c) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either b c
forall a b. a -> Either a b
Left (ObjParsor (Either a c) b -> ObjParsor (Either a c) (Either b c))
-> (ObjParsor a b -> ObjParsor (Either a c) b)
-> ObjParsor a b
-> ObjParsor (Either a c) (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjParsor a b -> ObjParsor (Either a c) b
forall a b. Coercible a b => a -> b
coerce
  right' :: forall a b c. ObjParsor a b -> ObjParsor (Either c a) (Either c b)
right' = (b -> Either c b)
-> ObjParsor (Either c a) b -> ObjParsor (Either c a) (Either c b)
forall a b.
(a -> b) -> ObjParsor (Either c a) a -> ObjParsor (Either c a) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either c b
forall a b. b -> Either a b
Right (ObjParsor (Either c a) b -> ObjParsor (Either c a) (Either c b))
-> (ObjParsor a b -> ObjParsor (Either c a) b)
-> ObjParsor a b
-> ObjParsor (Either c a) (Either c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjParsor a b -> ObjParsor (Either c a) b
forall a b. Coercible a b => a -> b
coerce
instance CocartesianMonoidal ObjParsor
instance CocartesianChoice ObjParsor where
  alternate :: forall a b c d.
Either (ObjParsor a b) (ObjParsor c d)
-> ObjParsor (Either a c) (Either b d)
alternate = (ObjParsor a b -> ObjParsor (Either a c) (Either b d))
-> (ObjParsor c d -> ObjParsor (Either a c) (Either b d))
-> Either (ObjParsor a b) (ObjParsor c d)
-> ObjParsor (Either a c) (Either b d)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((b -> Either b d)
-> ObjParsor (Either a c) b -> ObjParsor (Either a c) (Either b d)
forall a b.
(a -> b) -> ObjParsor (Either a c) a -> ObjParsor (Either a c) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either b d
forall a b. a -> Either a b
Left (ObjParsor (Either a c) b -> ObjParsor (Either a c) (Either b d))
-> (ObjParsor a b -> ObjParsor (Either a c) b)
-> ObjParsor a b
-> ObjParsor (Either a c) (Either b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjParsor a b -> ObjParsor (Either a c) b
forall a b. Coercible a b => a -> b
coerce) ((d -> Either b d)
-> ObjParsor (Either a c) d -> ObjParsor (Either a c) (Either b d)
forall a b.
(a -> b) -> ObjParsor (Either a c) a -> ObjParsor (Either a c) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap d -> Either b d
forall a b. b -> Either a b
Right (ObjParsor (Either a c) d -> ObjParsor (Either a c) (Either b d))
-> (ObjParsor c d -> ObjParsor (Either a c) d)
-> ObjParsor c d
-> ObjParsor (Either a c) (Either b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjParsor c d -> ObjParsor (Either a c) d
forall a b. Coercible a b => a -> b
coerce)
instance DisjunctiveMonoid (ObjParsor a b) where
  falseP :: ObjParsor a b
falseP = [[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
forall a b.
[[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
ObjParsor [] [] Bool
True (\HashSet Key
_ Object
o -> Maybe Value -> Either JsonError b
forall a. Maybe Value -> Either JsonError a
jsonUnexpected (Value -> Maybe Value
forall a. a -> Maybe a
Just (Object -> Value
Object Object
o)))
  ObjParsor a b
p >|< :: ObjParsor a b -> ObjParsor a b -> ObjParsor a b
>|< ObjParsor a b
q = [[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
forall a b.
[[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
ObjParsor (ObjParsor a b -> [[Key]]
forall a b. ObjParsor a b -> [[Key]]
objParsorShapes ObjParsor a b
p [[Key]] -> [[Key]] -> [[Key]]
forall a. Semigroup a => a -> a -> a
<> ObjParsor a b -> [[Key]]
forall a b. ObjParsor a b -> [[Key]]
objParsorShapes ObjParsor a b
q) []
    (ObjParsor a b -> Bool
forall a b. ObjParsor a b -> Bool
objParsorRequired ObjParsor a b
p Bool -> Bool -> Bool
&& ObjParsor a b -> Bool
forall a b. ObjParsor a b -> Bool
objParsorRequired ObjParsor a b
q) ((HashSet Key -> Object -> Either JsonError b) -> ObjParsor a b)
-> (HashSet Key -> Object -> Either JsonError b) -> ObjParsor a b
forall a b. (a -> b) -> a -> b
$
    \HashSet Key
named Object
o -> case ObjParsor a b -> HashSet Key -> Object -> Either JsonError b
forall a b.
ObjParsor a b -> HashSet Key -> Object -> Either JsonError b
runObjParsor ObjParsor a b
p HashSet Key
named Object
o of
      Left JsonError
err -> (JsonError -> JsonError)
-> Either JsonError b -> Either JsonError b
forall a.
(JsonError -> JsonError)
-> Either JsonError a -> Either JsonError a
onFailure (JsonError -> JsonError -> JsonError
jsonOrElse JsonError
err) (ObjParsor a b -> HashSet Key -> Object -> Either JsonError b
forall a b.
ObjParsor a b -> HashSet Key -> Object -> Either JsonError b
runObjParsor ObjParsor a b
q HashSet Key
named Object
o)
      Either JsonError b
success -> Either JsonError b
success
instance JsonObj JsonParsor ObjParsor where
  jsonDict :: forall a b c d.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonParsor c d -> ObjParsor [(a, c)] [(b, d)]
jsonDict forall (k :: * -> * -> *). JsonStr k => k a b
key JsonParsor c d
p = [[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError [(b, d)])
-> ObjParsor [(a, c)] [(b, d)]
forall a b.
[[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
ObjParsor [[]] [] Bool
False ((HashSet Key -> Object -> Either JsonError [(b, d)])
 -> ObjParsor [(a, c)] [(b, d)])
-> (HashSet Key -> Object -> Either JsonError [(b, d)])
-> ObjParsor [(a, c)] [(b, d)]
forall a b. (a -> b) -> a -> b
$ \HashSet Key
named Object
o ->
    [(Key, Value)]
-> ((Key, Value) -> Either JsonError (b, d))
-> Either JsonError [(b, d)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for [(Key, Value)
kv | kv :: (Key, Value)
kv@(Key
k, Value
_) <- Object -> [(Key, Value)]
forall v. KeyMap v -> [(Key, v)]
KeyMap.toList Object
o, Bool -> Bool
not (Key -> HashSet Key -> Bool
forall a. Hashable a => a -> HashSet a -> Bool
HashSet.member Key
k HashSet Key
named)] (((Key, Value) -> Either JsonError (b, d))
 -> Either JsonError [(b, d)])
-> ((Key, Value) -> Either JsonError (b, d))
-> Either JsonError [(b, d)]
forall a b. (a -> b) -> a -> b
$
      \(Key
k, Value
v) -> JSONPathElement
-> Either JsonError (b, d) -> Either JsonError (b, d)
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Key -> JSONPathElement
Key Key
k) (Either JsonError (b, d) -> Either JsonError (b, d))
-> Either JsonError (b, d) -> Either JsonError (b, d)
forall a b. (a -> b) -> a -> b
$
        (,) (b -> d -> (b, d))
-> Either JsonError b -> Either JsonError (d -> (b, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JsonParsor a b -> Value -> Either JsonError b
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a b
forall (k :: * -> * -> *). JsonStr k => k a b
key (Text -> Value
String (Key -> Text
Key.toText Key
k)) Either JsonError (d -> (b, d))
-> Either JsonError d -> Either JsonError (b, d)
forall a b.
Either JsonError (a -> b)
-> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JsonParsor c d -> Value -> Either JsonError d
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor c d
p Value
v
  Text
k !: :: forall a b. Text -> JsonParsor a b -> ObjParsor a b
!: JsonParsor a b
p = [[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
forall a b.
[[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
ObjParsor [[Key
key]] [(Key, Set Text)]
tags Bool
True ((HashSet Key -> Object -> Either JsonError b) -> ObjParsor a b)
-> (HashSet Key -> Object -> Either JsonError b) -> ObjParsor a b
forall a b. (a -> b) -> a -> b
$ \HashSet Key
_ Object
o -> case Key -> Object -> Maybe Value
forall v. Key -> KeyMap v -> Maybe v
KeyMap.lookup Key
key Object
o of
    Maybe Value
Nothing -> String -> Maybe Value -> Either JsonError b
forall a. String -> Maybe Value -> Either JsonError a
jsonMissing (String
"key " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
k) (Value -> Maybe Value
forall a. a -> Maybe a
Just (Object -> Value
Object Object
o))
    Just Value
v -> JSONPathElement -> Either JsonError b -> Either JsonError b
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Key -> JSONPathElement
Key Key
key) (JsonParsor a b -> Value -> Either JsonError b
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a b
p Value
v)
    where
      key :: Key
key = Text -> Key
Key.fromText Text
k
      tags :: [(Key, Set Text)]
tags = case JsonParsor a b -> Maybe (Dispatch b)
forall a b. JsonParsor a b -> Maybe (Dispatch b)
jsonParsorDispatch JsonParsor a b
p of
        Just (Dispatch Maybe Key
Nothing Map Text (Value -> Either JsonError b)
table) -> [(Key
key, Map Text (Value -> Either JsonError b) -> Set Text
forall k a. Map k a -> Set k
Map.keysSet Map Text (Value -> Either JsonError b)
table)]
        Maybe (Dispatch b)
_ -> []
  Text
k ?: :: forall a b. Text -> JsonParsor a b -> ObjParsor (Maybe a) (Maybe b)
?: JsonParsor a b
p = [[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError (Maybe b))
-> ObjParsor (Maybe a) (Maybe b)
forall a b.
[[Key]]
-> [(Key, Set Text)]
-> Bool
-> (HashSet Key -> Object -> Either JsonError b)
-> ObjParsor a b
ObjParsor [[Key
key]] [] Bool
False ((HashSet Key -> Object -> Either JsonError (Maybe b))
 -> ObjParsor (Maybe a) (Maybe b))
-> (HashSet Key -> Object -> Either JsonError (Maybe b))
-> ObjParsor (Maybe a) (Maybe b)
forall a b. (a -> b) -> a -> b
$ \HashSet Key
_ Object
o ->
    (Value -> Either JsonError b)
-> Maybe Value -> Either JsonError (Maybe b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse (JSONPathElement -> Either JsonError b -> Either JsonError b
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Key -> JSONPathElement
Key Key
key) (Either JsonError b -> Either JsonError b)
-> (Value -> Either JsonError b) -> Value -> Either JsonError b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonParsor a b -> Value -> Either JsonError b
forall a b. JsonParsor a b -> Value -> Either JsonError b
runJsonParsor JsonParsor a b
p) (Key -> Object -> Maybe Value
forall v. Key -> KeyMap v -> Maybe v
KeyMap.lookup Key
key Object
o)
    where
      key :: Key
key = Text -> Key
Key.fromText Text
k

duplicateKey :: [Key] -> Maybe Key
duplicateKey :: [Key] -> Maybe Key
duplicateKey [Key]
keys
  | (Key -> Key) -> Bool
forall b. Ord b => (Key -> b) -> Bool
ascending Key -> Key
forall a. a -> a
id Bool -> Bool -> Bool
|| (Key -> (Int, Key)) -> Bool
forall b. Ord b => (Key -> b) -> Bool
ascending Key -> (Int, Key)
shortlex = Maybe Key
forall a. Maybe a
Nothing
  | HashSet Key -> Int
forall a. HashSet a -> Int
HashSet.size ([Key] -> HashSet Key
forall a. Hashable a => [a] -> HashSet a
HashSet.fromList [Key]
keys) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [Key] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Key]
keys = Maybe Key
forall a. Maybe a
Nothing
  | Bool
otherwise = HashSet Key -> [Key] -> Maybe Key
forall {a}. Hashable a => HashSet a -> [a] -> Maybe a
go HashSet Key
forall a. HashSet a
HashSet.empty [Key]
keys
  where
    ascending :: Ord b => (Key -> b) -> Bool
    ascending :: forall b. Ord b => (Key -> b) -> Bool
ascending Key -> b
f = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ((Key -> Key -> Bool) -> [Key] -> [Key] -> [Bool]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Key
k Key
j -> Key -> b
f Key
k b -> b -> Bool
forall a. Ord a => a -> a -> Bool
< Key -> b
f Key
j) [Key]
keys (Int -> [Key] -> [Key]
forall a. Int -> [a] -> [a]
drop Int
1 [Key]
keys))
    shortlex :: Key -> (Int, Key)
shortlex Key
key = (Text -> Int
Text.lengthWord8 (Key -> Text
Key.toText Key
key), Key
key)
    go :: HashSet a -> [a] -> Maybe a
go HashSet a
_ [] = Maybe a
forall a. Maybe a
Nothing
    go HashSet a
seen (a
key : [a]
rest)
      | a -> HashSet a -> Bool
forall a. Hashable a => a -> HashSet a -> Bool
HashSet.member a
key HashSet a
seen = a -> Maybe a
forall a. a -> Maybe a
Just a
key
      | Bool
otherwise = HashSet a -> [a] -> Maybe a
go (a -> HashSet a -> HashSet a
forall a. Hashable a => a -> HashSet a -> HashSet a
HashSet.insert a
key HashSet a
seen) [a]
rest

showKey :: Key -> String
showKey :: Key -> String
showKey = Text -> String
forall a. Show a => a -> String
show (Text -> String) -> (Key -> Text) -> Key -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> Text
Key.toText

-- Printing interpreters --

-- | @aeson@'s representations of JSON strings, `Value`, `Encoding` & t'Key'.
class AesonStr val where
  aesonText :: Text -> val
  aesonString :: String -> val
  -- | Render a string literal, which is rendered once.
  aesonLiteral :: Text -> val
  aesonLiteral = Text -> val
forall val. AesonStr val => Text -> val
aesonText
  -- | Render an array of a primitive at once, when that's faster.
  aesonPrimitives :: (a -> val) -> Maybe ([a] -> val)
  aesonPrimitives a -> val
_ = Maybe ([a] -> val)
forall a. Maybe a
Nothing
  -- | Render text, or else its @aeson@ string `Encoding.Encoding'`.
  aesonEncodedText :: (Text, Encoding.Encoding' Text) -> val
  aesonEncodedText = Text -> val
forall val. AesonStr val => Text -> val
aesonText (Text -> val)
-> ((Text, Encoding' Text) -> Text)
-> (Text, Encoding' Text)
-> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, Encoding' Text) -> Text
forall a b. (a, b) -> a
fst

instance AesonStr Value where
  aesonText :: Text -> Value
aesonText = Text -> Value
String
  aesonString :: String -> Value
aesonString = Text -> Value
String (Text -> Value) -> (String -> Text) -> String -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack
  {-# INLINE aesonText #-}
  {-# INLINE aesonString #-}

instance AesonStr Key where
  aesonText :: Text -> Key
aesonText = Text -> Key
Key.fromText
  aesonString :: String -> Key
aesonString = String -> Key
Key.fromString

instance AesonStr (Encoding.Encoding' a) where
  aesonText :: Text -> Encoding' a
aesonText = Text -> Encoding' a
forall a. Text -> Encoding' a
Encoding.text
  aesonString :: String -> Encoding' a
aesonString = String -> Encoding' a
forall a. String -> Encoding' a
Encoding.string
  aesonLiteral :: Text -> Encoding' a
aesonLiteral = Builder -> Encoding' a
forall a. Builder -> Encoding' a
Encoding.unsafeToEncoding (Builder -> Encoding' a)
-> (Text -> Builder) -> Text -> Encoding' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictByteString -> Builder
Builder.byteString
    (StrictByteString -> Builder)
-> (Text -> StrictByteString) -> Text -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> StrictByteString
LByteString.toStrict (ByteString -> StrictByteString)
-> (Text -> ByteString) -> Text -> StrictByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Encoding' (ZonkAny 6) -> ByteString
forall a. Encoding' a -> ByteString
Encoding.encodingToLazyByteString (Encoding' (ZonkAny 6) -> ByteString)
-> (Text -> Encoding' (ZonkAny 6)) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Encoding' (ZonkAny 6)
forall a. Text -> Encoding' a
Encoding.text
  aesonPrimitives :: forall a. (a -> Encoding' a) -> Maybe ([a] -> Encoding' a)
aesonPrimitives a -> Encoding' a
render =
    ([a] -> Encoding' a) -> Maybe ([a] -> Encoding' a)
forall a. a -> Maybe a
Just (Encoding -> Encoding' a
forall a b. Encoding' a -> Encoding' b
retagEncoding (Encoding -> Encoding' a)
-> ([a] -> Encoding) -> [a] -> Encoding' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Encoding) -> [a] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
Encoding.list (Encoding' a -> Encoding
forall a b. Encoding' a -> Encoding' b
retagEncoding (Encoding' a -> Encoding) -> (a -> Encoding' a) -> a -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Encoding' a
render))
  {-# INLINE aesonPrimitives #-}
  aesonEncodedText :: (Text, Encoding' Text) -> Encoding' a
aesonEncodedText = Encoding' Text -> Encoding' a
forall a b. Encoding' a -> Encoding' b
retagEncoding (Encoding' Text -> Encoding' a)
-> ((Text, Encoding' Text) -> Encoding' Text)
-> (Text, Encoding' Text)
-> Encoding' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, Encoding' Text) -> Encoding' Text
forall a b. (a, b) -> b
snd
  {-# INLINE aesonText #-}
  {-# INLINE aesonString #-}
  {-# INLINE aesonLiteral #-}
  {-# INLINE aesonEncodedText #-}

-- | Retag an @aeson@ `Encoding.Encoding'`.
retagEncoding :: Encoding.Encoding' a -> Encoding.Encoding' b
retagEncoding :: forall a b. Encoding' a -> Encoding' b
retagEncoding = Builder -> Encoding' b
forall a. Builder -> Encoding' a
Encoding.unsafeToEncoding (Builder -> Encoding' b)
-> (Encoding' a -> Builder) -> Encoding' a -> Encoding' b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Encoding' a -> Builder
forall tag. Encoding' tag -> Builder
Encoding.fromEncoding

{- | t'KeyPrintor' prints the key of an t'Object', which is total,
as a t'Key' or as its `Encoding.Encoding'`.
-}
newtype KeyPrintor key a b = KeyPrintor {forall key a b. KeyPrintor key a b -> a -> key
runKeyPrintor :: a -> key}

instance Profunctor (KeyPrintor key) where
  dimap :: forall a b c d.
(a -> b) -> (c -> d) -> KeyPrintor key b c -> KeyPrintor key a d
dimap a -> b
f c -> d
_ (KeyPrintor b -> key
render) = (a -> key) -> KeyPrintor key a d
forall key a b. (a -> key) -> KeyPrintor key a b
KeyPrintor (b -> key
render (b -> key) -> (a -> b) -> a -> key
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
instance Cochoice (KeyPrintor key) where
  unleft :: forall a d b.
KeyPrintor key (Either a d) (Either b d) -> KeyPrintor key a b
unleft (KeyPrintor Either a d -> key
render) = (a -> key) -> KeyPrintor key a b
forall key a b. (a -> key) -> KeyPrintor key a b
KeyPrintor (Either a d -> key
render (Either a d -> key) -> (a -> Either a d) -> a -> key
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either a d
forall a b. a -> Either a b
Left)
  unright :: forall d a b.
KeyPrintor key (Either d a) (Either d b) -> KeyPrintor key a b
unright (KeyPrintor Either d a -> key
render) = (a -> key) -> KeyPrintor key a b
forall key a b. (a -> key) -> KeyPrintor key a b
KeyPrintor (Either d a -> key
render (Either d a -> key) -> (a -> Either d a) -> a -> key
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either d a
forall a b. b -> Either a b
Right)
instance (AesonStr key, x ~ (), y ~ ()) => IsString (KeyPrintor key x y) where
  fromString :: String -> KeyPrintor key x y
fromString String
s = (x -> key) -> KeyPrintor key x y
forall key a b. (a -> key) -> KeyPrintor key a b
KeyPrintor (key -> x -> key
forall a b. a -> b -> a
const key
literal)
    where
      literal :: key
literal = Text -> key
forall val. AesonStr val => Text -> val
aesonLiteral (String -> Text
Text.pack String
s)
-- | A key's `rule` names nothing to print.
instance Ruled (KeyPrintor key a b)
instance BackusNaurForm (KeyPrintor key a b) where
  ruleRec :: String
-> (KeyPrintor key a b -> KeyPrintor key a b) -> KeyPrintor key a b
ruleRec String
_ = (KeyPrintor key a b -> KeyPrintor key a b) -> KeyPrintor key a b
forall a. (a -> a) -> a
fix
instance AesonStr key => JsonStr (KeyPrintor key) where
  jsonText :: KeyPrintor key Text Text
jsonText = (Text -> key) -> KeyPrintor key Text Text
forall key a b. (a -> key) -> KeyPrintor key a b
KeyPrintor Text -> key
forall val. AesonStr val => Text -> val
aesonText
  jsonString :: KeyPrintor key String String
jsonString = (String -> key) -> KeyPrintor key String String
forall key a b. (a -> key) -> KeyPrintor key a b
KeyPrintor String -> key
forall val. AesonStr val => String -> val
aesonString
  jsonEncodedText :: forall a.
APrism Text (Text, Encoding' Text) a a -> KeyPrintor key a a
jsonEncodedText APrism Text (Text, Encoding' Text) a a
encoding = APrism Text (Text, Encoding' Text) a a
-> ((a -> (Text, Encoding' Text))
    -> (Text -> Either (Text, Encoding' Text) a) -> KeyPrintor key a a)
-> KeyPrintor key a a
forall s t a b r.
APrism s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r
withPrism APrism Text (Text, Encoding' Text) a a
encoding (((a -> (Text, Encoding' Text))
  -> (Text -> Either (Text, Encoding' Text) a) -> KeyPrintor key a a)
 -> KeyPrintor key a a)
-> ((a -> (Text, Encoding' Text))
    -> (Text -> Either (Text, Encoding' Text) a) -> KeyPrintor key a a)
-> KeyPrintor key a a
forall a b. (a -> b) -> a -> b
$ \a -> (Text, Encoding' Text)
encode Text -> Either (Text, Encoding' Text) a
_ ->
    (a -> key) -> KeyPrintor key a a
forall key a b. (a -> key) -> KeyPrintor key a b
KeyPrintor ((Text, Encoding' Text) -> key
forall val. AesonStr val => (Text, Encoding' Text) -> val
aesonEncodedText ((Text, Encoding' Text) -> key)
-> (a -> (Text, Encoding' Text)) -> a -> key
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> (Text, Encoding' Text)
encode)
  -- | Literals rendered once, & printed by their index.
  jsonEnumWith :: forall a. (a -> Int) -> [(Text, a)] -> KeyPrintor key a a
jsonEnumWith a -> Int
indexOf [(Text, a)]
table = (a -> key) -> KeyPrintor key a a
forall key a b. (a -> key) -> KeyPrintor key a b
KeyPrintor (Array key -> Int -> key
forall a. Array a -> Int -> a
indexArray Array key
rendered (Int -> key) -> (a -> Int) -> a -> key
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int
indexOf)
    where
      rendered :: Array key
rendered = [key] -> Array key
forall a. [a] -> Array a
arrayFromList [Text -> key
forall val. AesonStr val => Text -> val
aesonLiteral Text
literal | (Text
literal, a
_) <- [(Text, a)]
table]

-- | @aeson@'s representations of JSON values, `Value` & `Encoding`.
class AesonStr val => AesonVal val where
  aesonNull :: val
  aesonBool :: Bool -> val
  aesonNumber :: Scientific -> val
  aesonIntegral :: Integral a => (a -> Encoding) -> a -> val
  aesonDouble :: Double -> val
  aesonList :: (a -> val) -> [a] -> val
  -- | An array of two elements.
  aesonPair :: val -> val -> val
  aesonObject :: [(Key, val)] -> val
  -- | Render an object of distinct keys, folded from a map.
  aesonMap
    :: (forall k. JsonStr k => k a b)
    -> (forall r. (a -> c -> r -> r) -> r -> m -> r)
    -> (c -> val) -> m -> val
  aesonValue :: Value -> val
  -- | A key of an object, encoded once, before printing its properties.
  type AesonKey val
  -- | The properties of an object, as they're rendered.
  type AesonProps val
  aesonKey :: Key -> AesonKey val
  aesonProp :: AesonKey val -> val -> AesonProps val -> AesonProps val
  aesonPropsEmpty :: AesonProps val
  aesonProps :: AesonProps val -> val
  -- | An object of a single property.
  aesonTag :: AesonKey val -> val -> val
  -- | The elements of an array, as they're rendered.
  type AesonElems val
  aesonElem :: val -> AesonElems val -> AesonElems val
  aesonElemsEmpty :: AesonElems val
  aesonElems :: AesonElems val -> val

-- | Elements of an `Encoding` array, separated by commas.
data EncodingElems = NoEncodingElems | EncodingElems Encoding

instance AesonVal Value where
  aesonNull :: Value
aesonNull = Value
Null
  aesonBool :: Bool -> Value
aesonBool = Bool -> Value
Bool
  aesonNumber :: Scientific -> Value
aesonNumber = Scientific -> Value
Number
  aesonIntegral :: forall a. Integral a => (a -> Encoding) -> a -> Value
aesonIntegral a -> Encoding
_ = Scientific -> Value
Number (Scientific -> Value) -> (a -> Scientific) -> a -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  aesonDouble :: Double -> Value
aesonDouble = Scientific -> Value
Number (Scientific -> Value) -> (Double -> Scientific) -> Double -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Scientific
forall a. RealFloat a => a -> Scientific
fromFloatDigits
  aesonList :: forall a. (a -> Value) -> [a] -> Value
aesonList a -> Value
f [a]
as = Array -> Value
Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ (forall s. ST s (MVector s Value)) -> Array
forall a. (forall s. ST s (MVector s a)) -> Vector a
Vector.create ((forall s. ST s (MVector s Value)) -> Array)
-> (forall s. ST s (MVector s Value)) -> Array
forall a b. (a -> b) -> a -> b
$ do
    array <- Int -> ST s (MVector (PrimState (ST s)) Value)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> m (MVector (PrimState m) a)
MVector.unsafeNew ([a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
as)
    let
      write Int
_ [] = MVector (PrimState (ST s)) Value
-> ST s (MVector (PrimState (ST s)) Value)
forall a. a -> ST s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MVector (PrimState (ST s)) Value
array
      write Int
i (a
a : [a]
rest) =
        (MVector (PrimState (ST s)) Value -> Int -> Value -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> Int -> a -> m ()
MVector.unsafeWrite MVector (PrimState (ST s)) Value
array Int
i (Value -> ST s ()) -> Value -> ST s ()
forall a b. (a -> b) -> a -> b
$! a -> Value
f a
a) ST s () -> ST s (MVector s Value) -> ST s (MVector s Value)
forall a b. ST s a -> ST s b -> ST s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> [a] -> ST s (MVector s Value)
write (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [a]
rest
    write 0 as
  aesonPair :: Value -> Value -> Value
aesonPair Value
a Value
b = Array -> Value
Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ (forall s. ST s (MVector s Value)) -> Array
forall a. (forall s. ST s (MVector s a)) -> Vector a
Vector.create ((forall s. ST s (MVector s Value)) -> Array)
-> (forall s. ST s (MVector s Value)) -> Array
forall a b. (a -> b) -> a -> b
$ do
    array <- Int -> ST s (MVector (PrimState (ST s)) Value)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> m (MVector (PrimState m) a)
MVector.unsafeNew Int
2
    MVector.unsafeWrite array 0 a
    MVector.unsafeWrite array 1 b
    pure array
  aesonObject :: [(Key, Value)] -> Value
aesonObject = Object -> Value
Object (Object -> Value)
-> ([(Key, Value)] -> Object) -> [(Key, Value)] -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Key, Value)] -> Object
forall v. [(Key, v)] -> KeyMap v
KeyMap.fromList
  aesonMap :: forall a b c m.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> (forall r. (a -> c -> r -> r) -> r -> m -> r)
-> (c -> Value)
-> m
-> Value
aesonMap forall (k :: * -> * -> *). JsonStr k => k a b
key forall r. (a -> c -> r -> r) -> r -> m -> r
fold c -> Value
render = Object -> Value
Object (Object -> Value) -> (m -> Object) -> m -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Key, Value)] -> Object
forall v. [(Key, v)] -> KeyMap v
KeyMap.fromList ([(Key, Value)] -> Object) -> (m -> [(Key, Value)]) -> m -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> c -> [(Key, Value)] -> [(Key, Value)])
-> [(Key, Value)] -> m -> [(Key, Value)]
forall r. (a -> c -> r -> r) -> r -> m -> r
fold a -> c -> [(Key, Value)] -> [(Key, Value)]
property []
    where
      property :: a -> c -> [(Key, Value)] -> [(Key, Value)]
property a
a c
c [(Key, Value)]
rest = let printed :: Value
printed = c -> Value
render c
c in
        Value
printed Value -> [(Key, Value)] -> [(Key, Value)]
forall a b. a -> b -> b
`seq` (KeyPrintor Key a b -> a -> Key
forall key a b. KeyPrintor key a b -> a -> key
runKeyPrintor KeyPrintor Key a b
forall (k :: * -> * -> *). JsonStr k => k a b
key a
a, Value
printed) (Key, Value) -> [(Key, Value)] -> [(Key, Value)]
forall a. a -> [a] -> [a]
: [(Key, Value)]
rest
  aesonValue :: Value -> Value
aesonValue = Value -> Value
forall a. a -> a
id
  type AesonKey Value = Key
  type AesonProps Value = [(Key, Value)]
  aesonKey :: Key -> AesonKey Value
aesonKey = Key -> Key
Key -> AesonKey Value
forall a. a -> a
id
  aesonProp :: AesonKey Value -> Value -> AesonProps Value -> AesonProps Value
aesonProp AesonKey Value
key Value
value AesonProps Value
rest = (AesonKey Value
key, Value
value) (AesonKey Value, Value)
-> [(AesonKey Value, Value)] -> [(AesonKey Value, Value)]
forall a. a -> [a] -> [a]
: [(AesonKey Value, Value)]
AesonProps Value
rest
  aesonPropsEmpty :: AesonProps Value
aesonPropsEmpty = []
  aesonProps :: AesonProps Value -> Value
aesonProps = Object -> Value
Object (Object -> Value)
-> ([(Key, Value)] -> Object) -> [(Key, Value)] -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Key, Value)] -> Object
forall v. [(Key, v)] -> KeyMap v
KeyMap.fromList
  aesonTag :: AesonKey Value -> Value -> Value
aesonTag AesonKey Value
key Value
value = Object -> Value
Object (Key -> Value -> Object
forall v. Key -> v -> KeyMap v
KeyMap.singleton Key
AesonKey Value
key Value
value)
  type AesonElems Value = [Value]
  aesonElem :: Value -> AesonElems Value -> AesonElems Value
aesonElem = (:)
  aesonElemsEmpty :: AesonElems Value
aesonElemsEmpty = []
  -- Few elements are an array of a known size, which is allocated inline.
  aesonElems :: AesonElems Value -> Value
aesonElems = \case
    [] -> Array -> Value
Array Array
forall a. Vector a
Vector.empty
    [Value
a] -> Array -> Value
Array (Value -> Array
forall a. a -> Vector a
Vector.singleton Value
a)
    [Value
a, Value
b] -> Value -> Value -> Value
forall val. AesonVal val => val -> val -> val
aesonPair Value
a Value
b
    [Value
a, Value
b, Value
c] -> Array -> Value
Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ (forall s. ST s (MVector s Value)) -> Array
forall a. (forall s. ST s (MVector s a)) -> Vector a
Vector.create ((forall s. ST s (MVector s Value)) -> Array)
-> (forall s. ST s (MVector s Value)) -> Array
forall a b. (a -> b) -> a -> b
$ do
      array <- Int -> ST s (MVector (PrimState (ST s)) Value)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> m (MVector (PrimState m) a)
MVector.unsafeNew Int
3
      MVector.unsafeWrite array 0 a
      MVector.unsafeWrite array 1 b
      MVector.unsafeWrite array 2 c
      pure array
    [Value
a, Value
b, Value
c, Value
d] -> Array -> Value
Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ (forall s. ST s (MVector s Value)) -> Array
forall a. (forall s. ST s (MVector s a)) -> Vector a
Vector.create ((forall s. ST s (MVector s Value)) -> Array)
-> (forall s. ST s (MVector s Value)) -> Array
forall a b. (a -> b) -> a -> b
$ do
      array <- Int -> ST s (MVector (PrimState (ST s)) Value)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> m (MVector (PrimState m) a)
MVector.unsafeNew Int
4
      MVector.unsafeWrite array 0 a
      MVector.unsafeWrite array 1 b
      MVector.unsafeWrite array 2 c
      MVector.unsafeWrite array 3 d
      pure array
    AesonElems Value
items -> (Value -> Value) -> [Value] -> Value
forall val a. AesonVal val => (a -> val) -> [a] -> val
forall a. (a -> Value) -> [a] -> Value
aesonList Value -> Value
forall a. a -> a
id [Value]
AesonElems Value
items
  {-# INLINE aesonElem #-}
  {-# INLINE aesonElemsEmpty #-}
  {-# INLINE aesonElems #-}
  {-# INLINE aesonNull #-}
  {-# INLINE aesonBool #-}
  {-# INLINE aesonNumber #-}
  {-# INLINE aesonIntegral #-}
  {-# INLINE aesonDouble #-}
  {-# INLINE aesonList #-}
  {-# INLINE aesonPair #-}
  {-# INLINE aesonObject #-}
  {-# INLINE aesonMap #-}
  {-# INLINE aesonValue #-}
  {-# INLINE aesonKey #-}
  {-# INLINE aesonProp #-}
  {-# INLINE aesonPropsEmpty #-}
  {-# INLINE aesonProps #-}

-- | Keys are rendered once, as their quoted strings, & properties as a series.
instance AesonVal Encoding where
  aesonNull :: Encoding
aesonNull = Encoding
Encoding.null_
  aesonBool :: Bool -> Encoding
aesonBool = Bool -> Encoding
Encoding.bool
  aesonNumber :: Scientific -> Encoding
aesonNumber = Scientific -> Encoding
Encoding.scientific
  aesonIntegral :: forall a. Integral a => (a -> Encoding) -> a -> Encoding
aesonIntegral = (a -> Encoding) -> a -> Encoding
forall a. a -> a
id
  aesonDouble :: Double -> Encoding
aesonDouble = Double -> Encoding
Encoding.double
  aesonList :: forall a. (a -> Encoding) -> [a] -> Encoding
aesonList = (a -> Encoding) -> [a] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
Encoding.list
  aesonPair :: Encoding -> Encoding -> Encoding
aesonPair Encoding
a Encoding
b = Encoding
forall a. Encoding' a
EncodingInternal.openBracket
    Encoding -> Encoding -> Encoding
forall a. Encoding' a -> Encoding' a -> Encoding' a
EncodingInternal.>< Encoding
a Encoding -> Encoding -> Encoding
forall a. Encoding' a -> Encoding' a -> Encoding' a
EncodingInternal.>< Encoding
forall a. Encoding' a
EncodingInternal.comma
    Encoding -> Encoding -> Encoding
forall a. Encoding' a -> Encoding' a -> Encoding' a
EncodingInternal.>< Encoding
b Encoding -> Encoding -> Encoding
forall a. Encoding' a -> Encoding' a -> Encoding' a
EncodingInternal.>< Encoding
forall a. Encoding' a
EncodingInternal.closeBracket
  aesonObject :: [(Key, Encoding)] -> Encoding
aesonObject = Series -> Encoding
Encoding.pairs (Series -> Encoding)
-> ([(Key, Encoding)] -> Series) -> [(Key, Encoding)] -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Key, Encoding) -> Series) -> [(Key, Encoding)] -> Series
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((Key -> Encoding -> Series) -> (Key, Encoding) -> Series
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Key -> Encoding -> Series
Encoding.pair)
  aesonMap :: forall a b c m.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> (forall r. (a -> c -> r -> r) -> r -> m -> r)
-> (c -> Encoding)
-> m
-> Encoding
aesonMap forall (k :: * -> * -> *). JsonStr k => k a b
key forall r. (a -> c -> r -> r) -> r -> m -> r
fold c -> Encoding
render = Series -> Encoding
Encoding.pairs (Series -> Encoding) -> (m -> Series) -> m -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> c -> Series -> Series) -> Series -> m -> Series
forall r. (a -> c -> r -> r) -> r -> m -> r
fold a -> c -> Series -> Series
property Series
forall a. Monoid a => a
mempty
    where
      property :: a -> c -> Series -> Series
property a
a c
c Series
rest =
        let encodedKey :: Encoding' Key
encodedKey = KeyPrintor (Encoding' Key) a b -> a -> Encoding' Key
forall key a b. KeyPrintor key a b -> a -> key
runKeyPrintor KeyPrintor (Encoding' Key) a b
forall (k :: * -> * -> *). JsonStr k => k a b
key a
a; printed :: Encoding
printed = c -> Encoding
render c
c
        in Encoding' Key
encodedKey Encoding' Key -> Series -> Series
forall a b. a -> b -> b
`seq` Encoding
printed Encoding -> Series -> Series
forall a b. a -> b -> b
`seq`
          Encoding' Key -> Encoding -> Series
Encoding.pair' Encoding' Key
encodedKey Encoding
printed Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Series
rest
  aesonValue :: Value -> Encoding
aesonValue = Value -> Encoding
Encoding.value
  type AesonKey Encoding = Encoding.Encoding' Key
  type AesonProps Encoding = Encoding.Series
  aesonKey :: Key -> AesonKey Encoding
aesonKey = Text -> AesonKey Encoding
forall val. AesonStr val => Text -> val
aesonLiteral (Text -> AesonKey Encoding)
-> (Key -> Text) -> Key -> AesonKey Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> Text
Key.toText
  aesonProp :: AesonKey Encoding
-> Encoding -> AesonProps Encoding -> AesonProps Encoding
aesonProp AesonKey Encoding
key Encoding
value AesonProps Encoding
rest = Encoding' Key -> Encoding -> Series
Encoding.pair' Encoding' Key
AesonKey Encoding
key Encoding
value Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Series
AesonProps Encoding
rest
  aesonPropsEmpty :: AesonProps Encoding
aesonPropsEmpty = AesonProps Encoding
forall a. Monoid a => a
mempty
  aesonProps :: AesonProps Encoding -> Encoding
aesonProps = Series -> Encoding
AesonProps Encoding -> Encoding
Encoding.pairs
  aesonTag :: AesonKey Encoding -> Encoding -> Encoding
aesonTag AesonKey Encoding
key Encoding
value = Series -> Encoding
Encoding.pairs (Encoding' Key -> Encoding -> Series
Encoding.pair' Encoding' Key
AesonKey Encoding
key Encoding
value)
  type AesonElems Encoding = EncodingElems
  aesonElem :: Encoding -> AesonElems Encoding -> AesonElems Encoding
aesonElem Encoding
value = \case
    EncodingElems
AesonElems Encoding
NoEncodingElems -> Encoding -> EncodingElems
EncodingElems Encoding
value
    EncodingElems Encoding
rest ->
      Encoding -> EncodingElems
EncodingElems (Encoding
value Encoding -> Encoding -> Encoding
forall a. Encoding' a -> Encoding' a -> Encoding' a
EncodingInternal.>< Encoding
forall a. Encoding' a
EncodingInternal.comma
        Encoding -> Encoding -> Encoding
forall a. Encoding' a -> Encoding' a -> Encoding' a
EncodingInternal.>< Encoding
rest)
  aesonElemsEmpty :: AesonElems Encoding
aesonElemsEmpty = EncodingElems
AesonElems Encoding
NoEncodingElems
  aesonElems :: AesonElems Encoding -> Encoding
aesonElems = \case
    EncodingElems
AesonElems Encoding
NoEncodingElems -> Encoding
Encoding.emptyArray_
    EncodingElems Encoding
items -> Encoding
forall a. Encoding' a
EncodingInternal.openBracket
      Encoding -> Encoding -> Encoding
forall a. Encoding' a -> Encoding' a -> Encoding' a
EncodingInternal.>< Encoding
items
      Encoding -> Encoding -> Encoding
forall a. Encoding' a -> Encoding' a -> Encoding' a
EncodingInternal.>< Encoding
forall a. Encoding' a
EncodingInternal.closeBracket
  {-# INLINE aesonElem #-}
  {-# INLINE aesonElemsEmpty #-}
  {-# INLINE aesonElems #-}
  {-# INLINE aesonNull #-}
  {-# INLINE aesonBool #-}
  {-# INLINE aesonNumber #-}
  {-# INLINE aesonIntegral #-}
  {-# INLINE aesonDouble #-}
  {-# INLINE aesonList #-}
  {-# INLINE aesonPair #-}
  {-# INLINE aesonObject #-}
  {-# INLINE aesonMap #-}
  {-# INLINE aesonValue #-}
  {-# INLINE aesonKey #-}
  {-# INLINE aesonProp #-}
  {-# INLINE aesonPropsEmpty #-}
  {-# INLINE aesonProps #-}

{- | t'JsonPrintor' `printorTry`s to print a value, or else `printorCheck`s it
to locate the failure. A `printorTotal` printor prints every value,
so it `printorRender`s it without trying. Totality is determined
through `rule`s, assuming those being determined are total.
It's always taken lazily, as @\\rules -> printorTotal p rules@,
so that building a recursive printor doesn't force itself.
A primitive `printorRenderArray`s an array of its values at once.
-}
data JsonPrintor val a b = JsonPrintor
  { forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal :: !(Set String -> Bool)
  , forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry :: !(a -> Maybe val)
  , forall val a b. JsonPrintor val a b -> a -> val
printorRender :: !(a -> val)
  , forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck :: !(a -> Either JsonError val)
  , forall val a b. JsonPrintor val a b -> Maybe ([a] -> val)
printorRenderArray :: !(Maybe ([a] -> val))
  }

runJsonPrintor :: JsonPrintor val a b -> a -> Either JsonError val
runJsonPrintor :: forall val a b. JsonPrintor val a b -> a -> Either JsonError val
runJsonPrintor JsonPrintor val a b
p
  | JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
forall a. Set a
Set.empty = val -> Either JsonError val
forall a b. b -> Either a b
Right (val -> Either JsonError val)
-> (a -> val) -> a -> Either JsonError val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
p
  | Bool
otherwise = \a
a -> Either JsonError val
-> (val -> Either JsonError val)
-> Maybe val
-> Either JsonError val
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p a
a) val -> Either JsonError val
forall a b. b -> Either a b
Right (JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p a
a)
{-# INLINE runJsonPrintor #-}

-- | A total t'JsonPrintor'.
printing :: (a -> val) -> JsonPrintor val a b
printing :: forall a val b. (a -> val) -> JsonPrintor val a b
printing a -> val
render =
  (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
True) (val -> Maybe val
forall a. a -> Maybe a
Just (val -> Maybe val) -> (a -> val) -> a -> Maybe val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> val
render) a -> val
render (val -> Either JsonError val
forall a b. b -> Either a b
Right (val -> Either JsonError val)
-> (a -> val) -> a -> Either JsonError val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> val
render) Maybe ([a] -> val)
forall a. Maybe a
Nothing
{-# INLINE printing #-}

-- | A total t'JsonPrintor' of a primitive.
primitive :: AesonStr val => (a -> val) -> JsonPrintor val a b
primitive :: forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive a -> val
render =
  ((a -> val) -> JsonPrintor val a (ZonkAny 3)
forall a val b. (a -> val) -> JsonPrintor val a b
printing a -> val
render) {printorRenderArray = aesonPrimitives render}
{-# INLINE primitive #-}

{- | A partial t'JsonPrintor', rendering what it tries,
or else null, as `jsonPrint` does.
-}
trying
  :: AesonVal val
  => (a -> Maybe val) -> (a -> Either JsonError val) -> JsonPrintor val a b
trying :: forall val a b.
AesonVal val =>
(a -> Maybe val)
-> (a -> Either JsonError val) -> JsonPrintor val a b
trying a -> Maybe val
attempt a -> Either JsonError val
check = (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
  (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
False) a -> Maybe val
attempt (val -> Maybe val -> val
forall a. a -> Maybe a -> a
fromMaybe val
forall val. AesonVal val => val
aesonNull (Maybe val -> val) -> (a -> Maybe val) -> a -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe val
attempt) a -> Either JsonError val
check Maybe ([a] -> val)
forall a. Maybe a
Nothing

-- | Try each of the values, rendering them for a total printor.
tryAll
  :: Traversable f
  => (Set String -> Bool) -> (a -> Maybe b) -> (a -> b) -> f a -> Maybe (f b)
tryAll :: forall (f :: * -> *) a b.
Traversable f =>
(Set String -> Bool)
-> (a -> Maybe b) -> (a -> b) -> f a -> Maybe (f b)
tryAll Set String -> Bool
total a -> Maybe b
attempt a -> b
render = \f a
as -> if Bool
isTotal
  then f b -> Maybe (f b)
forall a. a -> Maybe a
Just ((a -> b) -> f a -> f b
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
render f a
as)
  else (a -> Maybe b) -> f a -> Maybe (f b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> f a -> f (f b)
traverse a -> Maybe b
attempt f a
as
  where
    isTotal :: Bool
isTotal = Set String -> Bool
total Set String
forall a. Set a
Set.empty

{- | t'TupPrintor' prints the elements of a JSON array,
counted to locate a failure of a later element.
A single element keeps its rendering, so that mapping it composes.
-}
data TupPrintor val a b = TupPrintor
  { forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal :: !(Set String -> Bool)
  , forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry :: !(a -> Maybe (DList val))
  , forall val a b.
TupPrintor val a b -> a -> AesonElems val -> AesonElems val
tupPrintorRender :: !(a -> AesonElems val -> AesonElems val)
  , forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck :: !(a -> Elements val)
  , forall val a b. TupPrintor val a b -> Maybe (a -> val)
tupPrintorElement :: !(Maybe (a -> val))
  }

-- | Render a single element, before the rest.
renderElement
  :: AesonVal val => (a -> val) -> a -> AesonElems val -> AesonElems val
renderElement :: forall val a.
AesonVal val =>
(a -> val) -> a -> AesonElems val -> AesonElems val
renderElement a -> val
render a
a AesonElems val
rest =
  let printed :: val
printed = a -> val
render a
a in val
printed val -> AesonElems val -> AesonElems val
forall a b. a -> b -> b
`seq` val -> AesonElems val -> AesonElems val
forall val. AesonVal val => val -> AesonElems val -> AesonElems val
aesonElem val
printed AesonElems val
rest
{-# INLINE renderElement #-}

-- | Printed elements, counted to locate a failure of a later element.
newtype Elements val = Elements (Either JsonError (Int, DList val))
instance Semigroup (Elements val) where
  Elements (Right (Int
count0, DList val
elements0)) <> :: Elements val -> Elements val -> Elements val
<> Elements Either JsonError (Int, DList val)
later = Either JsonError (Int, DList val) -> Elements val
forall val. Either JsonError (Int, DList val) -> Elements val
Elements (Either JsonError (Int, DList val) -> Elements val)
-> Either JsonError (Int, DList val) -> Elements val
forall a b. (a -> b) -> a -> b
$
    case Either JsonError (Int, DList val)
later of
      Right (Int
count1, DList val
elements1) ->
        (Int, DList val) -> Either JsonError (Int, DList val)
forall a b. b -> Either a b
Right (Int
count0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
count1, DList val
elements0 DList val -> DList val -> DList val
forall a. Semigroup a => a -> a -> a
<> DList val
elements1)
      Left JsonError
err -> JsonError -> Either JsonError (Int, DList val)
forall a b. a -> Either a b
Left (JsonError -> Either JsonError (Int, DList val))
-> JsonError -> Either JsonError (Int, DList val)
forall a b. (a -> b) -> a -> b
$ case JsonError -> [JSONPathElement]
jsonErrorPath JsonError
err of
        Index Int
i : [JSONPathElement]
path -> JsonError
err {jsonErrorPath = Index (i + count0) : path}
        [JSONPathElement]
_ -> JsonError
err
  Elements val
failure <> Elements val
_ = Elements val
failure
instance Monoid (Elements val) where
  mempty :: Elements val
mempty = Either JsonError (Int, DList val) -> Elements val
forall val. Either JsonError (Int, DList val) -> Elements val
Elements ((Int, DList val) -> Either JsonError (Int, DList val)
forall a b. b -> Either a b
Right (Int
0, DList val
forall a. Monoid a => a
mempty))

{- | t'ObjPrintor' writes keys of an t'Object'.
Its keys are known before printing, so overlapping keys are found once,
unless it writes the rest of the properties, whose keys are checked.
-}
data ObjPrintor val a b = ObjPrintor
  { forall val a b. ObjPrintor val a b -> [[Key]]
objPrintorShapes :: [[Key]]
  , forall val a b. ObjPrintor val a b -> Bool
objPrintorRest :: !Bool
  , forall val a b. ObjPrintor val a b -> Set String -> Bool
objPrintorTotal :: !(Set String -> Bool)
  , forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry :: !(a -> Maybe (DList (Key, val)))
  , forall val a b.
ObjPrintor val a b -> a -> AesonProps val -> AesonProps val
objPrintorRender :: !(a -> AesonProps val -> AesonProps val)
  , forall val a b.
ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
objPrintorCheck :: !(a -> Either JsonError [(Key, val)])
  }

printDuplicate :: Key -> Either JsonError a
printDuplicate :: forall a. Key -> Either JsonError a
printDuplicate Key
key = String -> Maybe Value -> Either JsonError a
forall a. String -> Maybe Value -> Either JsonError a
jsonMissing (String
"key " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Key -> String
showKey Key
key String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" twice") Maybe Value
forall a. Maybe a
Nothing

instance Functor (JsonPrintor val a) where
  fmap :: forall a b. (a -> b) -> JsonPrintor val a a -> JsonPrintor val a b
fmap a -> b
_ (JsonPrintor Set String -> Bool
total a -> Maybe val
attempt a -> val
render a -> Either JsonError val
check Maybe ([a] -> val)
renderArray) =
    (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor Set String -> Bool
total a -> Maybe val
attempt a -> val
render a -> Either JsonError val
check Maybe ([a] -> val)
renderArray
  {-# INLINE fmap #-}
{- | A printor's results are phantom, so that `Witherable.mapMaybe`,
like `fmap`, keeps it, as @mapMaybe = dimapMaybe Just@ would observably,
but keeping its totality.
-}
instance Witherable.Filterable (JsonPrintor val a) where
  mapMaybe :: forall a b.
(a -> Maybe b) -> JsonPrintor val a a -> JsonPrintor val a b
mapMaybe a -> Maybe b
_ = JsonPrintor val a a -> JsonPrintor val a b
forall a b. Coercible a b => a -> b
coerce
instance AesonVal val => Filtrator (JsonPrintor val)
instance Profunctor (JsonPrintor val) where
  dimap :: forall a b c d.
(a -> b) -> (c -> d) -> JsonPrintor val b c -> JsonPrintor val a d
dimap a -> b
f c -> d
_ (JsonPrintor Set String -> Bool
total b -> Maybe val
attempt b -> val
render b -> Either JsonError val
check Maybe ([b] -> val)
renderArray) =
    (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a d
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor Set String -> Bool
total (b -> Maybe val
attempt (b -> Maybe val) -> (a -> b) -> a -> Maybe val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) (\a
a -> b -> val
render (b -> val) -> b -> val
forall a b. (a -> b) -> a -> b
$! a -> b
f a
a) (b -> Either JsonError val
check (b -> Either JsonError val)
-> (a -> b) -> a -> Either JsonError val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
      ((([b] -> val) -> [a] -> val)
-> Maybe ([b] -> val) -> Maybe ([a] -> val)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([b] -> val) -> ([a] -> [b]) -> [a] -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> [a] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map a -> b
f) Maybe ([b] -> val)
renderArray)
  q b c
_ #. :: forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> JsonPrintor val a b -> JsonPrintor val a c
#. JsonPrintor val a b
p = JsonPrintor val a b -> JsonPrintor val a c
forall a b. Coercible a b => a -> b
coerce JsonPrintor val a b
p
  JsonPrintor val b c
p .# :: forall a b c (q :: * -> * -> *).
Coercible b a =>
JsonPrintor val b c -> q a b -> JsonPrintor val a c
.# q a b
_ = JsonPrintor val b c -> JsonPrintor val a c
forall a b. Coercible a b => a -> b
coerce JsonPrintor val b c
p
  {-# INLINE dimap #-}
  {-# INLINE (#.) #-}
  {-# INLINE (.#) #-}
instance Cochoice (JsonPrintor val) where
  unleft :: forall a d b.
JsonPrintor val (Either a d) (Either b d) -> JsonPrintor val a b
unleft (JsonPrintor Set String -> Bool
total Either a d -> Maybe val
attempt Either a d -> val
render Either a d -> Either JsonError val
check Maybe ([Either a d] -> val)
renderArray) =
    (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor Set String -> Bool
total (Either a d -> Maybe val
attempt (Either a d -> Maybe val) -> (a -> Either a d) -> a -> Maybe val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either a d
forall a b. a -> Either a b
Left) (Either a d -> val
render (Either a d -> val) -> (a -> Either a d) -> a -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either a d
forall a b. a -> Either a b
Left) (Either a d -> Either JsonError val
check (Either a d -> Either JsonError val)
-> (a -> Either a d) -> a -> Either JsonError val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either a d
forall a b. a -> Either a b
Left)
      ((([Either a d] -> val) -> [a] -> val)
-> Maybe ([Either a d] -> val) -> Maybe ([a] -> val)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([Either a d] -> val) -> ([a] -> [Either a d]) -> [a] -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Either a d) -> [a] -> [Either a d]
forall a b. (a -> b) -> [a] -> [b]
map a -> Either a d
forall a b. a -> Either a b
Left) Maybe ([Either a d] -> val)
renderArray)
  unright :: forall d a b.
JsonPrintor val (Either d a) (Either d b) -> JsonPrintor val a b
unright (JsonPrintor Set String -> Bool
total Either d a -> Maybe val
attempt Either d a -> val
render Either d a -> Either JsonError val
check Maybe ([Either d a] -> val)
renderArray) =
    (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor Set String -> Bool
total (Either d a -> Maybe val
attempt (Either d a -> Maybe val) -> (a -> Either d a) -> a -> Maybe val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either d a
forall a b. b -> Either a b
Right) (Either d a -> val
render (Either d a -> val) -> (a -> Either d a) -> a -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either d a
forall a b. b -> Either a b
Right) (Either d a -> Either JsonError val
check (Either d a -> Either JsonError val)
-> (a -> Either d a) -> a -> Either JsonError val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either d a
forall a b. b -> Either a b
Right)
      ((([Either d a] -> val) -> [a] -> val)
-> Maybe ([Either d a] -> val) -> Maybe ([a] -> val)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([Either d a] -> val) -> ([a] -> [Either d a]) -> [a] -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Either d a) -> [a] -> [Either d a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Either d a
forall a b. b -> Either a b
Right) Maybe ([Either d a] -> val)
renderArray)
  {-# INLINE unleft #-}
  {-# INLINE unright #-}
instance CocartesianMonoidal (JsonPrintor val) where
  zeroP :: JsonPrintor val Void Void
zeroP = (Set String -> Bool)
-> (Void -> Maybe val)
-> (Void -> val)
-> (Void -> Either JsonError val)
-> Maybe ([Void] -> val)
-> JsonPrintor val Void Void
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
True) Void -> Maybe val
forall a. Void -> a
absurd Void -> val
forall a. Void -> a
absurd Void -> Either JsonError val
forall a. Void -> a
absurd Maybe ([Void] -> val)
forall a. Maybe a
Nothing
  JsonPrintor val a b
p >+< :: forall a b c d.
JsonPrintor val a b
-> JsonPrintor val c d -> JsonPrintor val (Either a c) (Either b d)
>+< JsonPrintor val c d
q = (Set String -> Bool)
-> (Either a c -> Maybe val)
-> (Either a c -> val)
-> (Either a c -> Either JsonError val)
-> Maybe ([Either a c] -> val)
-> JsonPrintor val (Either a c) (Either b d)
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
    (\Set String
rules -> JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
rules Bool -> Bool -> Bool
&& JsonPrintor val c d -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val c d
q Set String
rules)
    ((a -> Maybe val) -> (c -> Maybe val) -> Either a c -> Maybe val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p) (JsonPrintor val c d -> c -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val c d
q))
    ((a -> val) -> (c -> val) -> Either a c -> val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
p) (JsonPrintor val c d -> c -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val c d
q))
    ((a -> Either JsonError val)
-> (c -> Either JsonError val)
-> Either a c
-> Either JsonError val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p) (JsonPrintor val c d -> c -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val c d
q))
    Maybe ([Either a c] -> val)
forall a. Maybe a
Nothing
  {-# INLINE zeroP #-}
  {-# INLINE (>+<) #-}
instance AesonVal val => Choice (JsonPrintor val) where
  left' :: forall a b c.
JsonPrintor val a b -> JsonPrintor val (Either a c) (Either b c)
left' JsonPrintor val a b
p = (Either a c -> Maybe val)
-> (Either a c -> Either JsonError val)
-> JsonPrintor val (Either a c) (Either b c)
forall val a b.
AesonVal val =>
(a -> Maybe val)
-> (a -> Either JsonError val) -> JsonPrintor val a b
trying
    ((a -> Maybe val) -> (c -> Maybe val) -> Either a c -> Maybe val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p) (Maybe val -> c -> Maybe val
forall a b. a -> b -> a
const Maybe val
forall a. Maybe a
Nothing))
    ((a -> Either JsonError val)
-> (c -> Either JsonError val)
-> Either a c
-> Either JsonError val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p) (\c
_ -> Maybe Value -> Either JsonError val
forall a. Maybe Value -> Either JsonError a
jsonUnexpected Maybe Value
forall a. Maybe a
Nothing))
  right' :: forall a b c.
JsonPrintor val a b -> JsonPrintor val (Either c a) (Either c b)
right' JsonPrintor val a b
p = (Either c a -> Maybe val)
-> (Either c a -> Either JsonError val)
-> JsonPrintor val (Either c a) (Either c b)
forall val a b.
AesonVal val =>
(a -> Maybe val)
-> (a -> Either JsonError val) -> JsonPrintor val a b
trying
    ((c -> Maybe val) -> (a -> Maybe val) -> Either c a -> Maybe val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe val -> c -> Maybe val
forall a b. a -> b -> a
const Maybe val
forall a. Maybe a
Nothing) (JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p))
    ((c -> Either JsonError val)
-> (a -> Either JsonError val)
-> Either c a
-> Either JsonError val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\c
_ -> Maybe Value -> Either JsonError val
forall a. Maybe Value -> Either JsonError a
jsonUnexpected Maybe Value
forall a. Maybe a
Nothing) (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p))
  {-# INLINE left' #-}
  {-# INLINE right' #-}
instance AesonVal val => CocartesianChoice (JsonPrintor val)
instance AesonVal val => DisjunctiveMonoid (JsonPrintor val a b) where
  falseP :: JsonPrintor val a b
falseP = (a -> Maybe val)
-> (a -> Either JsonError val) -> JsonPrintor val a b
forall val a b.
AesonVal val =>
(a -> Maybe val)
-> (a -> Either JsonError val) -> JsonPrintor val a b
trying (Maybe val -> a -> Maybe val
forall a b. a -> b -> a
const Maybe val
forall a. Maybe a
Nothing) (\a
_ -> Maybe Value -> Either JsonError val
forall a. Maybe Value -> Either JsonError a
jsonUnexpected Maybe Value
forall a. Maybe a
Nothing)
  JsonPrintor val a b
p >|< :: JsonPrintor val a b -> JsonPrintor val a b -> JsonPrintor val a b
>|< JsonPrintor val a b
q = (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
    (\Set String
rules -> JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
rules Bool -> Bool -> Bool
|| JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
q Set String
rules)
    (\a
a -> JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p a
a Maybe val -> Maybe val -> Maybe val
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
q a
a)
    (\a
a -> val -> Maybe val -> val
forall a. a -> Maybe a -> a
fromMaybe (JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
q a
a) (JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p a
a))
    (\a
a -> case JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p a
a of
      Left JsonError
err1 -> (JsonError -> JsonError)
-> Either JsonError val -> Either JsonError val
forall a.
(JsonError -> JsonError)
-> Either JsonError a -> Either JsonError a
onFailure (JsonError -> JsonError -> JsonError
jsonOrElse JsonError
err1) (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
q a
a)
      Either JsonError val
success -> Either JsonError val
success)
    Maybe ([a] -> val)
forall a. Maybe a
Nothing
{- | A `rule` labels its failures with its display name.
Its totality assumes the rules being determined are total,
by induction on the values printed.
-}
instance Ruled (JsonPrintor val a b) where
  rule :: String -> JsonPrintor val a b -> JsonPrintor val a b
rule String
name JsonPrintor val a b
p = JsonPrintor val a b
p
    { printorTotal = \Set String
rules ->
        String -> Set String -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member String
name Set String
rules Bool -> Bool -> Bool
|| JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p (String -> Set String -> Set String
forall a. Ord a => a -> Set a -> Set a
Set.insert String
name Set String
rules)
    , printorCheck = onFailure (jsonRelabel (unqualified name)) . printorCheck p
    }
  {-# INLINE rule #-}
instance BackusNaurForm (JsonPrintor val a b) where
  ruleRec :: String
-> (JsonPrintor val a b -> JsonPrintor val a b)
-> JsonPrintor val a b
ruleRec String
name JsonPrintor val a b -> JsonPrintor val a b
f = (JsonPrintor val a b -> JsonPrintor val a b) -> JsonPrintor val a b
forall a. (a -> a) -> a
fix (String -> JsonPrintor val a b -> JsonPrintor val a b
forall p. Ruled p => String -> p -> p
rule String
name (JsonPrintor val a b -> JsonPrintor val a b)
-> (JsonPrintor val a b -> JsonPrintor val a b)
-> JsonPrintor val a b
-> JsonPrintor val a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonPrintor val a b -> JsonPrintor val a b
f)

instance (AesonStr val, x ~ (), y ~ ()) => IsString (JsonPrintor val x y) where
  fromString :: String -> JsonPrintor val x y
fromString String
s = (x -> val) -> JsonPrintor val x y
forall a val b. (a -> val) -> JsonPrintor val a b
printing (val -> x -> val
forall a b. a -> b -> a
const val
literal)
    where
      literal :: val
literal = Text -> val
forall val. AesonStr val => Text -> val
aesonLiteral (String -> Text
Text.pack String
s)
instance AesonStr val => JsonStr (JsonPrintor val) where
  jsonText :: JsonPrintor val Text Text
jsonText = (Text -> val) -> JsonPrintor val Text Text
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive Text -> val
forall val. AesonStr val => Text -> val
aesonText
  {-# INLINE jsonText #-}
  jsonString :: JsonPrintor val String String
jsonString = (String -> val) -> JsonPrintor val String String
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive String -> val
forall val. AesonStr val => String -> val
aesonString
  jsonEncodedText :: forall a.
APrism Text (Text, Encoding' Text) a a -> JsonPrintor val a a
jsonEncodedText APrism Text (Text, Encoding' Text) a a
encoding = APrism Text (Text, Encoding' Text) a a
-> ((a -> (Text, Encoding' Text))
    -> (Text -> Either (Text, Encoding' Text) a)
    -> JsonPrintor val a a)
-> JsonPrintor val a a
forall s t a b r.
APrism s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r
withPrism APrism Text (Text, Encoding' Text) a a
encoding (((a -> (Text, Encoding' Text))
  -> (Text -> Either (Text, Encoding' Text) a)
  -> JsonPrintor val a a)
 -> JsonPrintor val a a)
-> ((a -> (Text, Encoding' Text))
    -> (Text -> Either (Text, Encoding' Text) a)
    -> JsonPrintor val a a)
-> JsonPrintor val a a
forall a b. (a -> b) -> a -> b
$ \a -> (Text, Encoding' Text)
encode Text -> Either (Text, Encoding' Text) a
_ ->
    (a -> val) -> JsonPrintor val a a
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Text, Encoding' Text) -> val
forall val. AesonStr val => (Text, Encoding' Text) -> val
aesonEncodedText ((Text, Encoding' Text) -> val)
-> (a -> (Text, Encoding' Text)) -> a -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> (Text, Encoding' Text)
encode)
  -- | Literals rendered once, & printed by their index.
  jsonEnumWith :: forall a. (a -> Int) -> [(Text, a)] -> JsonPrintor val a a
jsonEnumWith a -> Int
indexOf [(Text, a)]
table = (a -> val) -> JsonPrintor val a a
forall a val b. (a -> val) -> JsonPrintor val a b
printing (Array val -> Int -> val
forall a. Array a -> Int -> a
indexArray Array val
rendered (Int -> val) -> (a -> Int) -> a -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int
indexOf)
    where
      rendered :: Array val
rendered = [val] -> Array val
forall a. [a] -> Array a
arrayFromList [Text -> val
forall val. AesonStr val => Text -> val
aesonLiteral Text
literal | (Text
literal, a
_) <- [(Text, a)]
table]
  {-# INLINE jsonString #-}
  {-# INLINE jsonEncodedText #-}
  {-# INLINE jsonEnumWith #-}
instance AesonVal val => JsonVal (JsonPrintor val) where
  jsonNull :: JsonPrintor val () ()
jsonNull = (() -> val) -> JsonPrintor val () ()
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive (val -> () -> val
forall a b. a -> b -> a
const val
forall val. AesonVal val => val
aesonNull)
  -- | As the default, but rendering without an `Either` for every value.
  jsonNullable :: forall a b.
JsonPrintor val a b -> JsonPrintor val (Maybe a) (Maybe b)
jsonNullable JsonPrintor val a b
p = (Set String -> Bool)
-> (Maybe a -> Maybe val)
-> (Maybe a -> val)
-> (Maybe a -> Either JsonError val)
-> Maybe ([Maybe a] -> val)
-> JsonPrintor val (Maybe a) (Maybe b)
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
    (\Set String
rules -> JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
rules)
    (Maybe val -> (a -> Maybe val) -> Maybe a -> Maybe val
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (val -> Maybe val
forall a. a -> Maybe a
Just val
forall val. AesonVal val => val
aesonNull) (JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p))
    Maybe a -> val
render
    (Either JsonError val
-> (a -> Either JsonError val) -> Maybe a -> Either JsonError val
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (val -> Either JsonError val
forall a b. b -> Either a b
Right val
forall val. AesonVal val => val
aesonNull) (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p))
    ((Maybe a -> val) -> Maybe ([Maybe a] -> val)
forall val a. AesonStr val => (a -> val) -> Maybe ([a] -> val)
forall a. (a -> val) -> Maybe ([a] -> val)
aesonPrimitives Maybe a -> val
render)
    where
      render :: Maybe a -> val
render = val -> (a -> val) -> Maybe a -> val
forall b a. b -> (a -> b) -> Maybe a -> b
maybe val
forall val. AesonVal val => val
aesonNull (JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
p)
  jsonBool :: JsonPrintor val Bool Bool
jsonBool = (Bool -> val) -> JsonPrintor val Bool Bool
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive Bool -> val
forall val. AesonVal val => Bool -> val
aesonBool
  {-# INLINE jsonBool #-}
  jsonNumber :: JsonPrintor val Scientific Scientific
jsonNumber = (Scientific -> val) -> JsonPrintor val Scientific Scientific
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive Scientific -> val
forall val. AesonVal val => Scientific -> val
aesonNumber
  jsonInt :: JsonPrintor val Int Int
jsonInt = (Int -> val) -> JsonPrintor val Int Int
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Int -> Encoding) -> Int -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Int -> Encoding
Encoding.int)
  {-# INLINE jsonInt #-}
  jsonInt8 :: JsonPrintor val Int8 Int8
jsonInt8 = (Int8 -> val) -> JsonPrintor val Int8 Int8
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Int8 -> Encoding) -> Int8 -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Int8 -> Encoding
Encoding.int8)
  jsonInt16 :: JsonPrintor val Int16 Int16
jsonInt16 = (Int16 -> val) -> JsonPrintor val Int16 Int16
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Int16 -> Encoding) -> Int16 -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Int16 -> Encoding
Encoding.int16)
  jsonInt32 :: JsonPrintor val Int32 Int32
jsonInt32 = (Int32 -> val) -> JsonPrintor val Int32 Int32
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Int32 -> Encoding) -> Int32 -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Int32 -> Encoding
Encoding.int32)
  jsonInt64 :: JsonPrintor val Int64 Int64
jsonInt64 = (Int64 -> val) -> JsonPrintor val Int64 Int64
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Int64 -> Encoding) -> Int64 -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Int64 -> Encoding
Encoding.int64)
  jsonWord :: JsonPrintor val Word Word
jsonWord = (Word -> val) -> JsonPrintor val Word Word
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Word -> Encoding) -> Word -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Word -> Encoding
Encoding.word)
  jsonWord8 :: JsonPrintor val Word8 Word8
jsonWord8 = (Word8 -> val) -> JsonPrintor val Word8 Word8
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Word8 -> Encoding) -> Word8 -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Word8 -> Encoding
Encoding.word8)
  jsonWord16 :: JsonPrintor val Word16 Word16
jsonWord16 = (Word16 -> val) -> JsonPrintor val Word16 Word16
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Word16 -> Encoding) -> Word16 -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Word16 -> Encoding
Encoding.word16)
  jsonWord32 :: JsonPrintor val Word32 Word32
jsonWord32 = (Word32 -> val) -> JsonPrintor val Word32 Word32
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Word32 -> Encoding) -> Word32 -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Word32 -> Encoding
Encoding.word32)
  jsonWord64 :: JsonPrintor val Word64 Word64
jsonWord64 = (Word64 -> val) -> JsonPrintor val Word64 Word64
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Word64 -> Encoding) -> Word64 -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Word64 -> Encoding
Encoding.word64)
  jsonInteger :: JsonPrintor val Integer Integer
jsonInteger = (Integer -> val) -> JsonPrintor val Integer Integer
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Integer -> Encoding) -> Integer -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral Integer -> Encoding
Encoding.integer)
  jsonNatural :: JsonPrintor val Natural Natural
jsonNatural = (Natural -> val) -> JsonPrintor val Natural Natural
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive ((Natural -> Encoding) -> Natural -> val
forall a. Integral a => (a -> Encoding) -> a -> val
forall val a.
(AesonVal val, Integral a) =>
(a -> Encoding) -> a -> val
aesonIntegral (Integer -> Encoding
Encoding.integer (Integer -> Encoding)
-> (Natural -> Integer) -> Natural -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Integer
forall a. Integral a => a -> Integer
toInteger))
  jsonDouble :: JsonPrintor val Double Double
jsonDouble = (Double -> val) -> JsonPrintor val Double Double
forall val a b. AesonStr val => (a -> val) -> JsonPrintor val a b
primitive Double -> val
forall val. AesonVal val => Double -> val
aesonDouble
  jsonValue :: JsonPrintor val Value Value
jsonValue = (Value -> val) -> JsonPrintor val Value Value
forall a val b. (a -> val) -> JsonPrintor val a b
printing Value -> val
forall val. AesonVal val => Value -> val
aesonValue
  jsonArray :: forall a b. JsonPrintor val a b -> JsonPrintor val [a] [b]
jsonArray JsonPrintor val a b
p = (Set String -> Bool)
-> ([a] -> Maybe val)
-> ([a] -> val)
-> ([a] -> Either JsonError val)
-> Maybe ([[a]] -> val)
-> JsonPrintor val [a] [b]
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
    (\Set String
rules -> JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
rules)
    (\[a]
as -> if JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
forall a. Set a
Set.empty
      then val -> Maybe val
forall a. a -> Maybe a
Just ([a] -> val
render [a]
as)
      else (val -> val) -> [val] -> val
forall val a. AesonVal val => (a -> val) -> [a] -> val
forall a. (a -> val) -> [a] -> val
aesonList val -> val
forall a. a -> a
id ([val] -> val) -> Maybe [val] -> Maybe val
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> Maybe val) -> [a] -> Maybe [val]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p) [a]
as)
    [a] -> val
render
    (\[a]
as -> (val -> val) -> [val] -> val
forall val a. AesonVal val => (a -> val) -> [a] -> val
forall a. (a -> val) -> [a] -> val
aesonList val -> val
forall a. a -> a
id ([val] -> val) -> Either JsonError [val] -> Either JsonError val
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      (Int -> a -> Either JsonError val)
-> [Int] -> [a] -> Either JsonError [val]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM (\Int
i a
a -> JSONPathElement -> Either JsonError val -> Either JsonError val
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Int -> JSONPathElement
Index Int
i) (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p a
a)) [Int
0 ..] [a]
as)
    Maybe ([[a]] -> val)
forall a. Maybe a
Nothing
    where
      render :: [a] -> val
render = ([a] -> val) -> Maybe ([a] -> val) -> [a] -> val
forall a. a -> Maybe a -> a
fromMaybe ((a -> val) -> [a] -> val
forall val a. AesonVal val => (a -> val) -> [a] -> val
forall a. (a -> val) -> [a] -> val
aesonList (JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
p)) (JsonPrintor val a b -> Maybe ([a] -> val)
forall val a b. JsonPrintor val a b -> Maybe ([a] -> val)
printorRenderArray JsonPrintor val a b
p)
  {-# INLINE jsonArray #-}
  -- | As the default, but rendering an array of two elements directly.
  jsonPair :: forall a b c d.
JsonPrintor val a b
-> JsonPrintor val c d -> JsonPrintor val (a, c) (b, d)
jsonPair JsonPrintor val a b
p JsonPrintor val c d
q = (Set String -> Bool)
-> ((a, c) -> Maybe val)
-> ((a, c) -> val)
-> ((a, c) -> Either JsonError val)
-> Maybe ([(a, c)] -> val)
-> JsonPrintor val (a, c) (b, d)
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
    (\Set String
rules -> JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
rules Bool -> Bool -> Bool
&& JsonPrintor val c d -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val c d
q Set String
rules)
    (\(a
a, c
c) -> val -> val -> val
forall val. AesonVal val => val -> val -> val
aesonPair (val -> val -> val) -> Maybe val -> Maybe (val -> val)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p a
a Maybe (val -> val) -> Maybe val -> Maybe val
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JsonPrintor val c d -> c -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val c d
q c
c)
    (a, c) -> val
render
    (\(a
a, c
c) -> val -> val -> val
forall val. AesonVal val => val -> val -> val
aesonPair
      (val -> val -> val)
-> Either JsonError val -> Either JsonError (val -> val)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSONPathElement -> Either JsonError val -> Either JsonError val
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Int -> JSONPathElement
Index Int
0) (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p a
a)
      Either JsonError (val -> val)
-> Either JsonError val -> Either JsonError val
forall a b.
Either JsonError (a -> b)
-> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSONPathElement -> Either JsonError val -> Either JsonError val
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Int -> JSONPathElement
Index Int
1) (JsonPrintor val c d -> c -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val c d
q c
c))
    Maybe ([(a, c)] -> val)
forall a. Maybe a
Nothing
    where
      render :: (a, c) -> val
render (a
a, c
c) =
        let x :: val
x = JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
p a
a; y :: val
y = JsonPrintor val c d -> c -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val c d
q c
c
        in val
x val -> val -> val
forall a b. a -> b -> b
`seq` val
y val -> val -> val
forall a b. a -> b -> b
`seq` val -> val -> val
forall val. AesonVal val => val -> val -> val
aesonPair val
x val
y
  {-# INLINE jsonPair #-}
  -- | As the default, but rendering its one property directly.
  jsonTag :: forall a b. Text -> JsonPrintor val a b -> JsonPrintor val a b
jsonTag Text
k JsonPrintor val a b
p = (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
    (\Set String
rules -> JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
rules)
    ((val -> val) -> Maybe val -> Maybe val
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (AesonKey val -> val -> val
forall val. AesonVal val => AesonKey val -> val -> val
aesonTag AesonKey val
key) (Maybe val -> Maybe val) -> (a -> Maybe val) -> a -> Maybe val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p)
    (\a
a -> let printed :: val
printed = JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
p a
a
      in val
printed val -> val -> val
forall a b. a -> b -> b
`seq` AesonKey val -> val -> val
forall val. AesonVal val => AesonKey val -> val -> val
aesonTag AesonKey val
key val
printed)
    ((val -> val) -> Either JsonError val -> Either JsonError val
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (AesonKey val -> val -> val
forall val. AesonVal val => AesonKey val -> val -> val
aesonTag AesonKey val
key) (Either JsonError val -> Either JsonError val)
-> (a -> Either JsonError val) -> a -> Either JsonError val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSONPathElement -> Either JsonError val -> Either JsonError val
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Key -> JSONPathElement
Key (Text -> Key
Key.fromText Text
k)) (Either JsonError val -> Either JsonError val)
-> (a -> Either JsonError val) -> a -> Either JsonError val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p)
    Maybe ([a] -> val)
forall a. Maybe a
Nothing
    where
      key :: AesonKey val
key = forall val. AesonVal val => Key -> AesonKey val
aesonKey @val (Text -> Key
Key.fromText Text
k)
  {-# INLINE jsonTag #-}
  jsonMap :: forall b a c d.
Ord b =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonPrintor val c d -> JsonPrintor val (Map a c) (Map b d)
jsonMap forall (k :: * -> * -> *). JsonStr k => k a b
key = (forall r. (a -> c -> r -> r) -> r -> Map a c -> r)
-> (forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonPrintor val c d
-> JsonPrintor val (Map a c) (Map b d)
forall val a c m b d n.
AesonVal val =>
(forall r. (a -> c -> r -> r) -> r -> m -> r)
-> (forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonPrintor val c d
-> JsonPrintor val m n
printDistinct (a -> c -> r -> r) -> r -> Map a c -> r
forall r. (a -> c -> r -> r) -> r -> Map a c -> r
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey k a b
forall (k :: * -> * -> *). JsonStr k => k a b
key
  jsonHashMap :: forall b a c d.
(Eq b, Hashable b) =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonPrintor val c d
-> JsonPrintor val (HashMap a c) (HashMap b d)
jsonHashMap forall (k :: * -> * -> *). JsonStr k => k a b
key = (forall r. (a -> c -> r -> r) -> r -> HashMap a c -> r)
-> (forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonPrintor val c d
-> JsonPrintor val (HashMap a c) (HashMap b d)
forall val a c m b d n.
AesonVal val =>
(forall r. (a -> c -> r -> r) -> r -> m -> r)
-> (forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonPrintor val c d
-> JsonPrintor val m n
printDistinct (a -> c -> r -> r) -> r -> HashMap a c -> r
forall r. (a -> c -> r -> r) -> r -> HashMap a c -> r
forall k v a. (k -> v -> a -> a) -> a -> HashMap k v -> a
HashMap.foldrWithKey k a b
forall (k :: * -> * -> *). JsonStr k => k a b
key
  jsonTuple :: forall a b.
(forall (q :: * -> * -> *). JsonTup (JsonPrintor val) q => q a b)
-> JsonPrintor val a b
jsonTuple = (forall (q :: * -> * -> *). JsonTup (JsonPrintor val) q => q a b)
-> JsonPrintor val a b
forall val a b.
AesonVal val =>
(forall (q :: * -> * -> *). JsonTup (JsonPrintor val) q => q a b)
-> JsonPrintor val a b
printTuple
  {-# INLINE jsonTuple #-}
  jsonObject :: forall a b.
(forall (q :: * -> * -> *). JsonObj (JsonPrintor val) q => q a b)
-> JsonPrintor val a b
jsonObject forall (q :: * -> * -> *). JsonObj (JsonPrintor val) q => q a b
obj = case
    ([Key] -> Maybe Key -> Maybe Key)
-> Maybe Key -> [[Key]] -> Maybe Key
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Maybe Key -> Maybe Key -> Maybe Key
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) (Maybe Key -> Maybe Key -> Maybe Key)
-> ([Key] -> Maybe Key) -> [Key] -> Maybe Key -> Maybe Key
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Key] -> Maybe Key
duplicateKey) Maybe Key
forall a. Maybe a
Nothing (ObjPrintor val a b -> [[Key]]
forall val a b. ObjPrintor val a b -> [[Key]]
objPrintorShapes ObjPrintor val a b
printor) of
    Just Key
key -> (a -> Maybe val)
-> (a -> Either JsonError val) -> JsonPrintor val a b
forall val a b.
AesonVal val =>
(a -> Maybe val)
-> (a -> Either JsonError val) -> JsonPrintor val a b
trying (Maybe val -> a -> Maybe val
forall a b. a -> b -> a
const Maybe val
forall a. Maybe a
Nothing) (\a
_ -> Key -> Either JsonError val
forall a. Key -> Either JsonError a
printDuplicate Key
key)
    Maybe Key
Nothing
      | ObjPrintor val a b -> Bool
forall val a b. ObjPrintor val a b -> Bool
objPrintorRest ObjPrintor val a b
printor -> (a -> Maybe val)
-> (a -> Either JsonError val) -> JsonPrintor val a b
forall val a b.
AesonVal val =>
(a -> Maybe val)
-> (a -> Either JsonError val) -> JsonPrintor val a b
trying
        (\a
a -> do
          props <- DList (Key, val) -> [(Key, val)]
forall a. DList a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (DList (Key, val) -> [(Key, val)])
-> Maybe (DList (Key, val)) -> Maybe [(Key, val)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ObjPrintor val a b -> a -> Maybe (DList (Key, val))
forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry ObjPrintor val a b
printor a
a
          guard (isNothing (duplicateKey (map fst props)))
          Just (aesonObject props))
        (\a
a -> do
          props <- ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
forall val a b.
ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
objPrintorCheck ObjPrintor val a b
printor a
a
          maybe (Right (aesonObject props)) printDuplicate
            (duplicateKey (map fst props)))
      | Bool
otherwise -> (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
        (\Set String
rules -> ObjPrintor val a b -> Set String -> Bool
forall val a b. ObjPrintor val a b -> Set String -> Bool
objPrintorTotal ObjPrintor val a b
printor Set String
rules)
        ((DList (Key, val) -> val) -> Maybe (DList (Key, val)) -> Maybe val
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([(Key, val)] -> val
forall val. AesonVal val => [(Key, val)] -> val
aesonObject ([(Key, val)] -> val)
-> (DList (Key, val) -> [(Key, val)]) -> DList (Key, val) -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList (Key, val) -> [(Key, val)]
forall a. DList a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList) (Maybe (DList (Key, val)) -> Maybe val)
-> (a -> Maybe (DList (Key, val))) -> a -> Maybe val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry ObjPrintor val a b
printor)
        (\a
a -> AesonProps val -> val
forall val. AesonVal val => AesonProps val -> val
aesonProps (ObjPrintor val a b -> a -> AesonProps val -> AesonProps val
forall val a b.
ObjPrintor val a b -> a -> AesonProps val -> AesonProps val
objPrintorRender ObjPrintor val a b
printor a
a (forall val. AesonVal val => AesonProps val
aesonPropsEmpty @val)))
        (([(Key, val)] -> val)
-> Either JsonError [(Key, val)] -> Either JsonError val
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(Key, val)] -> val
forall val. AesonVal val => [(Key, val)] -> val
aesonObject (Either JsonError [(Key, val)] -> Either JsonError val)
-> (a -> Either JsonError [(Key, val)])
-> a
-> Either JsonError val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
forall val a b.
ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
objPrintorCheck ObjPrintor val a b
printor)
        Maybe ([a] -> val)
forall a. Maybe a
Nothing
    where
      printor :: ObjPrintor val a b
printor = forall (q :: * -> * -> *). JsonObj (JsonPrintor val) q => q a b
obj @(ObjPrintor val)
  -- | The properties which a strict object rejects are never printed.
  jsonObjectStrict :: forall a b.
(forall (q :: * -> * -> *). JsonObj (JsonPrintor val) q => q a b)
-> JsonPrintor val a b
jsonObjectStrict forall (q :: * -> * -> *). JsonObj (JsonPrintor val) q => q a b
obj = (forall (q :: * -> * -> *). JsonObj (JsonPrintor val) q => q a b)
-> JsonPrintor val a b
forall a b.
(forall (q :: * -> * -> *). JsonObj (JsonPrintor val) q => q a b)
-> JsonPrintor val a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject q a b
forall (q :: * -> * -> *). JsonObj (JsonPrintor val) q => q a b
obj
  {-# INLINE jsonNull #-}
  {-# INLINE jsonNullable #-}
  {-# INLINE jsonNumber #-}
  {-# INLINE jsonInt8 #-}
  {-# INLINE jsonInt16 #-}
  {-# INLINE jsonInt32 #-}
  {-# INLINE jsonInt64 #-}
  {-# INLINE jsonWord #-}
  {-# INLINE jsonWord8 #-}
  {-# INLINE jsonWord16 #-}
  {-# INLINE jsonWord32 #-}
  {-# INLINE jsonWord64 #-}
  {-# INLINE jsonInteger #-}
  {-# INLINE jsonNatural #-}
  {-# INLINE jsonDouble #-}
  {-# INLINE jsonValue #-}
  {-# INLINE jsonMap #-}
  {-# INLINE jsonHashMap #-}
  {-# INLINE jsonObject #-}
  {-# INLINE jsonObjectStrict #-}

instance Functor (TupPrintor val a) where
  fmap :: forall a b. (a -> b) -> TupPrintor val a a -> TupPrintor val a b
fmap a -> b
_ (TupPrintor Set String -> Bool
total a -> Maybe (DList val)
attempt a -> AesonElems val -> AesonElems val
render a -> Elements val
check Maybe (a -> val)
single) =
    (Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor Set String -> Bool
total a -> Maybe (DList val)
attempt a -> AesonElems val -> AesonElems val
render a -> Elements val
check Maybe (a -> val)
single
  {-# INLINE fmap #-}
instance Applicative (TupPrintor val a) where
  pure :: forall a. a -> TupPrintor val a a
pure a
_ = (Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a a
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor
    (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
True) (Maybe (DList val) -> a -> Maybe (DList val)
forall a b. a -> b -> a
const (DList val -> Maybe (DList val)
forall a. a -> Maybe a
Just DList val
forall a. Monoid a => a
mempty)) (\a
_ AesonElems val
rest -> AesonElems val
rest) a -> Elements val
forall a. Monoid a => a
mempty Maybe (a -> val)
forall a. Maybe a
Nothing
  TupPrintor val a (a -> b)
p <*> :: forall a b.
TupPrintor val a (a -> b)
-> TupPrintor val a a -> TupPrintor val a b
<*> TupPrintor val a a
q = (Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor
    (\Set String
rules -> TupPrintor val a (a -> b) -> Set String -> Bool
forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal TupPrintor val a (a -> b)
p Set String
rules Bool -> Bool -> Bool
&& TupPrintor val a a -> Set String -> Bool
forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal TupPrintor val a a
q Set String
rules)
    (\a
a -> DList val -> DList val -> DList val
forall a. Semigroup a => a -> a -> a
(<>) (DList val -> DList val -> DList val)
-> Maybe (DList val) -> Maybe (DList val -> DList val)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TupPrintor val a (a -> b) -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a (a -> b)
p a
a Maybe (DList val -> DList val)
-> Maybe (DList val) -> Maybe (DList val)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TupPrintor val a a -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a a
q a
a)
    (\a
a AesonElems val
rest -> TupPrintor val a (a -> b) -> a -> AesonElems val -> AesonElems val
forall val a b.
TupPrintor val a b -> a -> AesonElems val -> AesonElems val
tupPrintorRender TupPrintor val a (a -> b)
p a
a (AesonElems val -> AesonElems val)
-> AesonElems val -> AesonElems val
forall a b. (a -> b) -> a -> b
$! TupPrintor val a a -> a -> AesonElems val -> AesonElems val
forall val a b.
TupPrintor val a b -> a -> AesonElems val -> AesonElems val
tupPrintorRender TupPrintor val a a
q a
a AesonElems val
rest)
    (TupPrintor val a (a -> b) -> a -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val a (a -> b)
p (a -> Elements val) -> (a -> Elements val) -> a -> Elements val
forall a. Semigroup a => a -> a -> a
<> TupPrintor val a a -> a -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val a a
q)
    Maybe (a -> val)
forall a. Maybe a
Nothing
  liftA2 :: forall a b c.
(a -> b -> c)
-> TupPrintor val a a -> TupPrintor val a b -> TupPrintor val a c
liftA2 a -> b -> c
f TupPrintor val a a
p TupPrintor val a b
q = (a -> b -> c) -> TupPrintor val a a -> TupPrintor val a (b -> c)
forall a b. (a -> b) -> TupPrintor val a a -> TupPrintor val a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b -> c
f TupPrintor val a a
p TupPrintor val a (b -> c)
-> TupPrintor val a b -> TupPrintor val a c
forall a b.
TupPrintor val a (a -> b)
-> TupPrintor val a a -> TupPrintor val a b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TupPrintor val a b
q
  TupPrintor val a a
p *> :: forall a b.
TupPrintor val a a -> TupPrintor val a b -> TupPrintor val a b
*> TupPrintor val a b
q = (a -> b -> b) -> TupPrintor val a a -> TupPrintor val a (b -> b)
forall a b. (a -> b) -> TupPrintor val a a -> TupPrintor val a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
_ b
b -> b
b) TupPrintor val a a
p TupPrintor val a (b -> b)
-> TupPrintor val a b -> TupPrintor val a b
forall a b.
TupPrintor val a (a -> b)
-> TupPrintor val a a -> TupPrintor val a b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TupPrintor val a b
q
  TupPrintor val a a
p <* :: forall a b.
TupPrintor val a a -> TupPrintor val a b -> TupPrintor val a a
<* TupPrintor val a b
q = (a -> b -> a) -> TupPrintor val a a -> TupPrintor val a (b -> a)
forall a b. (a -> b) -> TupPrintor val a a -> TupPrintor val a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b -> a
forall a b. a -> b -> a
const TupPrintor val a a
p TupPrintor val a (b -> a)
-> TupPrintor val a b -> TupPrintor val a a
forall a b.
TupPrintor val a (a -> b)
-> TupPrintor val a a -> TupPrintor val a b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TupPrintor val a b
q
  {-# INLINE pure #-}
  {-# INLINE (<*>) #-}
  {-# INLINE liftA2 #-}
  {-# INLINE (*>) #-}
  {-# INLINE (<*) #-}
instance AesonVal val => Profunctor (TupPrintor val) where
  {-# SPECIALISE instance Profunctor (TupPrintor Value) #-}
  {-# SPECIALISE instance Profunctor (TupPrintor Encoding) #-}
  dimap :: forall a b c d.
(a -> b) -> (c -> d) -> TupPrintor val b c -> TupPrintor val a d
dimap a -> b
f c -> d
_ TupPrintor val b c
p = case TupPrintor val b c -> Maybe (b -> val)
forall val a b. TupPrintor val a b -> Maybe (a -> val)
tupPrintorElement TupPrintor val b c
p of
    Just b -> val
single ->
      let projected :: a -> val
projected a
a = b -> val
single (b -> val) -> b -> val
forall a b. (a -> b) -> a -> b
$! a -> b
f a
a in (Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a d
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor Set String -> Bool
total
        (b -> Maybe (DList val)
attempt (b -> Maybe (DList val)) -> (a -> b) -> a -> Maybe (DList val)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) ((a -> val) -> a -> AesonElems val -> AesonElems val
forall val a.
AesonVal val =>
(a -> val) -> a -> AesonElems val -> AesonElems val
renderElement a -> val
projected) (b -> Elements val
check (b -> Elements val) -> (a -> b) -> a -> Elements val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) ((a -> val) -> Maybe (a -> val)
forall a. a -> Maybe a
Just a -> val
projected)
    Maybe (b -> val)
Nothing -> (Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a d
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor Set String -> Bool
total (b -> Maybe (DList val)
attempt (b -> Maybe (DList val)) -> (a -> b) -> a -> Maybe (DList val)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
      (\a
a AesonElems val
rest -> let b :: b
b = a -> b
f a
a in b
b b -> AesonElems val -> AesonElems val
forall a b. a -> b -> b
`seq` b -> AesonElems val -> AesonElems val
render b
b AesonElems val
rest) (b -> Elements val
check (b -> Elements val) -> (a -> b) -> a -> Elements val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) Maybe (a -> val)
forall a. Maybe a
Nothing
    where
      TupPrintor Set String -> Bool
total b -> Maybe (DList val)
attempt b -> AesonElems val -> AesonElems val
render b -> Elements val
check Maybe (b -> val)
_ = TupPrintor val b c
p
  {-# INLINE dimap #-}
  lmap :: forall a b c. (a -> b) -> TupPrintor val b c -> TupPrintor val a c
lmap a -> b
f = (a -> b) -> (c -> c) -> TupPrintor val b c -> TupPrintor val a c
forall a b c d.
(a -> b) -> (c -> d) -> TupPrintor val b c -> TupPrintor val a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
f c -> c
forall a. a -> a
id
  {-# INLINE lmap #-}
  q b c
_ #. :: forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> TupPrintor val a b -> TupPrintor val a c
#. TupPrintor val a b
p = TupPrintor val a b -> TupPrintor val a c
forall a b. Coercible a b => a -> b
coerce TupPrintor val a b
p
  TupPrintor val b c
p .# :: forall a b c (q :: * -> * -> *).
Coercible b a =>
TupPrintor val b c -> q a b -> TupPrintor val a c
.# q a b
_ = TupPrintor val b c -> TupPrintor val a c
forall a b. Coercible a b => a -> b
coerce TupPrintor val b c
p
instance AesonVal val => CocartesianMonoidal (TupPrintor val) where
  zeroP :: TupPrintor val Void Void
zeroP = (Set String -> Bool)
-> (Void -> Maybe (DList val))
-> (Void -> AesonElems val -> AesonElems val)
-> (Void -> Elements val)
-> Maybe (Void -> val)
-> TupPrintor val Void Void
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
True) Void -> Maybe (DList val)
forall a. Void -> a
absurd Void -> AesonElems val -> AesonElems val
forall a. Void -> a
absurd Void -> Elements val
forall a. Void -> a
absurd Maybe (Void -> val)
forall a. Maybe a
Nothing
  TupPrintor val a b
p >+< :: forall a b c d.
TupPrintor val a b
-> TupPrintor val c d -> TupPrintor val (Either a c) (Either b d)
>+< TupPrintor val c d
q = (Set String -> Bool)
-> (Either a c -> Maybe (DList val))
-> (Either a c -> AesonElems val -> AesonElems val)
-> (Either a c -> Elements val)
-> Maybe (Either a c -> val)
-> TupPrintor val (Either a c) (Either b d)
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor
    (\Set String
rules -> TupPrintor val a b -> Set String -> Bool
forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal TupPrintor val a b
p Set String
rules Bool -> Bool -> Bool
&& TupPrintor val c d -> Set String -> Bool
forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal TupPrintor val c d
q Set String
rules)
    ((a -> Maybe (DList val))
-> (c -> Maybe (DList val)) -> Either a c -> Maybe (DList val)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (TupPrintor val a b -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a b
p) (TupPrintor val c d -> c -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val c d
q))
    (\Either a c
e AesonElems val
rest -> case Either a c
e of
      Left a
a -> TupPrintor val a b -> a -> AesonElems val -> AesonElems val
forall val a b.
TupPrintor val a b -> a -> AesonElems val -> AesonElems val
tupPrintorRender TupPrintor val a b
p a
a AesonElems val
rest
      Right c
b -> TupPrintor val c d -> c -> AesonElems val -> AesonElems val
forall val a b.
TupPrintor val a b -> a -> AesonElems val -> AesonElems val
tupPrintorRender TupPrintor val c d
q c
b AesonElems val
rest)
    ((a -> Elements val)
-> (c -> Elements val) -> Either a c -> Elements val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (TupPrintor val a b -> a -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val a b
p) (TupPrintor val c d -> c -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val c d
q))
    Maybe (Either a c -> val)
forall a. Maybe a
Nothing
instance AesonVal val => Distributor (TupPrintor val) where
  manyP :: forall a b. TupPrintor val a b -> TupPrintor val [a] [b]
manyP TupPrintor val a b
p = (Set String -> Bool)
-> ([a] -> Maybe (DList val))
-> ([a] -> AesonElems val -> AesonElems val)
-> ([a] -> Elements val)
-> Maybe ([a] -> val)
-> TupPrintor val [a] [b]
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor
    (\Set String
rules -> TupPrintor val a b -> Set String -> Bool
forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal TupPrintor val a b
p Set String
rules)
    (([DList val] -> DList val)
-> Maybe [DList val] -> Maybe (DList val)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [DList val] -> DList val
forall a. Monoid a => [a] -> a
mconcat (Maybe [DList val] -> Maybe (DList val))
-> ([a] -> Maybe [DList val]) -> [a] -> Maybe (DList val)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> DList val)
-> [a]
-> Maybe [DList val]
forall (f :: * -> *) a b.
Traversable f =>
(Set String -> Bool)
-> (a -> Maybe b) -> (a -> b) -> f a -> Maybe (f b)
tryAll (TupPrintor val a b -> Set String -> Bool
forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal TupPrintor val a b
p) (TupPrintor val a b -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a b
p)
      (\a
a -> DList val -> Maybe (DList val) -> DList val
forall a. a -> Maybe a -> a
fromMaybe DList val
forall a. Monoid a => a
mempty (TupPrintor val a b -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a b
p a
a)))
    (\[a]
as AesonElems val
rest -> (a -> AesonElems val -> AesonElems val)
-> AesonElems val -> [a] -> AesonElems val
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\a
a AesonElems val
printed -> TupPrintor val a b -> a -> AesonElems val -> AesonElems val
forall val a b.
TupPrintor val a b -> a -> AesonElems val -> AesonElems val
tupPrintorRender TupPrintor val a b
p a
a (AesonElems val -> AesonElems val)
-> AesonElems val -> AesonElems val
forall a b. (a -> b) -> a -> b
$! AesonElems val
printed) AesonElems val
rest [a]
as)
    ((a -> Elements val) -> [a] -> Elements val
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (TupPrintor val a b -> a -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val a b
p))
    Maybe ([a] -> val)
forall a. Maybe a
Nothing
  optionalP :: forall a b.
TupPrintor val a b -> TupPrintor val (Maybe a) (Maybe b)
optionalP TupPrintor val a b
p = (Set String -> Bool)
-> (Maybe a -> Maybe (DList val))
-> (Maybe a -> AesonElems val -> AesonElems val)
-> (Maybe a -> Elements val)
-> Maybe (Maybe a -> val)
-> TupPrintor val (Maybe a) (Maybe b)
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor
    (\Set String
rules -> TupPrintor val a b -> Set String -> Bool
forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal TupPrintor val a b
p Set String
rules)
    (Maybe (DList val)
-> (a -> Maybe (DList val)) -> Maybe a -> Maybe (DList val)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (DList val -> Maybe (DList val)
forall a. a -> Maybe a
Just DList val
forall a. Monoid a => a
mempty) (TupPrintor val a b -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a b
p))
    (\Maybe a
ma AesonElems val
rest -> AesonElems val
-> (a -> AesonElems val) -> Maybe a -> AesonElems val
forall b a. b -> (a -> b) -> Maybe a -> b
maybe AesonElems val
rest (\a
a -> TupPrintor val a b -> a -> AesonElems val -> AesonElems val
forall val a b.
TupPrintor val a b -> a -> AesonElems val -> AesonElems val
tupPrintorRender TupPrintor val a b
p a
a AesonElems val
rest) Maybe a
ma)
    ((a -> Elements val) -> Maybe a -> Elements val
forall m a. Monoid m => (a -> m) -> Maybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (TupPrintor val a b -> a -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val a b
p))
    Maybe (Maybe a -> val)
forall a. Maybe a
Nothing
-- | `optionP` omits its default.
instance AesonVal val => Alternative (TupPrintor val a) where
  empty :: forall a. TupPrintor val a a
empty = TupPrintor val a a
forall a. DisjunctiveMonoid a => a
falseP
  <|> :: forall a.
TupPrintor val a a -> TupPrintor val a a -> TupPrintor val a a
(<|>) = TupPrintor val a a -> TupPrintor val a a -> TupPrintor val a a
forall a. DisjunctiveMonoid a => a -> a -> a
(>|<)
  many :: forall a. TupPrintor val a a -> TupPrintor val a [a]
many = (a -> [a]) -> TupPrintor val [a] [a] -> TupPrintor val a [a]
forall a b c. (a -> b) -> TupPrintor val b c -> TupPrintor val a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> [a]
forall a. a -> [a]
repeat (TupPrintor val [a] [a] -> TupPrintor val a [a])
-> (TupPrintor val a a -> TupPrintor val [a] [a])
-> TupPrintor val a a
-> TupPrintor val a [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupPrintor val a a -> TupPrintor val [a] [a]
forall a b. TupPrintor val a b -> TupPrintor val [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP
  some :: forall a. TupPrintor val a a -> TupPrintor val a [a]
some = (a -> [a]) -> TupPrintor val [a] [a] -> TupPrintor val a [a]
forall a b c. (a -> b) -> TupPrintor val b c -> TupPrintor val a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> [a]
forall a. a -> [a]
repeat (TupPrintor val [a] [a] -> TupPrintor val a [a])
-> (TupPrintor val a a -> TupPrintor val [a] [a])
-> TupPrintor val a a
-> TupPrintor val a [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupPrintor val a a -> TupPrintor val [a] [a]
forall a b. TupPrintor val a b -> TupPrintor val [a] [b]
forall (p :: * -> * -> *) a b. Alternator p => p a b -> p [a] [b]
someP
instance AesonVal val => Alternator (TupPrintor val) where
  optionP :: forall a b.
APrism a b () () -> TupPrintor val a b -> TupPrintor val a b
optionP APrism a b () ()
def TupPrintor val a b
p = APrism a b () () -> TupPrintor val a b
forall (p :: * -> * -> *) a b.
(Monoidal p, Choice p) =>
APrism a b () () -> p a b
pureP APrism a b () ()
def TupPrintor val a b -> TupPrintor val a b -> TupPrintor val a b
forall a. DisjunctiveMonoid a => a -> a -> a
>|< TupPrintor val a b
p
instance AesonVal val => Choice (TupPrintor val) where
  left' :: forall a b c.
TupPrintor val a b -> TupPrintor val (Either a c) (Either b c)
left' = Either (TupPrintor val a b) (TupPrintor val c c)
-> TupPrintor val (Either a c) (Either b c)
forall a b c d.
Either (TupPrintor val a b) (TupPrintor val c d)
-> TupPrintor val (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianChoice p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (Either (TupPrintor val a b) (TupPrintor val c c)
 -> TupPrintor val (Either a c) (Either b c))
-> (TupPrintor val a b
    -> Either (TupPrintor val a b) (TupPrintor val c c))
-> TupPrintor val a b
-> TupPrintor val (Either a c) (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupPrintor val a b
-> Either (TupPrintor val a b) (TupPrintor val c c)
forall a b. a -> Either a b
Left
  right' :: forall a b c.
TupPrintor val a b -> TupPrintor val (Either c a) (Either c b)
right' = Either (TupPrintor val c c) (TupPrintor val a b)
-> TupPrintor val (Either c a) (Either c b)
forall a b c d.
Either (TupPrintor val a b) (TupPrintor val c d)
-> TupPrintor val (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianChoice p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (Either (TupPrintor val c c) (TupPrintor val a b)
 -> TupPrintor val (Either c a) (Either c b))
-> (TupPrintor val a b
    -> Either (TupPrintor val c c) (TupPrintor val a b))
-> TupPrintor val a b
-> TupPrintor val (Either c a) (Either c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupPrintor val a b
-> Either (TupPrintor val c c) (TupPrintor val a b)
forall a b. b -> Either a b
Right
unprintable :: Elements val
unprintable :: forall val. Elements val
unprintable = Either JsonError (Int, DList val) -> Elements val
forall val. Either JsonError (Int, DList val) -> Elements val
Elements (Maybe Value -> Either JsonError (Int, DList val)
forall a. Maybe Value -> Either JsonError a
jsonUnexpected Maybe Value
forall a. Maybe a
Nothing)

-- | A partial t'TupPrintor', rendering what it tries, or else nothing.
tupTrying
  :: AesonVal val
  => (a -> Maybe (DList val)) -> (a -> Elements val) -> TupPrintor val a b
tupTrying :: forall val a b.
AesonVal val =>
(a -> Maybe (DList val))
-> (a -> Elements val) -> TupPrintor val a b
tupTrying a -> Maybe (DList val)
attempt a -> Elements val
check = (Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
False) a -> Maybe (DList val)
attempt
  (\a
a -> DList val -> AesonElems val -> AesonElems val
forall val.
AesonVal val =>
DList val -> AesonElems val -> AesonElems val
prependElems (DList val -> Maybe (DList val) -> DList val
forall a. a -> Maybe a -> a
fromMaybe DList val
forall a. Monoid a => a
mempty (a -> Maybe (DList val)
attempt a
a))) a -> Elements val
check Maybe (a -> val)
forall a. Maybe a
Nothing

-- | Render tried elements before others.
prependElems :: AesonVal val => DList val -> AesonElems val -> AesonElems val
prependElems :: forall val.
AesonVal val =>
DList val -> AesonElems val -> AesonElems val
prependElems DList val
items AesonElems val
rest = (val -> AesonElems val -> AesonElems val)
-> AesonElems val -> DList val -> AesonElems val
forall a b. (a -> b -> b) -> b -> DList a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr val -> AesonElems val -> AesonElems val
forall val. AesonVal val => val -> AesonElems val -> AesonElems val
aesonElem AesonElems val
rest DList val
items

instance AesonVal val => CocartesianChoice (TupPrintor val) where
  alternate :: forall a b c d.
Either (TupPrintor val a b) (TupPrintor val c d)
-> TupPrintor val (Either a c) (Either b d)
alternate = \case
    Left TupPrintor val a b
p -> (Either a c -> Maybe (DList val))
-> (Either a c -> Elements val)
-> TupPrintor val (Either a c) (Either b d)
forall val a b.
AesonVal val =>
(a -> Maybe (DList val))
-> (a -> Elements val) -> TupPrintor val a b
tupTrying
      ((a -> Maybe (DList val))
-> (c -> Maybe (DList val)) -> Either a c -> Maybe (DList val)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (TupPrintor val a b -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a b
p) (Maybe (DList val) -> c -> Maybe (DList val)
forall a b. a -> b -> a
const Maybe (DList val)
forall a. Maybe a
Nothing))
      ((a -> Elements val)
-> (c -> Elements val) -> Either a c -> Elements val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (TupPrintor val a b -> a -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val a b
p) (\c
_ -> Elements val
forall val. Elements val
unprintable))
    Right TupPrintor val c d
p -> (Either a c -> Maybe (DList val))
-> (Either a c -> Elements val)
-> TupPrintor val (Either a c) (Either b d)
forall val a b.
AesonVal val =>
(a -> Maybe (DList val))
-> (a -> Elements val) -> TupPrintor val a b
tupTrying
      ((a -> Maybe (DList val))
-> (c -> Maybe (DList val)) -> Either a c -> Maybe (DList val)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe (DList val) -> a -> Maybe (DList val)
forall a b. a -> b -> a
const Maybe (DList val)
forall a. Maybe a
Nothing) (TupPrintor val c d -> c -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val c d
p))
      ((a -> Elements val)
-> (c -> Elements val) -> Either a c -> Elements val
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\a
_ -> Elements val
forall val. Elements val
unprintable) (TupPrintor val c d -> c -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val c d
p))
instance AesonVal val => DisjunctiveMonoid (TupPrintor val a b) where
  falseP :: TupPrintor val a b
falseP = (a -> Maybe (DList val))
-> (a -> Elements val) -> TupPrintor val a b
forall val a b.
AesonVal val =>
(a -> Maybe (DList val))
-> (a -> Elements val) -> TupPrintor val a b
tupTrying (Maybe (DList val) -> a -> Maybe (DList val)
forall a b. a -> b -> a
const Maybe (DList val)
forall a. Maybe a
Nothing) (\a
_ -> Elements val
forall val. Elements val
unprintable)
  TupPrintor val a b
p >|< :: TupPrintor val a b -> TupPrintor val a b -> TupPrintor val a b
>|< TupPrintor val a b
q = (Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor
    (\Set String
rules -> TupPrintor val a b -> Set String -> Bool
forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal TupPrintor val a b
p Set String
rules Bool -> Bool -> Bool
|| TupPrintor val a b -> Set String -> Bool
forall val a b. TupPrintor val a b -> Set String -> Bool
tupPrintorTotal TupPrintor val a b
q Set String
rules)
    (\a
a -> TupPrintor val a b -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a b
p a
a Maybe (DList val) -> Maybe (DList val) -> Maybe (DList val)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TupPrintor val a b -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a b
q a
a)
    (\a
a AesonElems val
rest -> AesonElems val
-> (DList val -> AesonElems val)
-> Maybe (DList val)
-> AesonElems val
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
      (TupPrintor val a b -> a -> AesonElems val -> AesonElems val
forall val a b.
TupPrintor val a b -> a -> AesonElems val -> AesonElems val
tupPrintorRender TupPrintor val a b
q a
a AesonElems val
rest) (DList val -> AesonElems val -> AesonElems val
forall val.
AesonVal val =>
DList val -> AesonElems val -> AesonElems val
`prependElems` AesonElems val
rest) (TupPrintor val a b -> a -> Maybe (DList val)
forall val a b. TupPrintor val a b -> a -> Maybe (DList val)
tupPrintorTry TupPrintor val a b
p a
a))
    (\a
a -> case (TupPrintor val a b -> a -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val a b
p a
a, TupPrintor val a b -> a -> Elements val
forall val a b. TupPrintor val a b -> a -> Elements val
tupPrintorCheck TupPrintor val a b
q a
a) of
      (Elements (Left JsonError
err0), Elements (Left JsonError
err1)) ->
        Either JsonError (Int, DList val) -> Elements val
forall val. Either JsonError (Int, DList val) -> Elements val
Elements (JsonError -> Either JsonError (Int, DList val)
forall a b. a -> Either a b
Left (JsonError -> JsonError -> JsonError
jsonOrElse JsonError
err0 JsonError
err1))
      (Elements (Left JsonError
_), Elements val
printed) -> Elements val
printed
      (Elements val
printed, Elements val
_) -> Elements val
printed)
    Maybe (a -> val)
forall a. Maybe a
Nothing

instance AesonVal val => JsonTup (JsonPrintor val) (TupPrintor val) where
  {-# SPECIALISE instance JsonTup (JsonPrintor Value) (TupPrintor Value) #-}
  {-# SPECIALISE instance
    JsonTup (JsonPrintor Encoding) (TupPrintor Encoding) #-}
  jsonElem :: forall a b. JsonPrintor val a b -> TupPrintor val a b
jsonElem JsonPrintor val a b
p = (Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe (DList val))
-> (a -> AesonElems val -> AesonElems val)
-> (a -> Elements val)
-> Maybe (a -> val)
-> TupPrintor val a b
TupPrintor
    (\Set String
rules -> JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
rules)
    ((val -> DList val) -> Maybe val -> Maybe (DList val)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap val -> DList val
forall a. a -> DList a
DList.singleton (Maybe val -> Maybe (DList val))
-> (a -> Maybe val) -> a -> Maybe (DList val)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p)
    ((a -> val) -> a -> AesonElems val -> AesonElems val
forall val a.
AesonVal val =>
(a -> val) -> a -> AesonElems val -> AesonElems val
renderElement (JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
p))
    (\a
a -> Either JsonError (Int, DList val) -> Elements val
forall val. Either JsonError (Int, DList val) -> Elements val
Elements (Either JsonError (Int, DList val) -> Elements val)
-> Either JsonError (Int, DList val) -> Elements val
forall a b. (a -> b) -> a -> b
$ (\val
printed -> (Int
1, val -> DList val
forall a. a -> DList a
forall (f :: * -> *) a. Applicative f => a -> f a
pure val
printed))
      (val -> (Int, DList val))
-> Either JsonError val -> Either JsonError (Int, DList val)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSONPathElement -> Either JsonError val -> Either JsonError val
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Int -> JSONPathElement
Index Int
0) (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p a
a))
    ((a -> val) -> Maybe (a -> val)
forall a. a -> Maybe a
Just (JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
p))
  {-# INLINE jsonElem #-}

instance Functor (ObjPrintor val a) where
  fmap :: forall a b. (a -> b) -> ObjPrintor val a a -> ObjPrintor val a b
fmap a -> b
_ (ObjPrintor [[Key]]
keys Bool
rest Set String -> Bool
total a -> Maybe (DList (Key, val))
attempt a -> AesonProps val -> AesonProps val
render a -> Either JsonError [(Key, val)]
check) =
    [[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor [[Key]]
keys Bool
rest Set String -> Bool
total a -> Maybe (DList (Key, val))
attempt a -> AesonProps val -> AesonProps val
render a -> Either JsonError [(Key, val)]
check
  {-# INLINE fmap #-}
instance Applicative (ObjPrintor val a) where
  pure :: forall a. a -> ObjPrintor val a a
pure a
_ = [[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a a
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor [[]] Bool
False
    (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
True) (Maybe (DList (Key, val)) -> a -> Maybe (DList (Key, val))
forall a b. a -> b -> a
const (DList (Key, val) -> Maybe (DList (Key, val))
forall a. a -> Maybe a
Just DList (Key, val)
forall a. Monoid a => a
mempty)) (\a
_ AesonProps val
rest -> AesonProps val
rest) (\a
_ -> [(Key, val)] -> Either JsonError [(Key, val)]
forall a b. b -> Either a b
Right [])
  ObjPrintor [[Key]]
keys0 Bool
rest0 Set String -> Bool
total0 a -> Maybe (DList (Key, val))
try0 a -> AesonProps val -> AesonProps val
render0 a -> Either JsonError [(Key, val)]
check0
    <*> :: forall a b.
ObjPrintor val a (a -> b)
-> ObjPrintor val a a -> ObjPrintor val a b
<*> ObjPrintor [[Key]]
keys1 Bool
rest1 Set String -> Bool
total1 a -> Maybe (DList (Key, val))
try1 a -> AesonProps val -> AesonProps val
render1 a -> Either JsonError [(Key, val)]
check1 = [[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor
      (([Key] -> [Key] -> [Key]) -> [[Key]] -> [[Key]] -> [[Key]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 [Key] -> [Key] -> [Key]
forall a. Semigroup a => a -> a -> a
(<>) [[Key]]
keys0 [[Key]]
keys1)
      (Bool
rest0 Bool -> Bool -> Bool
|| Bool
rest1)
      (\Set String
rules -> Set String -> Bool
total0 Set String
rules Bool -> Bool -> Bool
&& Set String -> Bool
total1 Set String
rules)
      (\a
a -> DList (Key, val) -> DList (Key, val) -> DList (Key, val)
forall a. Semigroup a => a -> a -> a
(<>) (DList (Key, val) -> DList (Key, val) -> DList (Key, val))
-> Maybe (DList (Key, val))
-> Maybe (DList (Key, val) -> DList (Key, val))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> Maybe (DList (Key, val))
try0 a
a Maybe (DList (Key, val) -> DList (Key, val))
-> Maybe (DList (Key, val)) -> Maybe (DList (Key, val))
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> Maybe (DList (Key, val))
try1 a
a)
      (\a
a AesonProps val
rest -> a -> AesonProps val -> AesonProps val
render0 a
a (AesonProps val -> AesonProps val)
-> AesonProps val -> AesonProps val
forall a b. (a -> b) -> a -> b
$! a -> AesonProps val -> AesonProps val
render1 a
a AesonProps val
rest)
      (\a
a -> [(Key, val)] -> [(Key, val)] -> [(Key, val)]
forall a. Semigroup a => a -> a -> a
(<>) ([(Key, val)] -> [(Key, val)] -> [(Key, val)])
-> Either JsonError [(Key, val)]
-> Either JsonError ([(Key, val)] -> [(Key, val)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> Either JsonError [(Key, val)]
check0 a
a Either JsonError ([(Key, val)] -> [(Key, val)])
-> Either JsonError [(Key, val)] -> Either JsonError [(Key, val)]
forall a b.
Either JsonError (a -> b)
-> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> Either JsonError [(Key, val)]
check1 a
a)
  liftA2 :: forall a b c.
(a -> b -> c)
-> ObjPrintor val a a -> ObjPrintor val a b -> ObjPrintor val a c
liftA2 a -> b -> c
f ObjPrintor val a a
p ObjPrintor val a b
q = (a -> b -> c) -> ObjPrintor val a a -> ObjPrintor val a (b -> c)
forall a b. (a -> b) -> ObjPrintor val a a -> ObjPrintor val a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b -> c
f ObjPrintor val a a
p ObjPrintor val a (b -> c)
-> ObjPrintor val a b -> ObjPrintor val a c
forall a b.
ObjPrintor val a (a -> b)
-> ObjPrintor val a a -> ObjPrintor val a b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ObjPrintor val a b
q
  ObjPrintor val a a
p *> :: forall a b.
ObjPrintor val a a -> ObjPrintor val a b -> ObjPrintor val a b
*> ObjPrintor val a b
q = (a -> b -> b) -> ObjPrintor val a a -> ObjPrintor val a (b -> b)
forall a b. (a -> b) -> ObjPrintor val a a -> ObjPrintor val a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
_ b
b -> b
b) ObjPrintor val a a
p ObjPrintor val a (b -> b)
-> ObjPrintor val a b -> ObjPrintor val a b
forall a b.
ObjPrintor val a (a -> b)
-> ObjPrintor val a a -> ObjPrintor val a b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ObjPrintor val a b
q
  ObjPrintor val a a
p <* :: forall a b.
ObjPrintor val a a -> ObjPrintor val a b -> ObjPrintor val a a
<* ObjPrintor val a b
q = (a -> b -> a) -> ObjPrintor val a a -> ObjPrintor val a (b -> a)
forall a b. (a -> b) -> ObjPrintor val a a -> ObjPrintor val a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b -> a
forall a b. a -> b -> a
const ObjPrintor val a a
p ObjPrintor val a (b -> a)
-> ObjPrintor val a b -> ObjPrintor val a a
forall a b.
ObjPrintor val a (a -> b)
-> ObjPrintor val a a -> ObjPrintor val a b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ObjPrintor val a b
q
  {-# INLINE pure #-}
  {-# INLINE (<*>) #-}
  {-# INLINE liftA2 #-}
  {-# INLINE (*>) #-}
  {-# INLINE (<*) #-}
instance Profunctor (ObjPrintor val) where
  dimap :: forall a b c d.
(a -> b) -> (c -> d) -> ObjPrintor val b c -> ObjPrintor val a d
dimap a -> b
f c -> d
_ (ObjPrintor [[Key]]
keys Bool
rest Set String -> Bool
total b -> Maybe (DList (Key, val))
attempt b -> AesonProps val -> AesonProps val
render b -> Either JsonError [(Key, val)]
check) =
    [[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a d
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor [[Key]]
keys Bool
rest Set String -> Bool
total
      (b -> Maybe (DList (Key, val))
attempt (b -> Maybe (DList (Key, val)))
-> (a -> b) -> a -> Maybe (DList (Key, val))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) (\a
a AesonProps val
props -> let b :: b
b = a -> b
f a
a in b
b b -> AesonProps val -> AesonProps val
forall a b. a -> b -> b
`seq` b -> AesonProps val -> AesonProps val
render b
b AesonProps val
props)
      (b -> Either JsonError [(Key, val)]
check (b -> Either JsonError [(Key, val)])
-> (a -> b) -> a -> Either JsonError [(Key, val)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
  q b c
_ #. :: forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> ObjPrintor val a b -> ObjPrintor val a c
#. ObjPrintor val a b
p = ObjPrintor val a b -> ObjPrintor val a c
forall a b. Coercible a b => a -> b
coerce ObjPrintor val a b
p
  ObjPrintor val b c
p .# :: forall a b c (q :: * -> * -> *).
Coercible b a =>
ObjPrintor val b c -> q a b -> ObjPrintor val a c
.# q a b
_ = ObjPrintor val b c -> ObjPrintor val a c
forall a b. Coercible a b => a -> b
coerce ObjPrintor val b c
p
  {-# INLINE dimap #-}
  {-# INLINE (#.) #-}
  {-# INLINE (.#) #-}
instance AesonVal val => Choice (ObjPrintor val) where
  left' :: forall a b c.
ObjPrintor val a b -> ObjPrintor val (Either a c) (Either b c)
left' = Either (ObjPrintor val a b) (ObjPrintor val c c)
-> ObjPrintor val (Either a c) (Either b c)
forall a b c d.
Either (ObjPrintor val a b) (ObjPrintor val c d)
-> ObjPrintor val (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianChoice p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (Either (ObjPrintor val a b) (ObjPrintor val c c)
 -> ObjPrintor val (Either a c) (Either b c))
-> (ObjPrintor val a b
    -> Either (ObjPrintor val a b) (ObjPrintor val c c))
-> ObjPrintor val a b
-> ObjPrintor val (Either a c) (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjPrintor val a b
-> Either (ObjPrintor val a b) (ObjPrintor val c c)
forall a b. a -> Either a b
Left
  right' :: forall a b c.
ObjPrintor val a b -> ObjPrintor val (Either c a) (Either c b)
right' = Either (ObjPrintor val c c) (ObjPrintor val a b)
-> ObjPrintor val (Either c a) (Either c b)
forall a b c d.
Either (ObjPrintor val a b) (ObjPrintor val c d)
-> ObjPrintor val (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianChoice p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (Either (ObjPrintor val c c) (ObjPrintor val a b)
 -> ObjPrintor val (Either c a) (Either c b))
-> (ObjPrintor val a b
    -> Either (ObjPrintor val c c) (ObjPrintor val a b))
-> ObjPrintor val a b
-> ObjPrintor val (Either c a) (Either c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjPrintor val a b
-> Either (ObjPrintor val c c) (ObjPrintor val a b)
forall a b. b -> Either a b
Right
  {-# INLINE left' #-}
  {-# INLINE right' #-}
instance CocartesianMonoidal (ObjPrintor val) where
  zeroP :: ObjPrintor val Void Void
zeroP = [[Key]]
-> Bool
-> (Set String -> Bool)
-> (Void -> Maybe (DList (Key, val)))
-> (Void -> AesonProps val -> AesonProps val)
-> (Void -> Either JsonError [(Key, val)])
-> ObjPrintor val Void Void
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor [] Bool
False (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
True) Void -> Maybe (DList (Key, val))
forall a. Void -> a
absurd Void -> AesonProps val -> AesonProps val
forall a. Void -> a
absurd Void -> Either JsonError [(Key, val)]
forall a. Void -> a
absurd
  ObjPrintor val a b
p >+< :: forall a b c d.
ObjPrintor val a b
-> ObjPrintor val c d -> ObjPrintor val (Either a c) (Either b d)
>+< ObjPrintor val c d
q = [[Key]]
-> Bool
-> (Set String -> Bool)
-> (Either a c -> Maybe (DList (Key, val)))
-> (Either a c -> AesonProps val -> AesonProps val)
-> (Either a c -> Either JsonError [(Key, val)])
-> ObjPrintor val (Either a c) (Either b d)
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor
    (ObjPrintor val a b -> [[Key]]
forall val a b. ObjPrintor val a b -> [[Key]]
objPrintorShapes ObjPrintor val a b
p [[Key]] -> [[Key]] -> [[Key]]
forall a. Semigroup a => a -> a -> a
<> ObjPrintor val c d -> [[Key]]
forall val a b. ObjPrintor val a b -> [[Key]]
objPrintorShapes ObjPrintor val c d
q)
    (ObjPrintor val a b -> Bool
forall val a b. ObjPrintor val a b -> Bool
objPrintorRest ObjPrintor val a b
p Bool -> Bool -> Bool
|| ObjPrintor val c d -> Bool
forall val a b. ObjPrintor val a b -> Bool
objPrintorRest ObjPrintor val c d
q)
    (\Set String
rules -> ObjPrintor val a b -> Set String -> Bool
forall val a b. ObjPrintor val a b -> Set String -> Bool
objPrintorTotal ObjPrintor val a b
p Set String
rules Bool -> Bool -> Bool
&& ObjPrintor val c d -> Set String -> Bool
forall val a b. ObjPrintor val a b -> Set String -> Bool
objPrintorTotal ObjPrintor val c d
q Set String
rules)
    ((a -> Maybe (DList (Key, val)))
-> (c -> Maybe (DList (Key, val)))
-> Either a c
-> Maybe (DList (Key, val))
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ObjPrintor val a b -> a -> Maybe (DList (Key, val))
forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry ObjPrintor val a b
p) (ObjPrintor val c d -> c -> Maybe (DList (Key, val))
forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry ObjPrintor val c d
q))
    (\Either a c
e AesonProps val
props -> case Either a c
e of
      Left a
a -> ObjPrintor val a b -> a -> AesonProps val -> AesonProps val
forall val a b.
ObjPrintor val a b -> a -> AesonProps val -> AesonProps val
objPrintorRender ObjPrintor val a b
p a
a AesonProps val
props
      Right c
b -> ObjPrintor val c d -> c -> AesonProps val -> AesonProps val
forall val a b.
ObjPrintor val a b -> a -> AesonProps val -> AesonProps val
objPrintorRender ObjPrintor val c d
q c
b AesonProps val
props)
    ((a -> Either JsonError [(Key, val)])
-> (c -> Either JsonError [(Key, val)])
-> Either a c
-> Either JsonError [(Key, val)]
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
forall val a b.
ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
objPrintorCheck ObjPrintor val a b
p) (ObjPrintor val c d -> c -> Either JsonError [(Key, val)]
forall val a b.
ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
objPrintorCheck ObjPrintor val c d
q))
  {-# INLINE zeroP #-}
  {-# INLINE (>+<) #-}
instance AesonVal val => CocartesianChoice (ObjPrintor val) where
  alternate :: forall a b c d.
Either (ObjPrintor val a b) (ObjPrintor val c d)
-> ObjPrintor val (Either a c) (Either b d)
alternate = \case
    Left ObjPrintor val a b
p -> ObjPrintor val a b
-> (Either a c -> Maybe (DList (Key, val)))
-> (Either a c -> Either JsonError [(Key, val)])
-> ObjPrintor val (Either a c) (Either b d)
forall val x y a b.
AesonVal val =>
ObjPrintor val x y
-> (a -> Maybe (DList (Key, val)))
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
objTrying ObjPrintor val a b
p
      ((a -> Maybe (DList (Key, val)))
-> (c -> Maybe (DList (Key, val)))
-> Either a c
-> Maybe (DList (Key, val))
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ObjPrintor val a b -> a -> Maybe (DList (Key, val))
forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry ObjPrintor val a b
p) (Maybe (DList (Key, val)) -> c -> Maybe (DList (Key, val))
forall a b. a -> b -> a
const Maybe (DList (Key, val))
forall a. Maybe a
Nothing))
      ((a -> Either JsonError [(Key, val)])
-> (c -> Either JsonError [(Key, val)])
-> Either a c
-> Either JsonError [(Key, val)]
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
forall val a b.
ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
objPrintorCheck ObjPrintor val a b
p) (\c
_ -> Maybe Value -> Either JsonError [(Key, val)]
forall a. Maybe Value -> Either JsonError a
jsonUnexpected Maybe Value
forall a. Maybe a
Nothing))
    Right ObjPrintor val c d
p -> ObjPrintor val c d
-> (Either a c -> Maybe (DList (Key, val)))
-> (Either a c -> Either JsonError [(Key, val)])
-> ObjPrintor val (Either a c) (Either b d)
forall val x y a b.
AesonVal val =>
ObjPrintor val x y
-> (a -> Maybe (DList (Key, val)))
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
objTrying ObjPrintor val c d
p
      ((a -> Maybe (DList (Key, val)))
-> (c -> Maybe (DList (Key, val)))
-> Either a c
-> Maybe (DList (Key, val))
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe (DList (Key, val)) -> a -> Maybe (DList (Key, val))
forall a b. a -> b -> a
const Maybe (DList (Key, val))
forall a. Maybe a
Nothing) (ObjPrintor val c d -> c -> Maybe (DList (Key, val))
forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry ObjPrintor val c d
p))
      ((a -> Either JsonError [(Key, val)])
-> (c -> Either JsonError [(Key, val)])
-> Either a c
-> Either JsonError [(Key, val)]
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\a
_ -> Maybe Value -> Either JsonError [(Key, val)]
forall a. Maybe Value -> Either JsonError a
jsonUnexpected Maybe Value
forall a. Maybe a
Nothing) (ObjPrintor val c d -> c -> Either JsonError [(Key, val)]
forall val a b.
ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
objPrintorCheck ObjPrintor val c d
p))
  {-# INLINE alternate #-}
instance AesonVal val => DisjunctiveMonoid (ObjPrintor val a b) where
  falseP :: ObjPrintor val a b
falseP = [[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor [] Bool
False (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
False) (Maybe (DList (Key, val)) -> a -> Maybe (DList (Key, val))
forall a b. a -> b -> a
const Maybe (DList (Key, val))
forall a. Maybe a
Nothing)
    (\a
_ AesonProps val
props -> AesonProps val
props) (\a
_ -> Maybe Value -> Either JsonError [(Key, val)]
forall a. Maybe Value -> Either JsonError a
jsonUnexpected Maybe Value
forall a. Maybe a
Nothing)
  ObjPrintor val a b
p >|< :: ObjPrintor val a b -> ObjPrintor val a b -> ObjPrintor val a b
>|< ObjPrintor val a b
q = [[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor
    (ObjPrintor val a b -> [[Key]]
forall val a b. ObjPrintor val a b -> [[Key]]
objPrintorShapes ObjPrintor val a b
p [[Key]] -> [[Key]] -> [[Key]]
forall a. Semigroup a => a -> a -> a
<> ObjPrintor val a b -> [[Key]]
forall val a b. ObjPrintor val a b -> [[Key]]
objPrintorShapes ObjPrintor val a b
q)
    (ObjPrintor val a b -> Bool
forall val a b. ObjPrintor val a b -> Bool
objPrintorRest ObjPrintor val a b
p Bool -> Bool -> Bool
|| ObjPrintor val a b -> Bool
forall val a b. ObjPrintor val a b -> Bool
objPrintorRest ObjPrintor val a b
q)
    (\Set String
rules -> ObjPrintor val a b -> Set String -> Bool
forall val a b. ObjPrintor val a b -> Set String -> Bool
objPrintorTotal ObjPrintor val a b
p Set String
rules Bool -> Bool -> Bool
|| ObjPrintor val a b -> Set String -> Bool
forall val a b. ObjPrintor val a b -> Set String -> Bool
objPrintorTotal ObjPrintor val a b
q Set String
rules)
    (\a
a -> ObjPrintor val a b -> a -> Maybe (DList (Key, val))
forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry ObjPrintor val a b
p a
a Maybe (DList (Key, val))
-> Maybe (DList (Key, val)) -> Maybe (DList (Key, val))
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ObjPrintor val a b -> a -> Maybe (DList (Key, val))
forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry ObjPrintor val a b
q a
a)
    (\a
a AesonProps val
props -> AesonProps val
-> (DList (Key, val) -> AesonProps val)
-> Maybe (DList (Key, val))
-> AesonProps val
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
      (ObjPrintor val a b -> a -> AesonProps val -> AesonProps val
forall val a b.
ObjPrintor val a b -> a -> AesonProps val -> AesonProps val
objPrintorRender ObjPrintor val a b
q a
a AesonProps val
props) (DList (Key, val) -> AesonProps val -> AesonProps val
forall val.
AesonVal val =>
DList (Key, val) -> AesonProps val -> AesonProps val
`prependProps` AesonProps val
props) (ObjPrintor val a b -> a -> Maybe (DList (Key, val))
forall val a b. ObjPrintor val a b -> a -> Maybe (DList (Key, val))
objPrintorTry ObjPrintor val a b
p a
a))
    (\a
a -> case ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
forall val a b.
ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
objPrintorCheck ObjPrintor val a b
p a
a of
      Left JsonError
err -> (JsonError -> JsonError)
-> Either JsonError [(Key, val)] -> Either JsonError [(Key, val)]
forall a.
(JsonError -> JsonError)
-> Either JsonError a -> Either JsonError a
onFailure (JsonError -> JsonError -> JsonError
jsonOrElse JsonError
err) (ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
forall val a b.
ObjPrintor val a b -> a -> Either JsonError [(Key, val)]
objPrintorCheck ObjPrintor val a b
q a
a)
      Either JsonError [(Key, val)]
success -> Either JsonError [(Key, val)]
success)

-- | A partial t'ObjPrintor' of another's shapes, rendering what it tries.
objTrying
  :: AesonVal val
  => ObjPrintor val x y
  -> (a -> Maybe (DList (Key, val)))
  -> (a -> Either JsonError [(Key, val)])
  -> ObjPrintor val a b
objTrying :: forall val x y a b.
AesonVal val =>
ObjPrintor val x y
-> (a -> Maybe (DList (Key, val)))
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
objTrying ObjPrintor val x y
p a -> Maybe (DList (Key, val))
attempt = [[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor (ObjPrintor val x y -> [[Key]]
forall val a b. ObjPrintor val a b -> [[Key]]
objPrintorShapes ObjPrintor val x y
p) (ObjPrintor val x y -> Bool
forall val a b. ObjPrintor val a b -> Bool
objPrintorRest ObjPrintor val x y
p)
  (Bool -> Set String -> Bool
forall a b. a -> b -> a
const Bool
False) a -> Maybe (DList (Key, val))
attempt
  (\a
a AesonProps val
props -> DList (Key, val) -> AesonProps val -> AesonProps val
forall val.
AesonVal val =>
DList (Key, val) -> AesonProps val -> AesonProps val
prependProps (DList (Key, val) -> Maybe (DList (Key, val)) -> DList (Key, val)
forall a. a -> Maybe a -> a
fromMaybe DList (Key, val)
forall a. Monoid a => a
mempty (a -> Maybe (DList (Key, val))
attempt a
a)) AesonProps val
props)

-- | Render tried properties before others, encoding their keys.
prependProps
  :: forall val. AesonVal val
  => DList (Key, val) -> AesonProps val -> AesonProps val
prependProps :: forall val.
AesonVal val =>
DList (Key, val) -> AesonProps val -> AesonProps val
prependProps DList (Key, val)
props AesonProps val
rest =
  ((Key, val) -> AesonProps val -> AesonProps val)
-> AesonProps val -> DList (Key, val) -> AesonProps val
forall a b. (a -> b -> b) -> b -> DList a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(Key
key, val
value) -> AesonKey val -> val -> AesonProps val -> AesonProps val
forall val.
AesonVal val =>
AesonKey val -> val -> AesonProps val -> AesonProps val
aesonProp (forall val. AesonVal val => Key -> AesonKey val
aesonKey @val Key
key) val
value) AesonProps val
rest DList (Key, val)
props

instance AesonVal val => JsonObj (JsonPrintor val) (ObjPrintor val) where
  jsonDict :: forall a b c d.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonPrintor val c d -> ObjPrintor val [(a, c)] [(b, d)]
jsonDict forall (k :: * -> * -> *). JsonStr k => k a b
key JsonPrintor val c d
p = [[Key]]
-> Bool
-> (Set String -> Bool)
-> ([(a, c)] -> Maybe (DList (Key, val)))
-> ([(a, c)] -> AesonProps val -> AesonProps val)
-> ([(a, c)] -> Either JsonError [(Key, val)])
-> ObjPrintor val [(a, c)] [(b, d)]
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor [[]] Bool
True
    (\Set String
rules -> JsonPrintor val c d -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val c d
p Set String
rules)
    (([(Key, val)] -> DList (Key, val))
-> Maybe [(Key, val)] -> Maybe (DList (Key, val))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(Key, val)] -> DList (Key, val)
forall a. [a] -> DList a
DList.fromList (Maybe [(Key, val)] -> Maybe (DList (Key, val)))
-> ([(a, c)] -> Maybe [(Key, val)])
-> [(a, c)]
-> Maybe (DList (Key, val))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, c) -> Maybe (Key, val)) -> [(a, c)] -> Maybe [(Key, val)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (\(a
a, c
c) -> (a -> Key
keyOf a
a,) (val -> (Key, val)) -> Maybe val -> Maybe (Key, val)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JsonPrintor val c d -> c -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val c d
p c
c))
    (\[(a, c)]
entries AesonProps val
rest -> ((a, c) -> AesonProps val -> AesonProps val)
-> AesonProps val -> [(a, c)] -> AesonProps val
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr
      (\(a
a, c
c) AesonProps val
props -> AesonKey val
-> JsonPrintor val c d -> c -> AesonProps val -> AesonProps val
forall val a b.
AesonVal val =>
AesonKey val
-> JsonPrintor val a b -> a -> AesonProps val -> AesonProps val
renderProperty (forall val. AesonVal val => Key -> AesonKey val
aesonKey @val (a -> Key
keyOf a
a)) JsonPrintor val c d
p c
c AesonProps val
props)
      AesonProps val
rest [(a, c)]
entries)
    (((a, c) -> Either JsonError (Key, val))
-> [(a, c)] -> Either JsonError [(Key, val)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (\(a
a, c
c) -> let k :: Key
k = a -> Key
keyOf a
a in
      (Key
k,) (val -> (Key, val))
-> Either JsonError val -> Either JsonError (Key, val)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSONPathElement -> Either JsonError val -> Either JsonError val
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Key -> JSONPathElement
Key Key
k) (JsonPrintor val c d -> c -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val c d
p c
c)))
    where
      keyOf :: a -> Key
keyOf = KeyPrintor Key a b -> a -> Key
forall key a b. KeyPrintor key a b -> a -> key
runKeyPrintor KeyPrintor Key a b
forall (k :: * -> * -> *). JsonStr k => k a b
key
  Text
k !: :: forall a b. Text -> JsonPrintor val a b -> ObjPrintor val a b
!: JsonPrintor val a b
p = [[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor [[Key
key]] Bool
False
    (\Set String
rules -> JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
rules)
    ((val -> DList (Key, val)) -> Maybe val -> Maybe (DList (Key, val))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap val -> DList (Key, val)
property (Maybe val -> Maybe (DList (Key, val)))
-> (a -> Maybe val) -> a -> Maybe (DList (Key, val))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p)
    (AesonKey val
-> JsonPrintor val a b -> a -> AesonProps val -> AesonProps val
forall val a b.
AesonVal val =>
AesonKey val
-> JsonPrintor val a b -> a -> AesonProps val -> AesonProps val
renderProperty AesonKey val
encodedKey JsonPrintor val a b
p)
    (Key -> JsonPrintor val a b -> a -> Either JsonError [(Key, val)]
forall val a b.
Key -> JsonPrintor val a b -> a -> Either JsonError [(Key, val)]
printProperty Key
key JsonPrintor val a b
p)
    where
      key :: Key
key = Text -> Key
Key.fromText Text
k
      encodedKey :: AesonKey val
encodedKey = forall val. AesonVal val => Key -> AesonKey val
aesonKey @val Key
key
      property :: val -> DList (Key, val)
property val
printed = (Key, val) -> DList (Key, val)
forall a. a -> DList a
DList.singleton (Key
key, val
printed)
  Text
k ?: :: forall a b.
Text -> JsonPrintor val a b -> ObjPrintor val (Maybe a) (Maybe b)
?: JsonPrintor val a b
p = [[Key]]
-> Bool
-> (Set String -> Bool)
-> (Maybe a -> Maybe (DList (Key, val)))
-> (Maybe a -> AesonProps val -> AesonProps val)
-> (Maybe a -> Either JsonError [(Key, val)])
-> ObjPrintor val (Maybe a) (Maybe b)
forall val a b.
[[Key]]
-> Bool
-> (Set String -> Bool)
-> (a -> Maybe (DList (Key, val)))
-> (a -> AesonProps val -> AesonProps val)
-> (a -> Either JsonError [(Key, val)])
-> ObjPrintor val a b
ObjPrintor [[Key
key]] Bool
False
    (\Set String
rules -> JsonPrintor val a b -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val a b
p Set String
rules)
    (Maybe (DList (Key, val))
-> (a -> Maybe (DList (Key, val)))
-> Maybe a
-> Maybe (DList (Key, val))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (DList (Key, val) -> Maybe (DList (Key, val))
forall a. a -> Maybe a
Just DList (Key, val)
forall a. Monoid a => a
mempty) ((val -> DList (Key, val)) -> Maybe val -> Maybe (DList (Key, val))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap val -> DList (Key, val)
property (Maybe val -> Maybe (DList (Key, val)))
-> (a -> Maybe val) -> a -> Maybe (DList (Key, val))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonPrintor val a b -> a -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val a b
p))
    (\Maybe a
ma AesonProps val
rest -> AesonProps val
-> (a -> AesonProps val) -> Maybe a -> AesonProps val
forall b a. b -> (a -> b) -> Maybe a -> b
maybe AesonProps val
rest (\a
a -> AesonKey val
-> JsonPrintor val a b -> a -> AesonProps val -> AesonProps val
forall val a b.
AesonVal val =>
AesonKey val
-> JsonPrintor val a b -> a -> AesonProps val -> AesonProps val
renderProperty AesonKey val
encodedKey JsonPrintor val a b
p a
a AesonProps val
rest) Maybe a
ma)
    (Either JsonError [(Key, val)]
-> (a -> Either JsonError [(Key, val)])
-> Maybe a
-> Either JsonError [(Key, val)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([(Key, val)] -> Either JsonError [(Key, val)]
forall a b. b -> Either a b
Right []) (Key -> JsonPrintor val a b -> a -> Either JsonError [(Key, val)]
forall val a b.
Key -> JsonPrintor val a b -> a -> Either JsonError [(Key, val)]
printProperty Key
key JsonPrintor val a b
p))
    where
      key :: Key
key = Text -> Key
Key.fromText Text
k
      encodedKey :: AesonKey val
encodedKey = forall val. AesonVal val => Key -> AesonKey val
aesonKey @val Key
key
      property :: val -> DList (Key, val)
property val
printed = (Key, val) -> DList (Key, val)
forall a. a -> DList a
DList.singleton (Key
key, val
printed)
  {-# INLINE jsonDict #-}
  {-# INLINE (!:) #-}
  {-# INLINE (?:) #-}

{- | Print an array of elements. Outside the `JsonVal` instance, so that
the instance's specializations needn't break their recursion through
`jsonTuple` itself, which would stop it from inlining.
-}
printTuple
  :: forall val a b. AesonVal val
  => (forall q. JsonTup (JsonPrintor val) q => q a b) -> JsonPrintor val a b
printTuple :: forall val a b.
AesonVal val =>
(forall (q :: * -> * -> *). JsonTup (JsonPrintor val) q => q a b)
-> JsonPrintor val a b
printTuple forall (q :: * -> * -> *). JsonTup (JsonPrintor val) q => q a b
tup = case forall (q :: * -> * -> *). JsonTup (JsonPrintor val) q => q a b
tup @(TupPrintor val) of
  -- The grammar's printor, instantiated once, rather than in each field.
  TupPrintor Set String -> Bool
total a -> Maybe (DList val)
attempt a -> AesonElems val -> AesonElems val
render a -> Elements val
check Maybe (a -> val)
_ -> (Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
    (\Set String
rules -> Set String -> Bool
total Set String
rules)
    ((DList val -> val) -> Maybe (DList val) -> Maybe val
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((val -> val) -> [val] -> val
forall val a. AesonVal val => (a -> val) -> [a] -> val
forall a. (a -> val) -> [a] -> val
aesonList val -> val
forall a. a -> a
id ([val] -> val) -> (DList val -> [val]) -> DList val -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList val -> [val]
forall a. DList a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList) (Maybe (DList val) -> Maybe val)
-> (a -> Maybe (DList val)) -> a -> Maybe val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe (DList val)
attempt)
    (\a
a -> AesonElems val -> val
forall val. AesonVal val => AesonElems val -> val
aesonElems (a -> AesonElems val -> AesonElems val
render a
a (forall val. AesonVal val => AesonElems val
aesonElemsEmpty @val)))
    (\a
a -> case a -> Elements val
check a
a of
      Elements Either JsonError (Int, DList val)
printed -> (val -> val) -> [val] -> val
forall val a. AesonVal val => (a -> val) -> [a] -> val
forall a. (a -> val) -> [a] -> val
aesonList val -> val
forall a. a -> a
id ([val] -> val)
-> ((Int, DList val) -> [val]) -> (Int, DList val) -> val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList val -> [val]
forall a. DList a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (DList val -> [val])
-> ((Int, DList val) -> DList val) -> (Int, DList val) -> [val]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, DList val) -> DList val
forall a b. (a, b) -> b
snd ((Int, DList val) -> val)
-> Either JsonError (Int, DList val) -> Either JsonError val
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Either JsonError (Int, DList val)
printed)
    Maybe ([a] -> val)
forall a. Maybe a
Nothing
{-# INLINE printTuple #-}

-- | Print the properties of a map, whose keys are distinct, as an object.
printDistinct
  :: AesonVal val
  => (forall r. (a -> c -> r -> r) -> r -> m -> r)
  -> (forall k. JsonStr k => k a b)
  -> JsonPrintor val c d -> JsonPrintor val m n
printDistinct :: forall val a c m b d n.
AesonVal val =>
(forall r. (a -> c -> r -> r) -> r -> m -> r)
-> (forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonPrintor val c d
-> JsonPrintor val m n
printDistinct forall r. (a -> c -> r -> r) -> r -> m -> r
fold forall (k :: * -> * -> *). JsonStr k => k a b
key JsonPrintor val c d
p = (Set String -> Bool)
-> (m -> Maybe val)
-> (m -> val)
-> (m -> Either JsonError val)
-> Maybe ([m] -> val)
-> JsonPrintor val m n
forall val a b.
(Set String -> Bool)
-> (a -> Maybe val)
-> (a -> val)
-> (a -> Either JsonError val)
-> Maybe ([a] -> val)
-> JsonPrintor val a b
JsonPrintor
  (\Set String
rules -> JsonPrintor val c d -> Set String -> Bool
forall val a b. JsonPrintor val a b -> Set String -> Bool
printorTotal JsonPrintor val c d
p Set String
rules)
  (([(Key, val)] -> val) -> Maybe [(Key, val)] -> Maybe val
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(Key, val)] -> val
forall val. AesonVal val => [(Key, val)] -> val
aesonObject (Maybe [(Key, val)] -> Maybe val)
-> (m -> Maybe [(Key, val)]) -> m -> Maybe val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> c -> Maybe [(Key, val)] -> Maybe [(Key, val)])
-> Maybe [(Key, val)] -> m -> Maybe [(Key, val)]
forall r. (a -> c -> r -> r) -> r -> m -> r
fold a -> c -> Maybe [(Key, val)] -> Maybe [(Key, val)]
attempt ([(Key, val)] -> Maybe [(Key, val)]
forall a. a -> Maybe a
Just []))
  ((forall (k :: * -> * -> *). JsonStr k => k a b)
-> (forall r. (a -> c -> r -> r) -> r -> m -> r)
-> (c -> val)
-> m
-> val
forall val a b c m.
AesonVal val =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> (forall r. (a -> c -> r -> r) -> r -> m -> r)
-> (c -> val)
-> m
-> val
forall a b c m.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> (forall r. (a -> c -> r -> r) -> r -> m -> r)
-> (c -> val)
-> m
-> val
aesonMap k a b
forall (k :: * -> * -> *). JsonStr k => k a b
key (a -> c -> r -> r) -> r -> m -> r
forall r. (a -> c -> r -> r) -> r -> m -> r
fold (JsonPrintor val c d -> c -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val c d
p))
  (([(Key, val)] -> val)
-> Either JsonError [(Key, val)] -> Either JsonError val
forall a b. (a -> b) -> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(Key, val)] -> val
forall val. AesonVal val => [(Key, val)] -> val
aesonObject (Either JsonError [(Key, val)] -> Either JsonError val)
-> (m -> Either JsonError [(Key, val)])
-> m
-> Either JsonError val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
 -> c
 -> Either JsonError [(Key, val)]
 -> Either JsonError [(Key, val)])
-> Either JsonError [(Key, val)]
-> m
-> Either JsonError [(Key, val)]
forall r. (a -> c -> r -> r) -> r -> m -> r
fold a
-> c
-> Either JsonError [(Key, val)]
-> Either JsonError [(Key, val)]
check ([(Key, val)] -> Either JsonError [(Key, val)]
forall a b. b -> Either a b
Right []))
  Maybe ([m] -> val)
forall a. Maybe a
Nothing
  where
    keyOf :: a -> Key
keyOf = KeyPrintor Key a b -> a -> Key
forall key a b. KeyPrintor key a b -> a -> key
runKeyPrintor KeyPrintor Key a b
forall (k :: * -> * -> *). JsonStr k => k a b
key
    attempt :: a -> c -> Maybe [(Key, val)] -> Maybe [(Key, val)]
attempt a
a c
c Maybe [(Key, val)]
rest = (:) ((Key, val) -> [(Key, val)] -> [(Key, val)])
-> (val -> (Key, val)) -> val -> [(Key, val)] -> [(Key, val)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Key
keyOf a
a,) (val -> [(Key, val)] -> [(Key, val)])
-> Maybe val -> Maybe ([(Key, val)] -> [(Key, val)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JsonPrintor val c d -> c -> Maybe val
forall val a b. JsonPrintor val a b -> a -> Maybe val
printorTry JsonPrintor val c d
p c
c Maybe ([(Key, val)] -> [(Key, val)])
-> Maybe [(Key, val)] -> Maybe [(Key, val)]
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe [(Key, val)]
rest
    check :: a
-> c
-> Either JsonError [(Key, val)]
-> Either JsonError [(Key, val)]
check a
a c
c Either JsonError [(Key, val)]
rest = (:) ((Key, val) -> [(Key, val)] -> [(Key, val)])
-> (val -> (Key, val)) -> val -> [(Key, val)] -> [(Key, val)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key
k,) (val -> [(Key, val)] -> [(Key, val)])
-> Either JsonError val
-> Either JsonError ([(Key, val)] -> [(Key, val)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSONPathElement -> Either JsonError val -> Either JsonError val
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Key -> JSONPathElement
Key Key
k) (JsonPrintor val c d -> c -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val c d
p c
c) Either JsonError ([(Key, val)] -> [(Key, val)])
-> Either JsonError [(Key, val)] -> Either JsonError [(Key, val)]
forall a b.
Either JsonError (a -> b)
-> Either JsonError a -> Either JsonError b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Either JsonError [(Key, val)]
rest
      where
        k :: Key
k = a -> Key
keyOf a
a

renderProperty
  :: AesonVal val
  => AesonKey val -> JsonPrintor val a b -> a -> AesonProps val
  -> AesonProps val
renderProperty :: forall val a b.
AesonVal val =>
AesonKey val
-> JsonPrintor val a b -> a -> AesonProps val -> AesonProps val
renderProperty AesonKey val
key JsonPrintor val a b
p a
a AesonProps val
rest =
  let printed :: val
printed = JsonPrintor val a b -> a -> val
forall val a b. JsonPrintor val a b -> a -> val
printorRender JsonPrintor val a b
p a
a in val
printed val -> AesonProps val -> AesonProps val
forall a b. a -> b -> b
`seq` AesonKey val -> val -> AesonProps val -> AesonProps val
forall val.
AesonVal val =>
AesonKey val -> val -> AesonProps val -> AesonProps val
aesonProp AesonKey val
key val
printed AesonProps val
rest
{-# INLINE renderProperty #-}

printProperty
  :: Key -> JsonPrintor val a b -> a -> Either JsonError [(Key, val)]
printProperty :: forall val a b.
Key -> JsonPrintor val a b -> a -> Either JsonError [(Key, val)]
printProperty Key
key JsonPrintor val a b
p a
a =
  (\val
printed -> [(Key
key, val
printed)]) (val -> [(Key, val)])
-> Either JsonError val -> Either JsonError [(Key, val)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSONPathElement -> Either JsonError val -> Either JsonError val
forall a.
JSONPathElement -> Either JsonError a -> Either JsonError a
jsonAt (Key -> JSONPathElement
Key Key
key) (JsonPrintor val a b -> a -> Either JsonError val
forall val a b. JsonPrintor val a b -> a -> Either JsonError val
printorCheck JsonPrintor val a b
p a
a)

-- Types of JSON --

{- | The type of JSON values, which a grammar describes,
of rules by their names, in a t'Bnf', as `jsonType` describes them.
It's the union of its alternatives, so that `falseP` is the type of
no values.
-}
data JsonType
  = JsonRule String -- ^ the type of a rule, by its name
  | JsonNull -- ^ @null@
  | JsonBoolean -- ^ @true@ or @false@
  | JsonNumber -- ^ numbers
  | JsonString -- ^ strings
  | JsonLiteral Text -- ^ a string
  | JsonSubtype JsonType -- ^ some values of a type
  | JsonArray JsonElements -- ^ arrays of elements
  | JsonObject [JsonProperty] -- ^ objects of properties
  | JsonUnion [JsonType] -- ^ values of any of some types
  deriving stock (JsonType -> JsonType -> Bool
(JsonType -> JsonType -> Bool)
-> (JsonType -> JsonType -> Bool) -> Eq JsonType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JsonType -> JsonType -> Bool
== :: JsonType -> JsonType -> Bool
$c/= :: JsonType -> JsonType -> Bool
/= :: JsonType -> JsonType -> Bool
Eq, Eq JsonType
Eq JsonType =>
(JsonType -> JsonType -> Ordering)
-> (JsonType -> JsonType -> Bool)
-> (JsonType -> JsonType -> Bool)
-> (JsonType -> JsonType -> Bool)
-> (JsonType -> JsonType -> Bool)
-> (JsonType -> JsonType -> JsonType)
-> (JsonType -> JsonType -> JsonType)
-> Ord JsonType
JsonType -> JsonType -> Bool
JsonType -> JsonType -> Ordering
JsonType -> JsonType -> JsonType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: JsonType -> JsonType -> Ordering
compare :: JsonType -> JsonType -> Ordering
$c< :: JsonType -> JsonType -> Bool
< :: JsonType -> JsonType -> Bool
$c<= :: JsonType -> JsonType -> Bool
<= :: JsonType -> JsonType -> Bool
$c> :: JsonType -> JsonType -> Bool
> :: JsonType -> JsonType -> Bool
$c>= :: JsonType -> JsonType -> Bool
>= :: JsonType -> JsonType -> Bool
$cmax :: JsonType -> JsonType -> JsonType
max :: JsonType -> JsonType -> JsonType
$cmin :: JsonType -> JsonType -> JsonType
min :: JsonType -> JsonType -> JsonType
Ord, Int -> JsonType -> ShowS
[JsonType] -> ShowS
JsonType -> String
(Int -> JsonType -> ShowS)
-> (JsonType -> String) -> ([JsonType] -> ShowS) -> Show JsonType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JsonType -> ShowS
showsPrec :: Int -> JsonType -> ShowS
$cshow :: JsonType -> String
show :: JsonType -> String
$cshowList :: [JsonType] -> ShowS
showList :: [JsonType] -> ShowS
Show, ReadPrec [JsonType]
ReadPrec JsonType
Int -> ReadS JsonType
ReadS [JsonType]
(Int -> ReadS JsonType)
-> ReadS [JsonType]
-> ReadPrec JsonType
-> ReadPrec [JsonType]
-> Read JsonType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS JsonType
readsPrec :: Int -> ReadS JsonType
$creadList :: ReadS [JsonType]
readList :: ReadS [JsonType]
$creadPrec :: ReadPrec JsonType
readPrec :: ReadPrec JsonType
$creadListPrec :: ReadPrec [JsonType]
readListPrec :: ReadPrec [JsonType]
Read)

-- | The `JsonElements` of a `JsonArray` are the `KleeneStarAlgebra` generated by `JsonType`.
data JsonElements
  = JsonElement JsonType -- ^ an element
  | JsonElements JsonElements -- ^ elements, repeated any number of times
  | JsonElements1 JsonElements -- ^ elements, repeated at least once
  | JsonElementsOpt JsonElements -- ^ elements, or none
  | JsonElementsTup [JsonElements] -- ^ elements, in sequence
  | JsonElementsAlt [JsonElements] -- ^ elements, any of some alternatives
  deriving stock (JsonElements -> JsonElements -> Bool
(JsonElements -> JsonElements -> Bool)
-> (JsonElements -> JsonElements -> Bool) -> Eq JsonElements
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JsonElements -> JsonElements -> Bool
== :: JsonElements -> JsonElements -> Bool
$c/= :: JsonElements -> JsonElements -> Bool
/= :: JsonElements -> JsonElements -> Bool
Eq, Eq JsonElements
Eq JsonElements =>
(JsonElements -> JsonElements -> Ordering)
-> (JsonElements -> JsonElements -> Bool)
-> (JsonElements -> JsonElements -> Bool)
-> (JsonElements -> JsonElements -> Bool)
-> (JsonElements -> JsonElements -> Bool)
-> (JsonElements -> JsonElements -> JsonElements)
-> (JsonElements -> JsonElements -> JsonElements)
-> Ord JsonElements
JsonElements -> JsonElements -> Bool
JsonElements -> JsonElements -> Ordering
JsonElements -> JsonElements -> JsonElements
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: JsonElements -> JsonElements -> Ordering
compare :: JsonElements -> JsonElements -> Ordering
$c< :: JsonElements -> JsonElements -> Bool
< :: JsonElements -> JsonElements -> Bool
$c<= :: JsonElements -> JsonElements -> Bool
<= :: JsonElements -> JsonElements -> Bool
$c> :: JsonElements -> JsonElements -> Bool
> :: JsonElements -> JsonElements -> Bool
$c>= :: JsonElements -> JsonElements -> Bool
>= :: JsonElements -> JsonElements -> Bool
$cmax :: JsonElements -> JsonElements -> JsonElements
max :: JsonElements -> JsonElements -> JsonElements
$cmin :: JsonElements -> JsonElements -> JsonElements
min :: JsonElements -> JsonElements -> JsonElements
Ord, Int -> JsonElements -> ShowS
[JsonElements] -> ShowS
JsonElements -> String
(Int -> JsonElements -> ShowS)
-> (JsonElements -> String)
-> ([JsonElements] -> ShowS)
-> Show JsonElements
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JsonElements -> ShowS
showsPrec :: Int -> JsonElements -> ShowS
$cshow :: JsonElements -> String
show :: JsonElements -> String
$cshowList :: [JsonElements] -> ShowS
showList :: [JsonElements] -> ShowS
Show, ReadPrec [JsonElements]
ReadPrec JsonElements
Int -> ReadS JsonElements
ReadS [JsonElements]
(Int -> ReadS JsonElements)
-> ReadS [JsonElements]
-> ReadPrec JsonElements
-> ReadPrec [JsonElements]
-> Read JsonElements
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS JsonElements
readsPrec :: Int -> ReadS JsonElements
$creadList :: ReadS [JsonElements]
readList :: ReadS [JsonElements]
$creadPrec :: ReadPrec JsonElements
readPrec :: ReadPrec JsonElements
$creadListPrec :: ReadPrec [JsonElements]
readListPrec :: ReadPrec [JsonElements]
Read)

-- | A property of a `JsonObject`.
data JsonProperty
  = JsonProperty Text Bool JsonType
  -- ^ a property, by its key, which is optional or not
  | JsonDict JsonType JsonType
  -- ^ the rest of the properties, by the types of their keys & values
  deriving stock (JsonProperty -> JsonProperty -> Bool
(JsonProperty -> JsonProperty -> Bool)
-> (JsonProperty -> JsonProperty -> Bool) -> Eq JsonProperty
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JsonProperty -> JsonProperty -> Bool
== :: JsonProperty -> JsonProperty -> Bool
$c/= :: JsonProperty -> JsonProperty -> Bool
/= :: JsonProperty -> JsonProperty -> Bool
Eq, Eq JsonProperty
Eq JsonProperty =>
(JsonProperty -> JsonProperty -> Ordering)
-> (JsonProperty -> JsonProperty -> Bool)
-> (JsonProperty -> JsonProperty -> Bool)
-> (JsonProperty -> JsonProperty -> Bool)
-> (JsonProperty -> JsonProperty -> Bool)
-> (JsonProperty -> JsonProperty -> JsonProperty)
-> (JsonProperty -> JsonProperty -> JsonProperty)
-> Ord JsonProperty
JsonProperty -> JsonProperty -> Bool
JsonProperty -> JsonProperty -> Ordering
JsonProperty -> JsonProperty -> JsonProperty
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: JsonProperty -> JsonProperty -> Ordering
compare :: JsonProperty -> JsonProperty -> Ordering
$c< :: JsonProperty -> JsonProperty -> Bool
< :: JsonProperty -> JsonProperty -> Bool
$c<= :: JsonProperty -> JsonProperty -> Bool
<= :: JsonProperty -> JsonProperty -> Bool
$c> :: JsonProperty -> JsonProperty -> Bool
> :: JsonProperty -> JsonProperty -> Bool
$c>= :: JsonProperty -> JsonProperty -> Bool
>= :: JsonProperty -> JsonProperty -> Bool
$cmax :: JsonProperty -> JsonProperty -> JsonProperty
max :: JsonProperty -> JsonProperty -> JsonProperty
$cmin :: JsonProperty -> JsonProperty -> JsonProperty
min :: JsonProperty -> JsonProperty -> JsonProperty
Ord, Int -> JsonProperty -> ShowS
[JsonProperty] -> ShowS
JsonProperty -> String
(Int -> JsonProperty -> ShowS)
-> (JsonProperty -> String)
-> ([JsonProperty] -> ShowS)
-> Show JsonProperty
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JsonProperty -> ShowS
showsPrec :: Int -> JsonProperty -> ShowS
$cshow :: JsonProperty -> String
show :: JsonProperty -> String
$cshowList :: [JsonProperty] -> ShowS
showList :: [JsonProperty] -> ShowS
Show, ReadPrec [JsonProperty]
ReadPrec JsonProperty
Int -> ReadS JsonProperty
ReadS [JsonProperty]
(Int -> ReadS JsonProperty)
-> ReadS [JsonProperty]
-> ReadPrec JsonProperty
-> ReadPrec [JsonProperty]
-> Read JsonProperty
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS JsonProperty
readsPrec :: Int -> ReadS JsonProperty
$creadList :: ReadS [JsonProperty]
readList :: ReadS [JsonProperty]
$creadPrec :: ReadPrec JsonProperty
readPrec :: ReadPrec JsonProperty
$creadListPrec :: ReadPrec [JsonProperty]
readListPrec :: ReadPrec [JsonProperty]
Read)

instance DisjunctiveMonoid JsonType where
  falseP :: JsonType
falseP = [JsonType] -> JsonType
JsonUnion []
  JsonType
a >|< :: JsonType -> JsonType -> JsonType
>|< JsonType
b = [JsonType] -> JsonType
jsonUnion [JsonType
a, JsonType
b]

-- | A union, of the alternatives of some types.
jsonUnion :: [JsonType] -> JsonType
jsonUnion :: [JsonType] -> JsonType
jsonUnion [JsonType]
types = case [JsonType] -> [JsonType]
forall a. Eq a => [a] -> [a]
nub ((JsonType -> [JsonType]) -> [JsonType] -> [JsonType]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap JsonType -> [JsonType]
flatten [JsonType]
types) of
  [JsonType
t] -> JsonType
t
  [JsonType]
ts -> [JsonType] -> JsonType
JsonUnion [JsonType]
ts
  where
    flatten :: JsonType -> [JsonType]
flatten = \case
      JsonUnion [JsonType]
ts -> [JsonType]
ts
      JsonType
t -> [JsonType
t]

jsonSubtype :: JsonType -> JsonType
jsonSubtype :: JsonType -> JsonType
jsonSubtype = \case
  JsonUnion [] -> JsonType
forall a. DisjunctiveMonoid a => a
falseP
  t :: JsonType
t@(JsonSubtype JsonType
_) -> JsonType
t
  JsonType
t -> JsonType -> JsonType
JsonSubtype JsonType
t

instance Semigroup JsonElements where
  JsonElementsAlt [] <> :: JsonElements -> JsonElements -> JsonElements
<> JsonElements
_ = JsonElements
forall a. DisjunctiveMonoid a => a
falseP
  JsonElements
_ <> JsonElementsAlt [] = JsonElements
forall a. DisjunctiveMonoid a => a
falseP
  JsonElements JsonElements
a <> JsonElements
b | JsonElements
a JsonElements -> JsonElements -> Bool
forall a. Eq a => a -> a -> Bool
== JsonElements
b = JsonElements -> JsonElements
forall k. KleeneStarAlgebra k => k -> k
plusK JsonElements
a
  JsonElements
a <> JsonElements JsonElements
b | JsonElements
a JsonElements -> JsonElements -> Bool
forall a. Eq a => a -> a -> Bool
== JsonElements
b = JsonElements -> JsonElements
forall k. KleeneStarAlgebra k => k -> k
plusK JsonElements
a
  JsonElements
a <> JsonElements
b = case (JsonElements -> Maybe [JsonElements]
flatten JsonElements
a, JsonElements -> Maybe [JsonElements]
flatten JsonElements
b) of
    (Just [JsonElements]
as, Just [JsonElements]
bs) -> case [JsonElements]
as [JsonElements] -> [JsonElements] -> [JsonElements]
forall a. Semigroup a => a -> a -> a
<> [JsonElements]
bs of
      [JsonElements
els] -> JsonElements
els
      [JsonElements]
els -> [JsonElements] -> JsonElements
JsonElementsTup [JsonElements]
els
    (Maybe [JsonElements], Maybe [JsonElements])
_ -> JsonElements
forall a. DisjunctiveMonoid a => a
falseP
    where
      -- Sequenced elements, or none, for no sequence of elements.
      flatten :: JsonElements -> Maybe [JsonElements]
flatten = \case
        JsonElementsAlt [] -> Maybe [JsonElements]
forall a. Maybe a
Nothing
        JsonElementsTup [JsonElements]
els -> [JsonElements] -> Maybe [JsonElements]
forall a. a -> Maybe a
Just [JsonElements]
els
        JsonElements
els -> [JsonElements] -> Maybe [JsonElements]
forall a. a -> Maybe a
Just [JsonElements
els]
instance Monoid JsonElements where
  mempty :: JsonElements
mempty = [JsonElements] -> JsonElements
JsonElementsTup []
instance DisjunctiveMonoid JsonElements where
  falseP :: JsonElements
falseP = [JsonElements] -> JsonElements
JsonElementsAlt []
  JsonElements
a >|< :: JsonElements -> JsonElements -> JsonElements
>|< JsonElements
b | JsonElements
a JsonElements -> JsonElements -> Bool
forall a. Eq a => a -> a -> Bool
== JsonElements
b = JsonElements
a
  JsonElementsAlt [] >|< JsonElements
b = JsonElements
b
  JsonElements
a >|< JsonElementsAlt [] = JsonElements
a
  JsonElements1 JsonElements
a >|< JsonElementsTup [] = JsonElements -> JsonElements
forall k. KleeneStarAlgebra k => k -> k
starK JsonElements
a
  JsonElementsTup [] >|< JsonElements1 JsonElements
b = JsonElements -> JsonElements
forall k. KleeneStarAlgebra k => k -> k
starK JsonElements
b
  JsonElements
a >|< JsonElementsTup [] = JsonElements -> JsonElements
forall k. KleeneStarAlgebra k => k -> k
optK JsonElements
a
  JsonElementsTup [] >|< JsonElements
b = JsonElements -> JsonElements
forall k. KleeneStarAlgebra k => k -> k
optK JsonElements
b
  JsonElements
a >|< JsonElements
b = case [JsonElements] -> [JsonElements]
forall a. Eq a => [a] -> [a]
nub (JsonElements -> [JsonElements]
flatten JsonElements
a [JsonElements] -> [JsonElements] -> [JsonElements]
forall a. Semigroup a => a -> a -> a
<> JsonElements -> [JsonElements]
flatten JsonElements
b) of
    [JsonElements
els] -> JsonElements
els
    [JsonElements]
alts -> [JsonElements] -> JsonElements
JsonElementsAlt [JsonElements]
alts
    where
      flatten :: JsonElements -> [JsonElements]
flatten = \case
        JsonElementsAlt [JsonElements]
alts -> [JsonElements]
alts
        JsonElements
els -> [JsonElements
els]
instance KleeneStarAlgebra JsonElements where
  starK :: JsonElements -> JsonElements
starK = \case
    JsonElementsAlt [] -> JsonElements
forall a. Monoid a => a
mempty
    JsonElementsTup [] -> JsonElements
forall a. Monoid a => a
mempty
    JsonElements
els -> JsonElements -> JsonElements
JsonElements JsonElements
els
  plusK :: JsonElements -> JsonElements
plusK = \case
    JsonElementsAlt [] -> JsonElements
forall a. DisjunctiveMonoid a => a
falseP
    JsonElementsTup [] -> JsonElements
forall a. Monoid a => a
mempty
    JsonElements
els -> JsonElements -> JsonElements
JsonElements1 JsonElements
els
  optK :: JsonElements -> JsonElements
optK = \case
    JsonElementsAlt [] -> JsonElements
forall a. Monoid a => a
mempty
    JsonElementsTup [] -> JsonElements
forall a. Monoid a => a
mempty
    JsonElements1 JsonElements
els -> JsonElements -> JsonElements
forall k. KleeneStarAlgebra k => k -> k
starK JsonElements
els
    els :: JsonElements
els@(JsonElements JsonElements
_) -> JsonElements
els
    els :: JsonElements
els@(JsonElementsOpt JsonElements
_) -> JsonElements
els
    JsonElements
els -> JsonElements -> JsonElements
JsonElementsOpt JsonElements
els

{- | The type of the JSON of a type, by its rules, which are named
by their qualified names.

>>> jsonType (type Bool)
Bnf {startBnf = JsonBoolean, rulesBnf = fromList []}
>>> jsonType (Maybe Ordering)
Bnf {startBnf = JsonUnion [JsonNull,JsonRule "GHC.Types.Ordering"], rulesBnf = fromList [("GHC.Types.Ordering",JsonUnion [JsonLiteral "LT",JsonLiteral "EQ",JsonLiteral "GT"])]}
-}
jsonType :: forall (a :: Type) -> Json a => Bnf JsonType
jsonType :: forall a -> Json a => Bnf JsonType
jsonType a = JsonType -> Set (String, JsonType) -> Bnf JsonType
forall rule. rule -> Set (String, rule) -> Bnf rule
Bnf JsonType
start ([(String, JsonType)] -> Set (String, JsonType)
forall a. Ord a => [a] -> Set a
Set.fromList (Map String JsonType -> [(String, JsonType)]
forall k a. Map k a -> [(k, a)]
Map.toList Map String JsonType
rules))
  where
    JsonTypor Typing JsonType
typed = forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a @JsonTypor
    (JsonType
start, Map String JsonType
rules) = State (Map String JsonType) JsonType
-> Map String JsonType -> (JsonType, Map String JsonType)
forall s a. State s a -> s -> (a, s)
runState (Typing JsonType
-> Map String Bool -> State (Map String JsonType) JsonType
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT Typing JsonType
typed Map String Bool
forall k a. Map k a
Map.empty) Map String JsonType
forall k a. Map k a
Map.empty

{- | Type the JSON of types, in TypeScript, as a declaration of each rule
of their types, named by its unqualified name, or else its qualified name,
which `jsonTsPut` puts.

>>> jsonTsDeclarations (type '[Maybe Ordering])
[TypeAliasDeclaration [ExportKeyword] "Ordering" [] (UnionType [LiteralType (TextLiteral "LT"),LiteralType (TextLiteral "EQ"),LiteralType (TextLiteral "GT")])]
-}
jsonTsDeclarations :: forall (as :: [Type]) -> All Json as => [TsDeclaration]
jsonTsDeclarations :: forall (as :: [*]) -> All Json as => [TsDeclaration]
jsonTsDeclarations as = [Bnf JsonType] -> [TsDeclaration]
tsDeclarations ([Bnf JsonType] -> [TsDeclaration])
-> [Bnf JsonType] -> [TsDeclaration]
forall a b. (a -> b) -> a -> b
$ NP (K (Bnf JsonType)) as -> CollapseTo NP (Bnf JsonType)
forall (xs :: [*]) a.
SListIN NP xs =>
NP (K a) xs -> CollapseTo NP a
forall k l (h :: (k -> *) -> l -> *) (xs :: l) a.
(HCollapse h, SListIN h xs) =>
h (K a) xs -> CollapseTo h a
hcollapse
  (Proxy Json
-> (forall a. Json a => K (Bnf JsonType) a)
-> NP (K (Bnf JsonType)) as
forall k l (h :: (k -> *) -> l -> *) (c :: k -> Constraint)
       (xs :: l) (proxy :: (k -> Constraint) -> *) (f :: k -> *).
(HPure h, AllN h c xs) =>
proxy c -> (forall (a :: k). c a => f a) -> h f xs
forall (c :: * -> Constraint) (xs :: [*])
       (proxy :: (* -> Constraint) -> *) (f :: * -> *).
AllN NP c xs =>
proxy c -> (forall a. c a => f a) -> NP f xs
hcpure (forall {k} (t :: k). Proxy t
forall (t :: * -> Constraint). Proxy t
Proxy @Json) K (Bnf JsonType) a
forall a. Json a => K (Bnf JsonType) a
root :: NP (K (Bnf JsonType)) as)
  where
    root :: forall a. Json a => K (Bnf JsonType) a
    root :: forall a. Json a => K (Bnf JsonType) a
root = Bnf JsonType -> K (Bnf JsonType) a
forall k a (b :: k). a -> K a b
K (Bnf JsonType
Json a => Bnf JsonType
forall a -> Json a => Bnf JsonType
jsonType (type a))

{- | Put the TypeScript declarations of the JSON of types to a handle,
like a @.ts@ file.

>>> jsonTsPut (type '[Maybe Ordering]) stdout
export type Ordering = "LT" | "EQ" | "GT";
-}
jsonTsPut :: forall (as :: [Type]) -> All Json as => Handle -> IO ()
jsonTsPut :: forall (as :: [*]) -> All Json as => Handle -> IO ()
jsonTsPut as Handle
handle = case (ParsecState (Seq TsToken) [TsDeclaration] -> Maybe [TsDeclaration]
forall s a. ParsecState s a -> Maybe a
parsecResult ParsecState (Seq TsToken) [TsDeclaration]
printed, ParsecState (Seq Char) [TsToken] -> Maybe [TsToken]
forall s a. ParsecState s a -> Maybe a
parsecResult ParsecState (Seq Char) [TsToken]
source) of
  (Maybe [TsDeclaration]
Nothing, Maybe [TsToken]
_) -> String -> ParsecState (Seq TsToken) [TsDeclaration] -> IO ()
forall {s} {a} {a}.
(Categorized (Item s), Show (Item s),
 Show (Categorize (Item s))) =>
String -> ParsecState s a -> IO a
unprinted String
"tokens" ParsecState (Seq TsToken) [TsDeclaration]
printed
  (Maybe [TsDeclaration]
_, Maybe [TsToken]
Nothing) -> String -> ParsecState (Seq Char) [TsToken] -> IO ()
forall {s} {a} {a}.
(Categorized (Item s), Show (Item s),
 Show (Categorize (Item s))) =>
String -> ParsecState s a -> IO a
unprinted String
"characters" ParsecState (Seq Char) [TsToken]
source
  (Maybe [TsDeclaration], Maybe [TsToken])
_ -> Handle -> String -> IO ()
hPutStr Handle
handle (Seq Char -> String
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (ParsecState (Seq Char) [TsToken] -> Seq Char
forall s a. ParsecState s a -> s
parsecStream ParsecState (Seq Char) [TsToken]
source))
  where
    -- Printed into sequences, which grow at their ends in constant time.
    printed :: ParsecState (Seq TsToken) [TsDeclaration]
printed = [TsDeclaration]
-> Seq TsToken -> ParsecState (Seq TsToken) [TsDeclaration]
forall a string token.
(CtxGrammar token a, Cons string string token token,
 Snoc string string token token, Item string ~ token,
 Categorized token) =>
a -> string -> ParsecState string a
unparsecG ([TsDeclaration]
All Json as => [TsDeclaration]
forall (as :: [*]) -> All Json as => [TsDeclaration]
jsonTsDeclarations as) (forall a. Seq a
Seq.empty @TsToken)
    source :: ParsecState (Seq Char) [TsToken]
source =
      [TsToken] -> Seq Char -> ParsecState (Seq Char) [TsToken]
forall a string token.
(CtxGrammar token a, Cons string string token token,
 Snoc string string token token, Item string ~ token,
 Categorized token) =>
a -> string -> ParsecState string a
unparsecG (Seq TsToken -> [TsToken]
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (ParsecState (Seq TsToken) [TsDeclaration] -> Seq TsToken
forall s a. ParsecState s a -> s
parsecStream ParsecState (Seq TsToken) [TsDeclaration]
printed)) (forall a. Seq a
Seq.empty @Char)
    unprinted :: String -> ParsecState s a -> IO a
unprinted String
layer ParsecState s a
stage = IOError -> IO a
forall a. HasCallStack => IOError -> IO a
ioError (IOError -> IO a) -> IOError -> IO a
forall a b. (a -> b) -> a -> b
$ String -> IOError
userError (String -> IOError) -> String -> IOError
forall a b. (a -> b) -> a -> b
$
      String
"jsonTsPut: cannot print " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
layer String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" at "
      String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word -> String
forall a. Show a => a -> String
show (ParsecState s a -> Word
forall s a. ParsecState s a -> Word
parsecOffset ParsecState s a
stage) String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
", expecting "
      String -> ShowS
forall a. Semigroup a => a -> a -> a
<> TokenClass (Item s) -> String
forall a. Show a => a -> String
show (ParsecFailure s -> TokenClass (Item s)
forall s. ParsecFailure s -> TokenClass (Item s)
parsecExpect (ParsecState s a -> ParsecFailure s
forall s a. ParsecState s a -> ParsecFailure s
parsecFailure ParsecState s a
stage))

{- | t'JsonTypor' types the JSON of a grammar, reading the rules being typed
which are unguarded by an array, object or tuple, each noting whether it's
been unrolled, & updating the rules & their types.
-}
newtype JsonTypor a b = JsonTypor (Typing JsonType)

-- | The elements of tuples, which `>*<` sequences.
newtype TupTypor a b = TupTypor
  {forall a b. TupTypor a b -> Ap Typing JsonElements
runTupTypor :: Ap Typing JsonElements}

-- | Alternative shapes of objects, which `>*<` concatenates.
newtype ObjTypor a b = ObjTypor
  {forall a b. ObjTypor a b -> Ap Typing (Ap [] [JsonProperty])
runObjTypor :: Ap Typing (Ap [] [JsonProperty])}

type Typing = ReaderT (Map String Bool) (State (Map String JsonType))

{- | Type a rule once, so that every other occurrence of it, recursive or
not, is a `JsonRule`. Its type is reserved, as `falseP`, while it's typed.
An unguarded occurrence is its least fixpoint instead, unrolled once,
so that a rule of a rule is the rule, & a rule recurring unguarded
contributes `falseP`, since JSON values are finite.
-}
typeRule :: String -> JsonTypor a b -> JsonTypor c d
typeRule :: forall a b c d. String -> JsonTypor a b -> JsonTypor c d
typeRule String
key (JsonTypor Typing JsonType
body) = Typing JsonType -> JsonTypor c d
forall a b. Typing JsonType -> JsonTypor a b
JsonTypor (Typing JsonType -> JsonTypor c d)
-> Typing JsonType -> JsonTypor c d
forall a b. (a -> b) -> a -> b
$ do
  unguarded <- ReaderT
  (Map String Bool) (State (Map String JsonType)) (Map String Bool)
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
  typed <- lift get
  case (Map.lookup key unguarded, Map.member key typed) of
    (Just Bool
True, Bool
_) -> JsonType -> Typing JsonType
forall a.
a -> ReaderT (Map String Bool) (State (Map String JsonType)) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure JsonType
forall a. DisjunctiveMonoid a => a
falseP
    (Just Bool
False, Bool
_) -> (Map String Bool -> Map String Bool)
-> Typing JsonType -> Typing JsonType
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local (String -> Bool -> Map String Bool -> Map String Bool
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
key Bool
True) Typing JsonType
body
    (Maybe Bool
Nothing, Bool
True) -> JsonType -> Typing JsonType
forall a.
a -> ReaderT (Map String Bool) (State (Map String JsonType)) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (String -> JsonType
JsonRule String
key)
    (Maybe Bool
Nothing, Bool
False) -> do
      StateT (Map String JsonType) Identity ()
-> ReaderT (Map String Bool) (State (Map String JsonType)) ()
forall (m :: * -> *) a.
Monad m =>
m a -> ReaderT (Map String Bool) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((Map String JsonType -> Map String JsonType)
-> StateT (Map String JsonType) Identity ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify (String -> JsonType -> Map String JsonType -> Map String JsonType
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
key JsonType
forall a. DisjunctiveMonoid a => a
falseP))
      ruleType <- (Map String Bool -> Map String Bool)
-> Typing JsonType -> Typing JsonType
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local (String -> Bool -> Map String Bool -> Map String Bool
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
key Bool
False) Typing JsonType
body
      lift (modify (Map.insert key ruleType))
      pure (JsonRule key)

guarded :: Typing a -> Typing a
guarded :: forall a. Typing a -> Typing a
guarded = (Map String Bool -> Map String Bool)
-> ReaderT (Map String Bool) (State (Map String JsonType)) a
-> ReaderT (Map String Bool) (State (Map String JsonType)) a
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local (Map String Bool -> Map String Bool -> Map String Bool
forall a b. a -> b -> a
const Map String Bool
forall k a. Map k a
Map.empty)

typing :: JsonType -> JsonTypor a b
typing :: forall a b. JsonType -> JsonTypor a b
typing = Typing JsonType -> JsonTypor a b
forall a b. Typing JsonType -> JsonTypor a b
JsonTypor (Typing JsonType -> JsonTypor a b)
-> (JsonType -> Typing JsonType) -> JsonType -> JsonTypor a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JsonType -> Typing JsonType
forall a.
a -> ReaderT (Map String Bool) (State (Map String JsonType)) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

deriving via Grammor (Typing JsonType) a
  instance Functor (JsonTypor a)
deriving via Grammor (Typing JsonType)
  instance Profunctor JsonTypor
deriving via Grammor (Typing JsonType)
  instance Choice JsonTypor
-- | A partial isomorphism, like `?<`, matches a `JsonSubtype`.
instance Cochoice JsonTypor where
  unleft :: forall a d b. JsonTypor (Either a d) (Either b d) -> JsonTypor a b
unleft (JsonTypor Typing JsonType
t) = Typing JsonType -> JsonTypor a b
forall a b. Typing JsonType -> JsonTypor a b
JsonTypor (JsonType -> JsonType
jsonSubtype (JsonType -> JsonType) -> Typing JsonType -> Typing JsonType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Typing JsonType
t)
  unright :: forall d a b. JsonTypor (Either d a) (Either d b) -> JsonTypor a b
unright (JsonTypor Typing JsonType
t) = Typing JsonType -> JsonTypor a b
forall a b. Typing JsonType -> JsonTypor a b
JsonTypor (JsonType -> JsonType
jsonSubtype (JsonType -> JsonType) -> Typing JsonType -> Typing JsonType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Typing JsonType
t)
instance Witherable.Filterable (JsonTypor a) where
  mapMaybe :: forall a b. (a -> Maybe b) -> JsonTypor a a -> JsonTypor a b
mapMaybe = (a -> Maybe a) -> (a -> Maybe b) -> JsonTypor a a -> JsonTypor a b
forall (p :: * -> * -> *) s a b t.
(Choice p, Cochoice p) =>
(s -> Maybe a) -> (b -> Maybe t) -> p a b -> p s t
dimapMaybe a -> Maybe a
forall a. a -> Maybe a
Just
instance Filtrator JsonTypor
instance CocartesianMonoidal JsonTypor
instance CocartesianChoice JsonTypor where
  alternate :: forall a b c d.
Either (JsonTypor a b) (JsonTypor c d)
-> JsonTypor (Either a c) (Either b d)
alternate = (JsonTypor a b -> JsonTypor (Either a c) (Either b d))
-> (JsonTypor c d -> JsonTypor (Either a c) (Either b d))
-> Either (JsonTypor a b) (JsonTypor c d)
-> JsonTypor (Either a c) (Either b d)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either JsonTypor a b -> JsonTypor (Either a c) (Either b d)
forall a b. Coercible a b => a -> b
coerce JsonTypor c d -> JsonTypor (Either a c) (Either b d)
forall a b. Coercible a b => a -> b
coerce
instance DisjunctiveMonoid (JsonTypor a b) where
  falseP :: JsonTypor a b
falseP = JsonType -> JsonTypor a b
forall a b. JsonType -> JsonTypor a b
typing JsonType
forall a. DisjunctiveMonoid a => a
falseP
  JsonTypor Typing JsonType
t0 >|< :: JsonTypor a b -> JsonTypor a b -> JsonTypor a b
>|< JsonTypor Typing JsonType
t1 = Typing JsonType -> JsonTypor a b
forall a b. Typing JsonType -> JsonTypor a b
JsonTypor ((JsonType -> JsonType -> JsonType)
-> Typing JsonType -> Typing JsonType -> Typing JsonType
forall a b c.
(a -> b -> c)
-> ReaderT (Map String Bool) (State (Map String JsonType)) a
-> ReaderT (Map String Bool) (State (Map String JsonType)) b
-> ReaderT (Map String Bool) (State (Map String JsonType)) c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 JsonType -> JsonType -> JsonType
forall a. DisjunctiveMonoid a => a -> a -> a
(>|<) Typing JsonType
t0 Typing JsonType
t1)
instance Ruled (JsonTypor a b) where
  rule :: String -> JsonTypor a b -> JsonTypor a b
rule = String -> JsonTypor a b -> JsonTypor a b
forall a b c d. String -> JsonTypor a b -> JsonTypor c d
typeRule
instance BackusNaurForm (JsonTypor a b) where
  ruleRec :: String -> (JsonTypor a b -> JsonTypor a b) -> JsonTypor a b
ruleRec String
name JsonTypor a b -> JsonTypor a b
f = String -> JsonTypor a b -> JsonTypor a b
forall p. Ruled p => String -> p -> p
rule String
name (JsonTypor a b -> JsonTypor a b
f (String -> JsonTypor (ZonkAny 4) (ZonkAny 5) -> JsonTypor a b
forall a b c d. String -> JsonTypor a b -> JsonTypor c d
typeRule String
name JsonTypor (ZonkAny 4) (ZonkAny 5)
forall a. DisjunctiveMonoid a => a
falseP))
instance (x ~ (), y ~ ()) => IsString (JsonTypor x y) where
  fromString :: String -> JsonTypor x y
fromString = JsonType -> JsonTypor x y
forall a b. JsonType -> JsonTypor a b
typing (JsonType -> JsonTypor x y)
-> (String -> JsonType) -> String -> JsonTypor x y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> JsonType
JsonLiteral (Text -> JsonType) -> (String -> Text) -> String -> JsonType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack
instance JsonStr JsonTypor where
  jsonText :: JsonTypor Text Text
jsonText = JsonType -> JsonTypor Text Text
forall a b. JsonType -> JsonTypor a b
typing JsonType
JsonString
  jsonEnumWith :: forall a. (a -> Int) -> [(Text, a)] -> JsonTypor a a
jsonEnumWith a -> Int
_ [(Text, a)]
table =
    JsonType -> JsonTypor a a
forall a b. JsonType -> JsonTypor a b
typing ([JsonType] -> JsonType
jsonUnion [Text -> JsonType
JsonLiteral Text
literal | (Text
literal, a
_) <- [(Text, a)]
table])
instance JsonVal JsonTypor where
  jsonNull :: JsonTypor () ()
jsonNull = JsonType -> JsonTypor () ()
forall a b. JsonType -> JsonTypor a b
typing JsonType
JsonNull
  jsonBool :: JsonTypor Bool Bool
jsonBool = JsonType -> JsonTypor Bool Bool
forall a b. JsonType -> JsonTypor a b
typing JsonType
JsonBoolean
  jsonNumber :: JsonTypor Scientific Scientific
jsonNumber = JsonType -> JsonTypor Scientific Scientific
forall a b. JsonType -> JsonTypor a b
typing JsonType
JsonNumber
  jsonTuple :: forall a b.
(forall (q :: * -> * -> *). JsonTup JsonTypor q => q a b)
-> JsonTypor a b
jsonTuple forall (q :: * -> * -> *). JsonTup JsonTypor q => q a b
tup = Typing JsonType -> JsonTypor a b
forall a b. Typing JsonType -> JsonTypor a b
JsonTypor (JsonElements -> JsonType
tuple (JsonElements -> JsonType)
-> Typing JsonElements -> Typing JsonType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ap Typing JsonElements -> Typing JsonElements
forall {k} (f :: k -> *) (a :: k). Ap f a -> f a
getAp (TupTypor a b -> Ap Typing JsonElements
forall a b. TupTypor a b -> Ap Typing JsonElements
runTupTypor TupTypor a b
forall (q :: * -> * -> *). JsonTup JsonTypor q => q a b
tup))
    where
      tuple :: JsonElements -> JsonType
tuple = \case
        JsonElementsAlt [] -> JsonType
forall a. DisjunctiveMonoid a => a
falseP
        JsonElements
els -> JsonElements -> JsonType
JsonArray JsonElements
els
  jsonObject :: forall a b.
(forall (q :: * -> * -> *). JsonObj JsonTypor q => q a b)
-> JsonTypor a b
jsonObject forall (q :: * -> * -> *). JsonObj JsonTypor q => q a b
obj = Typing JsonType -> JsonTypor a b
forall a b. Typing JsonType -> JsonTypor a b
JsonTypor (Ap [] [JsonProperty] -> JsonType
objects (Ap [] [JsonProperty] -> JsonType)
-> Typing (Ap [] [JsonProperty]) -> Typing JsonType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ap Typing (Ap [] [JsonProperty]) -> Typing (Ap [] [JsonProperty])
forall {k} (f :: k -> *) (a :: k). Ap f a -> f a
getAp (ObjTypor a b -> Ap Typing (Ap [] [JsonProperty])
forall a b. ObjTypor a b -> Ap Typing (Ap [] [JsonProperty])
runObjTypor ObjTypor a b
forall (q :: * -> * -> *). JsonObj JsonTypor q => q a b
obj))
    where
      objects :: Ap [] [JsonProperty] -> JsonType
objects (Ap [[JsonProperty]]
shapes) = [JsonType] -> JsonType
jsonUnion (([JsonProperty] -> JsonType) -> [[JsonProperty]] -> [JsonType]
forall a b. (a -> b) -> [a] -> [b]
map [JsonProperty] -> JsonType
object [[JsonProperty]]
shapes)
      object :: [JsonProperty] -> JsonType
object [JsonProperty]
props
        | [Text] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([Text] -> [Text]
forall a. Eq a => [a] -> [a]
nub [Text]
keys) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [Text] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
keys = [JsonProperty] -> JsonType
JsonObject [JsonProperty]
props
        | Bool
otherwise = JsonType
forall a. DisjunctiveMonoid a => a
falseP
        where
          keys :: [Text]
keys = [Text
key | JsonProperty Text
key Bool
_ JsonType
_ <- [JsonProperty]
props]

deriving via Grammor (Ap Typing JsonElements) a
  instance Functor (TupTypor a)
deriving via Grammor (Ap Typing JsonElements) a
  instance Applicative (TupTypor a)
deriving via Grammor (Ap Typing JsonElements)
  instance Profunctor TupTypor
instance CocartesianMonoidal TupTypor
instance Choice TupTypor where
  left' :: forall a b c. TupTypor a b -> TupTypor (Either a c) (Either b c)
left' = TupTypor a b -> TupTypor (Either a c) (Either b c)
forall a b. Coercible a b => a -> b
coerce
  right' :: forall a b c. TupTypor a b -> TupTypor (Either c a) (Either c b)
right' = TupTypor a b -> TupTypor (Either c a) (Either c b)
forall a b. Coercible a b => a -> b
coerce
instance CocartesianChoice TupTypor where
  alternate :: forall a b c d.
Either (TupTypor a b) (TupTypor c d)
-> TupTypor (Either a c) (Either b d)
alternate = (TupTypor a b -> TupTypor (Either a c) (Either b d))
-> (TupTypor c d -> TupTypor (Either a c) (Either b d))
-> Either (TupTypor a b) (TupTypor c d)
-> TupTypor (Either a c) (Either b d)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either TupTypor a b -> TupTypor (Either a c) (Either b d)
forall a b. Coercible a b => a -> b
coerce TupTypor c d -> TupTypor (Either a c) (Either b d)
forall a b. Coercible a b => a -> b
coerce
instance DisjunctiveMonoid (TupTypor a b) where
  falseP :: TupTypor a b
falseP = Ap Typing JsonElements -> TupTypor a b
forall a b. Ap Typing JsonElements -> TupTypor a b
TupTypor (JsonElements -> Ap Typing JsonElements
forall a. a -> Ap Typing a
forall (f :: * -> *) a. Applicative f => a -> f a
pure JsonElements
forall a. DisjunctiveMonoid a => a
falseP)
  TupTypor Ap Typing JsonElements
s0 >|< :: TupTypor a b -> TupTypor a b -> TupTypor a b
>|< TupTypor Ap Typing JsonElements
s1 = Ap Typing JsonElements -> TupTypor a b
forall a b. Ap Typing JsonElements -> TupTypor a b
TupTypor ((JsonElements -> JsonElements -> JsonElements)
-> Ap Typing JsonElements
-> Ap Typing JsonElements
-> Ap Typing JsonElements
forall a b c.
(a -> b -> c) -> Ap Typing a -> Ap Typing b -> Ap Typing c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 JsonElements -> JsonElements -> JsonElements
forall a. DisjunctiveMonoid a => a -> a -> a
(>|<) Ap Typing JsonElements
s0 Ap Typing JsonElements
s1)
-- | `manyP` is a repetition of elements, `starK`.
instance Distributor TupTypor where
  manyP :: forall a b. TupTypor a b -> TupTypor [a] [b]
manyP (TupTypor Ap Typing JsonElements
s) = Ap Typing JsonElements -> TupTypor [a] [b]
forall a b. Ap Typing JsonElements -> TupTypor a b
TupTypor (JsonElements -> JsonElements
forall k. KleeneStarAlgebra k => k -> k
starK (JsonElements -> JsonElements)
-> Ap Typing JsonElements -> Ap Typing JsonElements
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ap Typing JsonElements
s)
instance Alternative (TupTypor a) where
  empty :: forall a. TupTypor a a
empty = TupTypor a a
forall a. DisjunctiveMonoid a => a
falseP
  <|> :: forall a. TupTypor a a -> TupTypor a a -> TupTypor a a
(<|>) = TupTypor a a -> TupTypor a a -> TupTypor a a
forall a. DisjunctiveMonoid a => a -> a -> a
(>|<)
  many :: forall a. TupTypor a a -> TupTypor a [a]
many = (a -> [a]) -> TupTypor [a] [a] -> TupTypor a [a]
forall a b c. (a -> b) -> TupTypor b c -> TupTypor a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> [a]
forall a. a -> [a]
repeat (TupTypor [a] [a] -> TupTypor a [a])
-> (TupTypor a a -> TupTypor [a] [a])
-> TupTypor a a
-> TupTypor a [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupTypor a a -> TupTypor [a] [a]
forall a b. TupTypor a b -> TupTypor [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP
  some :: forall a. TupTypor a a -> TupTypor a [a]
some = (a -> [a]) -> TupTypor [a] [a] -> TupTypor a [a]
forall a b c. (a -> b) -> TupTypor b c -> TupTypor a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> [a]
forall a. a -> [a]
repeat (TupTypor [a] [a] -> TupTypor a [a])
-> (TupTypor a a -> TupTypor [a] [a])
-> TupTypor a a
-> TupTypor a [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TupTypor a a -> TupTypor [a] [a]
forall a b. TupTypor a b -> TupTypor [a] [b]
forall (p :: * -> * -> *) a b. Alternator p => p a b -> p [a] [b]
someP
instance Alternator TupTypor
instance JsonTup JsonTypor TupTypor where
  jsonElem :: forall a b. JsonTypor a b -> TupTypor a b
jsonElem (JsonTypor Typing JsonType
t) = Ap Typing JsonElements -> TupTypor a b
forall a b. Ap Typing JsonElements -> TupTypor a b
TupTypor (Typing JsonElements -> Ap Typing JsonElements
forall {k} (f :: k -> *) (a :: k). f a -> Ap f a
Ap (JsonType -> JsonElements
single (JsonType -> JsonElements)
-> Typing JsonType -> Typing JsonElements
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Typing JsonType -> Typing JsonType
forall a. Typing a -> Typing a
guarded Typing JsonType
t))
    where
      single :: JsonType -> JsonElements
single = \case
        JsonUnion [] -> JsonElements
forall a. DisjunctiveMonoid a => a
falseP
        JsonType
ty -> JsonType -> JsonElements
JsonElement JsonType
ty

deriving via Grammor (Ap Typing (Ap [] [JsonProperty])) a
  instance Functor (ObjTypor a)
deriving via Grammor (Ap Typing (Ap [] [JsonProperty])) a
  instance Applicative (ObjTypor a)
deriving via Grammor (Ap Typing (Ap [] [JsonProperty]))
  instance Profunctor ObjTypor
instance Choice ObjTypor where
  left' :: forall a b c. ObjTypor a b -> ObjTypor (Either a c) (Either b c)
left' = ObjTypor a b -> ObjTypor (Either a c) (Either b c)
forall a b. Coercible a b => a -> b
coerce
  right' :: forall a b c. ObjTypor a b -> ObjTypor (Either c a) (Either c b)
right' = ObjTypor a b -> ObjTypor (Either c a) (Either c b)
forall a b. Coercible a b => a -> b
coerce
instance CocartesianMonoidal ObjTypor
instance CocartesianChoice ObjTypor where
  alternate :: forall a b c d.
Either (ObjTypor a b) (ObjTypor c d)
-> ObjTypor (Either a c) (Either b d)
alternate = (ObjTypor a b -> ObjTypor (Either a c) (Either b d))
-> (ObjTypor c d -> ObjTypor (Either a c) (Either b d))
-> Either (ObjTypor a b) (ObjTypor c d)
-> ObjTypor (Either a c) (Either b d)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ObjTypor a b -> ObjTypor (Either a c) (Either b d)
forall a b. Coercible a b => a -> b
coerce ObjTypor c d -> ObjTypor (Either a c) (Either b d)
forall a b. Coercible a b => a -> b
coerce
instance DisjunctiveMonoid (ObjTypor a b) where
  falseP :: ObjTypor a b
falseP = Ap Typing (Ap [] [JsonProperty]) -> ObjTypor a b
forall a b. Ap Typing (Ap [] [JsonProperty]) -> ObjTypor a b
ObjTypor (Ap [] [JsonProperty] -> Ap Typing (Ap [] [JsonProperty])
forall a. a -> Ap Typing a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([[JsonProperty]] -> Ap [] [JsonProperty]
forall {k} (f :: k -> *) (a :: k). f a -> Ap f a
Ap []))
  ObjTypor Ap Typing (Ap [] [JsonProperty])
s0 >|< :: ObjTypor a b -> ObjTypor a b -> ObjTypor a b
>|< ObjTypor Ap Typing (Ap [] [JsonProperty])
s1 = Ap Typing (Ap [] [JsonProperty]) -> ObjTypor a b
forall a b. Ap Typing (Ap [] [JsonProperty]) -> ObjTypor a b
ObjTypor ((Ap [] [JsonProperty]
 -> Ap [] [JsonProperty] -> Ap [] [JsonProperty])
-> Ap Typing (Ap [] [JsonProperty])
-> Ap Typing (Ap [] [JsonProperty])
-> Ap Typing (Ap [] [JsonProperty])
forall a b c.
(a -> b -> c) -> Ap Typing a -> Ap Typing b -> Ap Typing c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Ap [] [JsonProperty]
-> Ap [] [JsonProperty] -> Ap [] [JsonProperty]
forall {f :: * -> *} {a}.
Semigroup (f a) =>
Ap f a -> Ap f a -> Ap f a
unite Ap Typing (Ap [] [JsonProperty])
s0 Ap Typing (Ap [] [JsonProperty])
s1)
    where
      unite :: Ap f a -> Ap f a -> Ap f a
unite (Ap f a
shapes0) (Ap f a
shapes1) = f a -> Ap f a
forall {k} (f :: k -> *) (a :: k). f a -> Ap f a
Ap (f a
shapes0 f a -> f a -> f a
forall a. Semigroup a => a -> a -> a
<> f a
shapes1)
instance JsonObj JsonTypor ObjTypor where
  jsonDict :: forall a b c d.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> JsonTypor c d -> ObjTypor [(a, c)] [(b, d)]
jsonDict (JsonTypor Typing JsonType
k) (JsonTypor Typing JsonType
t) =
    Typing JsonProperty -> ObjTypor [(a, c)] [(b, d)]
forall a b. Typing JsonProperty -> ObjTypor a b
typedProperty (JsonType -> JsonType -> JsonProperty
JsonDict (JsonType -> JsonType -> JsonProperty)
-> Typing JsonType
-> ReaderT
     (Map String Bool)
     (State (Map String JsonType))
     (JsonType -> JsonProperty)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Typing JsonType -> Typing JsonType
forall a. Typing a -> Typing a
guarded Typing JsonType
k ReaderT
  (Map String Bool)
  (State (Map String JsonType))
  (JsonType -> JsonProperty)
-> Typing JsonType -> Typing JsonProperty
forall a b.
ReaderT (Map String Bool) (State (Map String JsonType)) (a -> b)
-> ReaderT (Map String Bool) (State (Map String JsonType)) a
-> ReaderT (Map String Bool) (State (Map String JsonType)) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Typing JsonType -> Typing JsonType
forall a. Typing a -> Typing a
guarded Typing JsonType
t)
  Text
k !: :: forall a b. Text -> JsonTypor a b -> ObjTypor a b
!: JsonTypor Typing JsonType
t = Typing JsonProperty -> ObjTypor a b
forall a b. Typing JsonProperty -> ObjTypor a b
typedProperty (Text -> Bool -> JsonType -> JsonProperty
JsonProperty Text
k Bool
False (JsonType -> JsonProperty)
-> Typing JsonType -> Typing JsonProperty
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Typing JsonType -> Typing JsonType
forall a. Typing a -> Typing a
guarded Typing JsonType
t)
  Text
k ?: :: forall a b. Text -> JsonTypor a b -> ObjTypor (Maybe a) (Maybe b)
?: JsonTypor Typing JsonType
t = Typing JsonProperty -> ObjTypor (Maybe a) (Maybe b)
forall a b. Typing JsonProperty -> ObjTypor a b
typedProperty (Text -> Bool -> JsonType -> JsonProperty
JsonProperty Text
k Bool
True (JsonType -> JsonProperty)
-> Typing JsonType -> Typing JsonProperty
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Typing JsonType -> Typing JsonType
forall a. Typing a -> Typing a
guarded Typing JsonType
t)

-- | An object type of one property.
typedProperty :: Typing JsonProperty -> ObjTypor a b
typedProperty :: forall a b. Typing JsonProperty -> ObjTypor a b
typedProperty Typing JsonProperty
prop = Ap Typing (Ap [] [JsonProperty]) -> ObjTypor a b
forall a b. Ap Typing (Ap [] [JsonProperty]) -> ObjTypor a b
ObjTypor (Typing (Ap [] [JsonProperty]) -> Ap Typing (Ap [] [JsonProperty])
forall {k} (f :: k -> *) (a :: k). f a -> Ap f a
Ap ((\JsonProperty
p -> [[JsonProperty]] -> Ap [] [JsonProperty]
forall {k} (f :: k -> *) (a :: k). f a -> Ap f a
Ap [[JsonProperty
p]]) (JsonProperty -> Ap [] [JsonProperty])
-> Typing JsonProperty -> Typing (Ap [] [JsonProperty])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Typing JsonProperty
prop))

-- | An element of a TypeScript tuple type.
data TupleElement
  = RequiredElement JsonType -- ^ @T@
  | OptionalElement JsonType -- ^ @T?@
  | RestElement JsonType -- ^ @...T[]@
  deriving stock TupleElement -> TupleElement -> Bool
(TupleElement -> TupleElement -> Bool)
-> (TupleElement -> TupleElement -> Bool) -> Eq TupleElement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TupleElement -> TupleElement -> Bool
== :: TupleElement -> TupleElement -> Bool
$c/= :: TupleElement -> TupleElement -> Bool
/= :: TupleElement -> TupleElement -> Bool
Eq

elementType :: TupleElement -> JsonType
elementType :: TupleElement -> JsonType
elementType = \case
  RequiredElement JsonType
t -> JsonType
t
  OptionalElement JsonType
t -> JsonType
t
  RestElement JsonType
t -> JsonType
t

-- | TypeScript tuple shapes, widening @(A B)*@ to @[...(A | B)[]]@.
tupleShapes :: JsonElements -> [[TupleElement]]
tupleShapes :: JsonElements -> [[TupleElement]]
tupleShapes = \case
  JsonElement JsonType
t -> [[JsonType -> TupleElement
RequiredElement JsonType
t]]
  JsonElementsTup [JsonElements]
els -> ([[TupleElement]] -> [TupleElement])
-> [[[TupleElement]]] -> [[TupleElement]]
forall a b. (a -> b) -> [a] -> [b]
map [[TupleElement]] -> [TupleElement]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ((JsonElements -> [[TupleElement]])
-> [JsonElements] -> [[[TupleElement]]]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse JsonElements -> [[TupleElement]]
tupleShapes [JsonElements]
els)
  JsonElementsAlt [JsonElements]
alts -> (JsonElements -> [[TupleElement]])
-> [JsonElements] -> [[TupleElement]]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap JsonElements -> [[TupleElement]]
tupleShapes [JsonElements]
alts
  JsonElements JsonElements
els -> case ([TupleElement] -> [JsonType]) -> [[TupleElement]] -> [JsonType]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((TupleElement -> JsonType) -> [TupleElement] -> [JsonType]
forall a b. (a -> b) -> [a] -> [b]
map TupleElement -> JsonType
elementType) (JsonElements -> [[TupleElement]]
tupleShapes JsonElements
els) of
    [] -> [[]]
    [JsonType]
ts -> [[JsonType -> TupleElement
RestElement ([JsonType] -> JsonType
jsonUnion [JsonType]
ts)]]
  JsonElements1 JsonElements
els ->
    [ [TupleElement]
shape [TupleElement] -> [TupleElement] -> [TupleElement]
forall a. Semigroup a => a -> a -> a
<> [TupleElement]
rest
    | [TupleElement]
shape <- JsonElements -> [[TupleElement]]
tupleShapes JsonElements
els, [TupleElement]
rest <- JsonElements -> [[TupleElement]]
tupleShapes (JsonElements -> JsonElements
JsonElements JsonElements
els) ]
  JsonElementsOpt JsonElements
els -> JsonElements -> [[TupleElement]]
tupleShapes JsonElements
els [[TupleElement]] -> [[TupleElement]] -> [[TupleElement]]
forall a. Semigroup a => a -> a -> a
<> [[]]

-- TypeScript --

{- | TypeScript declarations of the rules of some types, named by their
unqualified names, or else their qualified names, or else their numbered
qualified names, as TypeScript identifiers, in order of their names.
-}
tsDeclarations :: [Bnf JsonType] -> [TsDeclaration]
tsDeclarations :: [Bnf JsonType] -> [TsDeclaration]
tsDeclarations [Bnf JsonType]
bnfs =
  [ [TsTokenCategory]
-> Text -> [TsTypeParameter] -> TsType -> TsDeclaration
TypeAliasDeclaration [TsTokenCategory
ExportKeyword] Text
identifier [] (Map String JsonType -> Map String Text -> JsonType -> TsType
tsType Map String JsonType
rules Map String Text
names JsonType
ruleType)
  | (Text
identifier, JsonType
ruleType) <- ((Text, JsonType) -> Text)
-> [(Text, JsonType)] -> [(Text, JsonType)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (Text, JsonType) -> Text
forall a b. (a, b) -> a
fst
      [(Map String Text
names Map String Text -> String -> Text
forall k a. Ord k => Map k a -> k -> a
Map.! String
key, JsonType
ruleType) | (String
key, JsonType
ruleType) <- Map String JsonType -> [(String, JsonType)]
forall k a. Map k a -> [(k, a)]
Map.toList Map String JsonType
rules]
  ]
  where
    rules :: Map String JsonType
rules = [(String, JsonType)] -> Map String JsonType
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ((Bnf JsonType -> [(String, JsonType)])
-> [Bnf JsonType] -> [(String, JsonType)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Set (String, JsonType) -> [(String, JsonType)]
forall a. Set a -> [a]
Set.toList (Set (String, JsonType) -> [(String, JsonType)])
-> (Bnf JsonType -> Set (String, JsonType))
-> Bnf JsonType
-> [(String, JsonType)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bnf JsonType -> Set (String, JsonType)
forall rule. Bnf rule -> Set (String, rule)
rulesBnf) [Bnf JsonType]
bnfs)
    names :: Map String Text
names = (Map String Text -> String -> Map String Text)
-> Map String Text -> [String] -> Map String Text
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Map String Text -> String -> Map String Text
name Map String Text
forall k a. Map k a
Map.empty (Map String JsonType -> [String]
forall k a. Map k a -> [k]
Map.keys Map String JsonType
rules)
    name :: Map String Text -> String -> Map String Text
name Map String Text
named String
key = String -> Text -> Map String Text -> Map String Text
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
key Text
fresh Map String Text
named
      where
        taken :: [Text]
taken = Map String Text -> [Text]
forall k a. Map k a -> [a]
Map.elems Map String Text
named
        fresh :: Text
fresh = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
qualified (Maybe Text -> Text) -> Maybe Text -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> Maybe Text
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find
          (\Text
candidate -> Text
candidate Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
taken
            Bool -> Bool -> Bool
&& Text
candidate Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
tsReserved)
          ( String -> Text
tsIdentifier (ShowS
unqualified String
key) Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: Text
qualified
          Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Text
qualified Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"_" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (Int -> String
forall a. Show a => a -> String
show Int
n) | Int
n <- [Int
2 :: Int ..]] )
        qualified :: Text
qualified = String -> Text
tsIdentifier String
key

-- | Names of types which TypeScript reserves.
tsReserved :: [Text]
tsReserved :: [Text]
tsReserved =
  [ Text
"any", Text
"bigint", Text
"boolean", Text
"false", Text
"never", Text
"null", Text
"number"
  , Text
"object", Text
"string", Text
"symbol", Text
"true", Text
"undefined", Text
"unknown", Text
"void"
  ]

-- | A TypeScript identifier for a rule name, like @Box_List_Int@.
tsIdentifier :: String -> Text
tsIdentifier :: String -> Text
tsIdentifier String
name = case Text -> Maybe (Char, Text)
Text.uncons Text
ident of
  Maybe (Char, Text)
Nothing -> Text
"T"
  Just (Char
c, Text
_) | Char -> Bool
isDigit Char
c -> Text
"T_" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ident
  Maybe (Char, Text)
_ -> Text
ident
  where
    ident :: Text
ident = Text -> [Text] -> Text
Text.intercalate Text
"_"
      [Text
part | Text
part <- (Char -> Bool) -> Text -> [Text]
Text.split (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isAlphaNum) (String -> Text
Text.pack String
spelled)
      , Bool -> Bool
not (Text -> Bool
Text.null Text
part)]
    spelled :: String
spelled = (Char -> String) -> ShowS
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\Char
c -> if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'[' then String
" List " else [Char
c]) String
name

{- | The TypeScript type of a JSON type, by its rules & their names,
parenthesized as TypeScript parses it.
-}
tsType :: Map String JsonType -> Map String Text -> JsonType -> TsType
tsType :: Map String JsonType -> Map String Text -> JsonType -> TsType
tsType Map String JsonType
rules Map String Text
names = JsonType -> TsType
typeNode
  where
    typeNode :: JsonType -> TsType
typeNode = \case
      JsonRule String
key -> [Text] -> [TsType] -> TsType
ReferenceType [Map String Text
names Map String Text -> String -> Text
forall k a. Ord k => Map k a -> k -> a
Map.! String
key] []
      JsonType
JsonNull -> TsLiteral -> TsType
LiteralType TsLiteral
NullLiteral
      JsonType
JsonBoolean -> TsTokenCategory -> TsType
KeywordType TsTokenCategory
BooleanKeyword
      JsonType
JsonNumber -> TsTokenCategory -> TsType
KeywordType TsTokenCategory
NumberKeyword
      JsonType
JsonString -> TsTokenCategory -> TsType
KeywordType TsTokenCategory
StringKeyword
      JsonLiteral Text
text -> TsLiteral -> TsType
LiteralType (Text -> TsLiteral
TextLiteral Text
text)
      JsonSubtype JsonType
t -> JsonType -> TsType
typeNode JsonType
t
      t :: JsonType
t@(JsonArray JsonElements
_) -> JsonType -> TsType
typeNode ([JsonType] -> JsonType
JsonUnion [JsonType
t])
      JsonObject [JsonProperty]
props -> [JsonProperty] -> TsType
object [JsonProperty]
props
      JsonUnion [JsonType]
ts -> [TsType] -> TsType
union ([TsType] -> TsType) -> [TsType] -> TsType
forall a b. (a -> b) -> a -> b
$ case (JsonType -> Bool) -> [JsonType] -> ([JsonType], [JsonType])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break JsonType -> Bool
isTuple [JsonType]
ts of
        ([JsonType]
before, JsonType
_ : [JsonType]
_) ->
          (JsonType -> TsType) -> [JsonType] -> [TsType]
forall a b. (a -> b) -> [a] -> [b]
map JsonType -> TsType
typeNode [JsonType]
before
          [TsType] -> [TsType] -> [TsType]
forall a. Semigroup a => a -> a -> a
<> ([TupleElement] -> TsType) -> [[TupleElement]] -> [TsType]
forall a b. (a -> b) -> [a] -> [b]
map [TupleElement] -> TsType
tuple
            ([[TupleElement]] -> [[TupleElement]]
tsTuples ([[[TupleElement]]] -> [[TupleElement]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [JsonElements -> [[TupleElement]]
tupleShapes JsonElements
els | JsonArray JsonElements
els <- [JsonType]
ts]))
          [TsType] -> [TsType] -> [TsType]
forall a. Semigroup a => a -> a -> a
<> [JsonType -> TsType
typeNode JsonType
t | JsonType
t <- Int -> [JsonType] -> [JsonType]
forall a. Int -> [a] -> [a]
drop ([JsonType] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [JsonType]
before) [JsonType]
ts, Bool -> Bool
not (JsonType -> Bool
isTuple JsonType
t)]
        ([JsonType], [JsonType])
_ -> (JsonType -> TsType) -> [JsonType] -> [TsType]
forall a b. (a -> b) -> [a] -> [b]
map JsonType -> TsType
typeNode [JsonType]
ts
    isTuple :: JsonType -> Bool
isTuple = \case JsonArray JsonElements
_ -> Bool
True; JsonType
_ -> Bool
False
    tuple :: [TupleElement] -> TsType
tuple = \case
      [RestElement JsonType
t] -> TsType -> TsType
ArrayType (TsType -> TsType
operand (JsonType -> TsType
typeNode JsonType
t))
      [TupleElement]
els -> [TsType] -> TsType
TupleType ([TsType] -> TsType) -> [TsType] -> TsType
forall a b. (a -> b) -> a -> b
$ [TupleElement]
els [TupleElement] -> (TupleElement -> TsType) -> [TsType]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
        RequiredElement JsonType
t -> JsonType -> TsType
typeNode JsonType
t
        OptionalElement JsonType
t -> TsType -> TsType
OptionalType (TsType -> TsType
operand (JsonType -> TsType
typeNode JsonType
t))
        RestElement JsonType
t -> TsType -> TsType
RestType (TsType -> TsType
ArrayType (TsType -> TsType
operand (JsonType -> TsType
typeNode JsonType
t)))
    -- The intersected parts of an object type: its named properties
    -- & index signature, of its string keys, & a mapped type
    -- of its literal keys, but those which are named, which TypeScript
    -- types apart, like @{ id: T } & { [key in K as …]?: U }@.
    object :: [JsonProperty] -> TsType
object [JsonProperty]
props = case ([TsProperty]
named [TsProperty] -> [TsProperty] -> [TsProperty]
forall a. Semigroup a => a -> a -> a
<> [TsProperty]
indexSignatures, [TsType]
mappedTypes) of
      ([], []) -> [TsProperty] -> TsType
ObjectType []
      ([], [TsType
objectPart]) -> TsType
objectPart
      ([], [TsType]
objectParts) -> [TsType] -> TsType
IntersectionType [TsType]
objectParts
      ([TsProperty]
members, [TsType]
objectParts) -> case [TsProperty] -> TsType
ObjectType [TsProperty]
members TsType -> [TsType] -> [TsType]
forall a. a -> [a] -> [a]
: [TsType]
objectParts of
        [TsType
objectPart] -> TsType
objectPart
        [TsType]
allObjectParts -> [TsType] -> TsType
IntersectionType [TsType]
allObjectParts
      where
        named :: [TsProperty]
named =
          [ [TsTokenCategory]
-> TsPropertyName -> Bool -> Maybe TsType -> TsProperty
PropertySignature [] (Text -> TsPropertyName
propertyName Text
key) Bool
isOptional (TsType -> Maybe TsType
forall a. a -> Maybe a
Just (JsonType -> TsType
typeNode JsonType
t))
          | JsonProperty Text
key Bool
isOptional JsonType
t <- [JsonProperty]
props ]
        keys :: [Text]
keys = [Text
key | JsonProperty Text
key Bool
_ JsonType
_ <- [JsonProperty]
props]
        dicts :: [(JsonType, [JsonType], JsonType)]
dicts =
          [ (JsonType
keyType, Map String JsonType -> JsonType -> [JsonType]
typeAlternatives Map String JsonType
rules JsonType
keyType, JsonType
t)
          | JsonDict JsonType
keyType JsonType
t <- [JsonProperty]
props, JsonType
t JsonType -> JsonType -> Bool
forall a. Eq a => a -> a -> Bool
/= JsonType
forall a. DisjunctiveMonoid a => a
falseP ]
        indexSignatures :: [TsProperty]
indexSignatures =
          [ [TsTokenCategory] -> Text -> TsType -> TsType -> TsProperty
IndexSignature [] Text
"key" (TsTokenCategory -> TsType
KeywordType TsTokenCategory
StringKeyword) (TsType -> TsProperty) -> TsType -> TsProperty
forall a b. (a -> b) -> a -> b
$ [TsType] -> TsType
union
              (JsonType -> TsType
typeNode JsonType
t TsType -> [TsType] -> [TsType]
forall a. a -> [a] -> [a]
: [TsType]
covered)
          | (JsonType
_, [JsonType]
keyAlternatives, JsonType
t) <- [(JsonType, [JsonType], JsonType)]
dicts, JsonType
JsonString JsonType -> [JsonType] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [JsonType]
keyAlternatives ]
        -- An index type also covers the named properties,
        -- as TypeScript requires.
        covered :: [TsType]
covered =
          [JsonType -> TsType
typeNode JsonType
t | JsonProperty Text
_ Bool
_ JsonType
t <- [JsonProperty]
props]
          [TsType] -> [TsType] -> [TsType]
forall a. Semigroup a => a -> a -> a
<> [TsTokenCategory -> TsType
KeywordType TsTokenCategory
UndefinedKeyword | [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Bool
o | JsonProperty Text
_ Bool
o JsonType
_ <- [JsonProperty]
props]]
        mappedTypes :: [TsType]
mappedTypes =
          [ Maybe TsTokenCategory
-> Text
-> TsType
-> Maybe TsType
-> Maybe TsTokenCategory
-> TsType
-> TsType
MappedType Maybe TsTokenCategory
forall a. Maybe a
Nothing Text
"key" TsType
base Maybe TsType
exclusion (TsTokenCategory -> Maybe TsTokenCategory
forall a. a -> Maybe a
Just TsTokenCategory
QuestionToken) (JsonType -> TsType
typeNode JsonType
t)
          | (JsonType
keyType, [JsonType]
keyAlternatives, JsonType
t) <- [(JsonType, [JsonType], JsonType)]
dicts
          , let
              literalKeys :: [Text]
literalKeys = [Text
l | JsonLiteral Text
l <- [JsonType]
keyAlternatives]
              excluded :: [Text]
excluded = [Text
l | Text
l <- [Text]
literalKeys, Text
l Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
keys]
              base :: TsType
base
                | [Text] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
literalKeys Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [JsonType] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [JsonType]
keyAlternatives = JsonType -> TsType
typeNode JsonType
keyType
                | Bool
otherwise = [TsType] -> TsType
union ((Text -> TsType) -> [Text] -> [TsType]
forall a b. (a -> b) -> [a] -> [b]
map (TsLiteral -> TsType
LiteralType (TsLiteral -> TsType) -> (Text -> TsLiteral) -> Text -> TsType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TsLiteral
TextLiteral) [Text]
literalKeys)
              exclusion :: Maybe TsType
exclusion
                | [Text] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
excluded = Maybe TsType
forall a. Maybe a
Nothing
                | Bool
otherwise = TsType -> Maybe TsType
forall a. a -> Maybe a
Just (TsType -> Maybe TsType) -> TsType -> Maybe TsType
forall a b. (a -> b) -> a -> b
$ TsType -> TsType -> TsType -> TsType -> TsType
ConditionalType
                    ([Text] -> [TsType] -> TsType
ReferenceType [Text
"key"] [])
                    ([TsType] -> TsType
union ((Text -> TsType) -> [Text] -> [TsType]
forall a b. (a -> b) -> [a] -> [b]
map (TsLiteral -> TsType
LiteralType (TsLiteral -> TsType) -> (Text -> TsLiteral) -> Text -> TsType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TsLiteral
TextLiteral) [Text]
excluded))
                    (TsTokenCategory -> TsType
KeywordType TsTokenCategory
NeverKeyword)
                    ([Text] -> [TsType] -> TsType
ReferenceType [Text
"key"] [])
          , [Text] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
excluded Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< [Text] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
literalKeys
          ]
    propertyName :: Text -> TsPropertyName
propertyName Text
key
      | Text -> Bool
isIdentifier Text
key = Text -> TsPropertyName
PropertyIdentifier Text
key
      | Bool
otherwise = Text -> TsPropertyName
PropertyString Text
key
    isIdentifier :: Text -> Bool
isIdentifier Text
key = case Text -> Maybe (Char, Text)
Text.uncons Text
key of
      Just (Char
c, Text
rest) -> Char -> Bool
identifierStart Char
c Bool -> Bool -> Bool
&& (Char -> Bool) -> Text -> Bool
Text.all Char -> Bool
identifierChar Text
rest
      Maybe (Char, Text)
Nothing -> Bool
False
    identifierStart :: Char -> Bool
identifierStart Char
c = Char -> Bool
isAlpha Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'$'
    identifierChar :: Char -> Bool
identifierChar Char
c = Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'$'

-- | A union of types, flattened, or else its only type, or else @never@.
union :: [TsType] -> TsType
union :: [TsType] -> TsType
union [TsType]
nodes = case [TsType] -> [TsType]
forall a. Eq a => [a] -> [a]
nub ((TsType -> [TsType]) -> [TsType] -> [TsType]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TsType -> [TsType]
flatten [TsType]
nodes) of
  [] -> TsTokenCategory -> TsType
KeywordType TsTokenCategory
NeverKeyword
  [TsType
node] -> TsType
node
  [TsType]
alts -> [TsType] -> TsType
UnionType ((TsType -> TsType) -> [TsType] -> [TsType]
forall a b. (a -> b) -> [a] -> [b]
map TsType -> TsType
member [TsType]
alts)
  where
    flatten :: TsType -> [TsType]
flatten = \case
      UnionType [TsType]
alts -> [TsType]
alts
      KeywordType TsTokenCategory
NeverKeyword -> []
      TsType
node -> [TsType
node]
    member :: TsType -> TsType
member = \case
      node :: TsType
node@(ConditionalType {}) -> TsType -> TsType
ParenthesizedType TsType
node
      TsType
node -> TsType
node

-- | A type, parenthesized as an operand of an array or element type.
operand :: TsType -> TsType
operand :: TsType -> TsType
operand = \case
  node :: TsType
node@(UnionType [TsType]
_) -> TsType -> TsType
ParenthesizedType TsType
node
  node :: TsType
node@(IntersectionType [TsType]
_) -> TsType -> TsType
ParenthesizedType TsType
node
  node :: TsType
node@(ConditionalType {}) -> TsType -> TsType
ParenthesizedType TsType
node
  TsType
node -> TsType
node

-- | The alternatives of a type, resolving its rules & widening subtypes.
typeAlternatives :: Map String JsonType -> JsonType -> [JsonType]
typeAlternatives :: Map String JsonType -> JsonType -> [JsonType]
typeAlternatives Map String JsonType
rules = [String] -> JsonType -> [JsonType]
go []
  where
    go :: [String] -> JsonType -> [JsonType]
go [String]
seen = \case
      JsonRule String
key | String
key String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [String]
seen, Just JsonType
t <- String -> Map String JsonType -> Maybe JsonType
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
key Map String JsonType
rules ->
        [String] -> JsonType -> [JsonType]
go (String
key String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
seen) JsonType
t
      JsonUnion [JsonType]
ts -> (JsonType -> [JsonType]) -> [JsonType] -> [JsonType]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ([String] -> JsonType -> [JsonType]
go [String]
seen) [JsonType]
ts
      JsonSubtype JsonType
t -> [String] -> JsonType -> [JsonType]
go [String]
seen JsonType
t
      JsonType
t -> [JsonType
t]

{- | Tuples of some shapes, as TypeScript types them. TypeScript requires
that a tuple type has at most one rest element, no optional element after
a rest element, & no required element after an optional element.
So, the elements from the first rest element to the last are merged
into one rest element, & optional elements are expanded into
alternative shapes wherever they'd be followed by a required or
rest element, or a rest element precedes them.
Then, alternative shapes are merged exactly, where they differ by
one required or optional element's type, into a union, or by one more
element, into an optional or rest element, so that @[A] | [B]@ is @[A | B]@,
@[A] | [A, B]@ is @[A, B?]@ & @[] | [A, ...A[]]@ is @[...A[]]@.
-}
tsTuples :: [[TupleElement]] -> [[TupleElement]]
tsTuples :: [[TupleElement]] -> [[TupleElement]]
tsTuples [[TupleElement]]
shapes = [[TupleElement]] -> [[TupleElement]]
merged ([[TupleElement]] -> [[TupleElement]]
forall a. Eq a => [a] -> [a]
nub (([TupleElement] -> [[TupleElement]])
-> [[TupleElement]] -> [[TupleElement]]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Bool -> [TupleElement] -> [[TupleElement]]
expand Bool
False ([TupleElement] -> [[TupleElement]])
-> ([TupleElement] -> [TupleElement])
-> [TupleElement]
-> [[TupleElement]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [TupleElement] -> [TupleElement]
mergeRests) [[TupleElement]]
shapes))
  where
    merged :: [[TupleElement]] -> [[TupleElement]]
merged [[TupleElement]]
alts =
      case [ (Int
i, Int
j, [TupleElement]
shape)
           | [TupleElement] -> [TupleElement] -> Maybe [TupleElement]
merge <- [[TupleElement] -> [TupleElement] -> Maybe [TupleElement]
unioned, [TupleElement] -> [TupleElement] -> Maybe [TupleElement]
extended]
           , (Int
i, [TupleElement]
a) <- [Int] -> [[TupleElement]] -> [(Int, [TupleElement])]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0 :: Int ..] [[TupleElement]]
alts
           , (Int
j, [TupleElement]
b) <- [Int] -> [[TupleElement]] -> [(Int, [TupleElement])]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0 ..] [[TupleElement]]
alts
           , Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
j
           , Just [TupleElement]
shape <- [[TupleElement] -> [TupleElement] -> Maybe [TupleElement]
merge [TupleElement]
a [TupleElement]
b]
           ] of
        (Int
i, Int
j, [TupleElement]
shape) : [(Int, Int, [TupleElement])]
_ -> [[TupleElement]] -> [[TupleElement]]
merged
          [ if Int
k Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
i Int
j then [TupleElement]
shape else [TupleElement]
alt
          | (Int
k, [TupleElement]
alt) <- [Int] -> [[TupleElement]] -> [(Int, [TupleElement])]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0 ..] [[TupleElement]]
alts, Int
k Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
i Int
j ]
        [] -> [[TupleElement]]
alts
    unioned :: [TupleElement] -> [TupleElement] -> Maybe [TupleElement]
unioned [TupleElement]
a [TupleElement]
b = case ((TupleElement, TupleElement) -> Bool)
-> [(TupleElement, TupleElement)]
-> ([(TupleElement, TupleElement)], [(TupleElement, TupleElement)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break ((TupleElement -> TupleElement -> Bool)
-> (TupleElement, TupleElement) -> Bool
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry TupleElement -> TupleElement -> Bool
forall a. Eq a => a -> a -> Bool
(/=)) ([TupleElement] -> [TupleElement] -> [(TupleElement, TupleElement)]
forall a b. [a] -> [b] -> [(a, b)]
zip [TupleElement]
a [TupleElement]
b) of
      ([(TupleElement, TupleElement)]
same, (TupleElement
x, TupleElement
y) : [(TupleElement, TupleElement)]
others)
        | [TupleElement] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TupleElement]
a Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [TupleElement] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TupleElement]
b, ((TupleElement, TupleElement) -> Bool)
-> [(TupleElement, TupleElement)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ((TupleElement -> TupleElement -> Bool)
-> (TupleElement, TupleElement) -> Bool
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry TupleElement -> TupleElement -> Bool
forall a. Eq a => a -> a -> Bool
(==)) [(TupleElement, TupleElement)]
others
        , Just TupleElement
el <- TupleElement -> TupleElement -> Maybe TupleElement
unionedElement TupleElement
x TupleElement
y ->
            [TupleElement] -> Maybe [TupleElement]
forall a. a -> Maybe a
Just (((TupleElement, TupleElement) -> TupleElement)
-> [(TupleElement, TupleElement)] -> [TupleElement]
forall a b. (a -> b) -> [a] -> [b]
map (TupleElement, TupleElement) -> TupleElement
forall a b. (a, b) -> a
fst [(TupleElement, TupleElement)]
same [TupleElement] -> [TupleElement] -> [TupleElement]
forall a. Semigroup a => a -> a -> a
<> [TupleElement
el] [TupleElement] -> [TupleElement] -> [TupleElement]
forall a. Semigroup a => a -> a -> a
<> ((TupleElement, TupleElement) -> TupleElement)
-> [(TupleElement, TupleElement)] -> [TupleElement]
forall a b. (a -> b) -> [a] -> [b]
map (TupleElement, TupleElement) -> TupleElement
forall a b. (a, b) -> a
fst [(TupleElement, TupleElement)]
others)
      ([(TupleElement, TupleElement)], [(TupleElement, TupleElement)])
_ -> Maybe [TupleElement]
forall a. Maybe a
Nothing
    unionedElement :: TupleElement -> TupleElement -> Maybe TupleElement
unionedElement TupleElement
x TupleElement
y = case (TupleElement
x, TupleElement
y) of
      (RequiredElement JsonType
s, RequiredElement JsonType
t) -> TupleElement -> Maybe TupleElement
forall a. a -> Maybe a
Just (JsonType -> TupleElement
RequiredElement (JsonType
s JsonType -> JsonType -> JsonType
forall a. DisjunctiveMonoid a => a -> a -> a
>|< JsonType
t))
      (OptionalElement JsonType
s, OptionalElement JsonType
t) -> TupleElement -> Maybe TupleElement
forall a. a -> Maybe a
Just (JsonType -> TupleElement
OptionalElement (JsonType
s JsonType -> JsonType -> JsonType
forall a. DisjunctiveMonoid a => a -> a -> a
>|< JsonType
t))
      (TupleElement, TupleElement)
_ -> Maybe TupleElement
forall a. Maybe a
Nothing
    extended :: [TupleElement] -> [TupleElement] -> Maybe [TupleElement]
extended [TupleElement]
a [TupleElement]
b
      | (TupleElement -> Bool) -> [TupleElement] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any TupleElement -> Bool
isRest [TupleElement]
a = Maybe [TupleElement]
forall a. Maybe a
Nothing
      | Bool
otherwise = [TupleElement] -> [TupleElement] -> Maybe [TupleElement]
forall a. Eq a => [a] -> [a] -> Maybe [a]
stripPrefix [TupleElement]
a [TupleElement]
b Maybe [TupleElement]
-> ([TupleElement] -> Maybe [TupleElement]) -> Maybe [TupleElement]
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
          [RequiredElement JsonType
t] -> [TupleElement] -> Maybe [TupleElement]
forall a. a -> Maybe a
Just ([TupleElement]
a [TupleElement] -> [TupleElement] -> [TupleElement]
forall a. Semigroup a => a -> a -> a
<> [JsonType -> TupleElement
OptionalElement JsonType
t])
          [OptionalElement JsonType
_] -> [TupleElement] -> Maybe [TupleElement]
forall a. a -> Maybe a
Just [TupleElement]
b
          [RestElement JsonType
_] -> [TupleElement] -> Maybe [TupleElement]
forall a. a -> Maybe a
Just [TupleElement]
b
          [RequiredElement JsonType
t, RestElement JsonType
u] | JsonType
t JsonType -> JsonType -> Bool
forall a. Eq a => a -> a -> Bool
== JsonType
u -> [TupleElement] -> Maybe [TupleElement]
forall a. a -> Maybe a
Just ([TupleElement]
a [TupleElement] -> [TupleElement] -> [TupleElement]
forall a. Semigroup a => a -> a -> a
<> [JsonType -> TupleElement
RestElement JsonType
t])
          [TupleElement]
_ -> Maybe [TupleElement]
forall a. Maybe a
Nothing
    isRest :: TupleElement -> Bool
isRest = \case RestElement JsonType
_ -> Bool
True; TupleElement
_ -> Bool
False
    mergeRests :: [TupleElement] -> [TupleElement]
mergeRests [TupleElement]
els = case (TupleElement -> Bool) -> [TupleElement] -> [Int]
forall a. (a -> Bool) -> [a] -> [Int]
findIndices TupleElement -> Bool
isRest [TupleElement]
els of
      Int
start : rests :: [Int]
rests@(Int
_ : [Int]
_) ->
        let
          ([TupleElement]
before, [TupleElement]
others) = Int -> [TupleElement] -> ([TupleElement], [TupleElement])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
start [TupleElement]
els
          ([TupleElement]
middle, [TupleElement]
after) = Int -> [TupleElement] -> ([TupleElement], [TupleElement])
forall a. Int -> [a] -> ([a], [a])
splitAt ([Int] -> Int
forall a. HasCallStack => [a] -> a
last [Int]
rests Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
start Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [TupleElement]
others
        in
          [TupleElement]
before [TupleElement] -> [TupleElement] -> [TupleElement]
forall a. Semigroup a => a -> a -> a
<> [JsonType -> TupleElement
RestElement ([JsonType] -> JsonType
jsonUnion ((TupleElement -> JsonType) -> [TupleElement] -> [JsonType]
forall a b. (a -> b) -> [a] -> [b]
map TupleElement -> JsonType
elementType [TupleElement]
middle))] [TupleElement] -> [TupleElement] -> [TupleElement]
forall a. Semigroup a => a -> a -> a
<> [TupleElement]
after
      [Int]
_ -> [TupleElement]
els
    expand :: Bool -> [TupleElement] -> [[TupleElement]]
expand Bool
_ [] = [[]]
    expand Bool
restBefore (TupleElement
el : [TupleElement]
els) = case TupleElement
el of
      OptionalElement JsonType
t | Bool
restBefore Bool -> Bool -> Bool
|| Bool -> Bool
not ([TupleElement] -> Bool
optionalTail [TupleElement]
els) ->
        Bool -> [TupleElement] -> [[TupleElement]]
expand Bool
restBefore [TupleElement]
els [[TupleElement]] -> [[TupleElement]] -> [[TupleElement]]
forall a. Semigroup a => a -> a -> a
<> ([TupleElement] -> [TupleElement])
-> [[TupleElement]] -> [[TupleElement]]
forall a b. (a -> b) -> [a] -> [b]
map (JsonType -> TupleElement
RequiredElement JsonType
t TupleElement -> [TupleElement] -> [TupleElement]
forall a. a -> [a] -> [a]
:) (Bool -> [TupleElement] -> [[TupleElement]]
expand Bool
restBefore [TupleElement]
els)
      RestElement JsonType
_ -> ([TupleElement] -> [TupleElement])
-> [[TupleElement]] -> [[TupleElement]]
forall a b. (a -> b) -> [a] -> [b]
map (TupleElement
el TupleElement -> [TupleElement] -> [TupleElement]
forall a. a -> [a] -> [a]
:) (Bool -> [TupleElement] -> [[TupleElement]]
expand Bool
True [TupleElement]
els)
      TupleElement
_ -> ([TupleElement] -> [TupleElement])
-> [[TupleElement]] -> [[TupleElement]]
forall a b. (a -> b) -> [a] -> [b]
map (TupleElement
el TupleElement -> [TupleElement] -> [TupleElement]
forall a. a -> [a] -> [a]
:) (Bool -> [TupleElement] -> [[TupleElement]]
expand Bool
restBefore [TupleElement]
els)
    optionalTail :: [TupleElement] -> Bool
optionalTail = \case
      [] -> Bool
True
      [RestElement JsonType
_] -> Bool
True
      OptionalElement JsonType
_ : [TupleElement]
els -> [TupleElement] -> Bool
optionalTail [TupleElement]
els
      [TupleElement]
_ -> Bool
False

-- Json instance helpers

-- | An enumeration of a bounded `Enum`, by the names of its values.
jsonEnumerated :: (Bounded a, Enum a, JsonStr p) => (a -> Text) -> p a a
jsonEnumerated :: forall a (p :: * -> * -> *).
(Bounded a, Enum a, JsonStr p) =>
(a -> Text) -> p a a
jsonEnumerated a -> Text
name = (a -> Int) -> [(Text, a)] -> p a a
forall a. (a -> Int) -> [(Text, a)] -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
(a -> Int) -> [(Text, a)] -> p a a
jsonEnumWith
  (\a
a -> a -> Int
forall a. Enum a => a -> Int
fromEnum a
a Int -> Int -> Int
forall a. Num a => a -> a -> a
- a -> Int
forall a. Enum a => a -> Int
fromEnum (a
forall a. Bounded a => a
minBound a -> a -> a
forall a. a -> a -> a
`asTypeOf` a
a))
  [(a -> Text
name a
a, a
a) | a
a <- [a
forall a. Bounded a => a
minBound .. a
forall a. Bounded a => a
maxBound]]

boundedScientific :: Scientific -> Maybe Scientific
boundedScientific :: Scientific -> Maybe Scientific
boundedScientific Scientific
s = Scientific
s Scientific -> Maybe () -> Maybe Scientific
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int -> Int
forall a. Num a => a -> a
abs (Scientific -> Int
base10Exponent Scientific
s) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
1024)

_BoundedInteger :: (Integral a, Bounded a) => Prism' Scientific a
_BoundedInteger :: forall a. (Integral a, Bounded a) => Prism' Scientific a
_BoundedInteger = (a -> Scientific)
-> (Scientific -> Maybe a) -> Prism Scientific Scientific a a
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' a -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral Scientific -> Maybe a
forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger

jsonBoundedInteger :: (Integral a, Bounded a, JsonVal p) => p a a
jsonBoundedInteger :: forall a (p :: * -> * -> *).
(Integral a, Bounded a, JsonVal p) =>
p a a
jsonBoundedInteger = Market a a a (Identity a)
-> Market a a Scientific (Identity Scientific)
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific a
_BoundedInteger (Market a a a (Identity a)
 -> Market a a Scientific (Identity Scientific))
-> p Scientific Scientific -> p a a
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Scientific Scientific
forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
jsonNumber

_Integer :: Prism' Scientific Integer
_Integer :: Prism' Scientific Integer
_Integer = (Integer -> Scientific)
-> (Scientific -> Maybe Integer) -> Prism' Scientific Integer
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Integer -> Scientific
forall a. Num a => Integer -> a
fromInteger ((Scientific -> Maybe Integer) -> Prism' Scientific Integer)
-> (Scientific -> Maybe Integer) -> Prism' Scientific Integer
forall a b. (a -> b) -> a -> b
$
  Scientific -> Maybe Scientific
boundedScientific (Scientific -> Maybe Scientific)
-> (Scientific -> Maybe Integer) -> Scientific -> Maybe Integer
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (Double -> Maybe Integer)
-> (Integer -> Maybe Integer)
-> Either Double Integer
-> Maybe Integer
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe Integer -> Double -> Maybe Integer
forall a b. a -> b -> a
const Maybe Integer
forall a. Maybe a
Nothing) Integer -> Maybe Integer
forall a. a -> Maybe a
Just (Either Double Integer -> Maybe Integer)
-> (Scientific -> Either Double Integer)
-> Scientific
-> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
floatingOrInteger @Double

_Natural :: Prism' Scientific Natural
_Natural :: Prism' Scientific Natural
_Natural = (Natural -> Scientific)
-> (Scientific -> Maybe Natural) -> Prism' Scientific Natural
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Natural -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Scientific -> Maybe Natural) -> Prism' Scientific Natural)
-> (Scientific -> Maybe Natural) -> Prism' Scientific Natural
forall a b. (a -> b) -> a -> b
$ \Scientific
s -> do
  i <- Getting (First Integer) Scientific Integer
-> Scientific -> Maybe Integer
forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview Getting (First Integer) Scientific Integer
Prism' Scientific Integer
_Integer Scientific
s
  fromInteger i <$ guard (i >= 0)

jsonRealFloat :: (RealFloat a, JsonVal p) => p a a -> p a a
jsonRealFloat :: forall a (p :: * -> * -> *).
(RealFloat a, JsonVal p) =>
p a a -> p a a
jsonRealFloat p a a
finite = (a -> Either a a)
-> (Either a a -> a) -> p (Either a a) (Either a a) -> p a a
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 a -> Either a a
forall {a}. RealFloat a => a -> Either a a
finiteness ((a -> a) -> (a -> a) -> Either a a -> a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either a -> a
forall a. a -> a
id a -> a
forall a. a -> a
id) (p a a
finite p a a -> p a a -> p (Either a a) (Either a a)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p a a
nonFinite)
  where
    finiteness :: a -> Either a a
finiteness a
x = if a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
x Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isInfinite a
x then a -> Either a a
forall a b. b -> Either a b
Right a
x else a -> Either a a
forall a b. a -> Either a b
Left a
x
    nonFinite :: p a a
nonFinite = (a -> Either () (Either () ()))
-> (Either () (Either () ()) -> a)
-> p (Either () (Either () ())) (Either () (Either () ()))
-> p a a
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 a -> Either () (Either () ())
forall {p}. RealFloat p => p -> Either () (Either () ())
sign Either () (Either () ()) -> a
forall {a} {a} {b}. Either a (Either a b) -> a
value (p () ()
forall (p :: * -> * -> *). JsonVal p => p () ()
jsonNull p () ()
-> p (Either () ()) (Either () ())
-> p (Either () (Either () ())) (Either () (Either () ()))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p () ()
"+inf" p () () -> p () () -> p (Either () ()) (Either () ())
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p () ()
"-inf")
    sign :: p -> Either () (Either () ())
sign p
x
      | p -> Bool
forall a. RealFloat a => a -> Bool
isNaN p
x = () -> Either () (Either () ())
forall a b. a -> Either a b
Left ()
      | p
x p -> p -> Bool
forall a. Ord a => a -> a -> Bool
> p
0 = Either () () -> Either () (Either () ())
forall a b. b -> Either a b
Right (() -> Either () ()
forall a b. a -> Either a b
Left ())
      | Bool
otherwise = Either () () -> Either () (Either () ())
forall a b. b -> Either a b
Right (() -> Either () ()
forall a b. b -> Either a b
Right ())
    value :: Either a (Either a b) -> a
value = (a -> a) -> (Either a b -> a) -> Either a (Either a b) -> a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\a
_ -> a
0a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0) ((a -> a) -> (b -> a) -> Either a b -> a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\a
_ -> a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0) (\b
_ -> a -> a
forall a. Num a => a -> a
negate a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0))

jsonRealFrac :: (Fractional a, Real a, JsonVal p) => p a a
jsonRealFrac :: forall a (p :: * -> * -> *).
(Fractional a, Real a, JsonVal p) =>
p a a
jsonRealFrac =
  (a -> Scientific)
-> (Scientific -> Maybe a) -> Prism Scientific Scientific a a
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' a -> Scientific
forall a b. (Real a, Fractional b) => a -> b
realToFrac ((Scientific -> a) -> Maybe Scientific -> Maybe a
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Scientific -> a
forall a b. (Real a, Fractional b) => a -> b
realToFrac (Maybe Scientific -> Maybe a)
-> (Scientific -> Maybe Scientific) -> Scientific -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Scientific -> Maybe Scientific
boundedScientific) (Market a a a (Identity a)
 -> Market a a Scientific (Identity Scientific))
-> p Scientific Scientific -> p a a
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Scientific Scientific
forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
jsonNumber


jsonKeyText :: JsonStr p => p Key Key
jsonKeyText :: forall (k :: * -> * -> *). JsonStr k => k Key Key
jsonKeyText = (Key -> Text) -> (Text -> Key) -> Iso Key Key Text Text
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Key -> Text
Key.toText Text -> Key
Key.fromText (Exchange Text Text Text (Identity Text)
 -> Exchange Text Text Key (Identity Key))
-> p Text Text -> p Key Key
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText

-- | Read a `Scientific`, quickly when it's a canonical integer.
readScientific :: Text -> Maybe Scientific
readScientific :: Text -> Maybe Scientific
readScientific Text
t
  | Bool
canonical, Right (Integer
i, Text
_) <- Reader Integer -> Reader Integer
forall a. Num a => Reader a -> Reader a
TextRead.signed Reader Integer
forall a. Integral a => Reader a
TextRead.decimal Text
t =
      Scientific -> Maybe Scientific
forall a. a -> Maybe a
Just (Integer -> Scientific
forall a. Num a => Integer -> a
fromInteger Integer
i)
  | Bool
otherwise =
      [Scientific] -> Maybe Scientific
forall a. [a] -> Maybe a
listToMaybe [Scientific
s | (Scientific
s, String
"") <- ReadP Scientific -> ReadS Scientific
forall a. ReadP a -> ReadS a
readP_to_S ReadP Scientific
scientificP (Text -> String
Text.unpack Text
t)]
  where
    digits :: Text
digits = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
t (Text -> Text -> Maybe Text
Text.stripPrefix Text
"-" Text
t)
    canonical :: Bool
canonical = Bool -> Bool
not (Text -> Bool
Text.null Text
digits) Bool -> Bool -> Bool
&& (Char -> Bool) -> Text -> Bool
Text.all Char -> Bool
isDigit Text
digits
      Bool -> Bool -> Bool
&& (Text -> Int
Text.length Text
digits Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 Bool -> Bool -> Bool
|| Int -> Text -> Text
Text.take Int
1 Text
digits Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"0")

-- | `Scientific` map keys, as @aeson@ renders them.
jsonScientificKey :: JsonStr p => p Scientific Scientific
jsonScientificKey :: forall (p :: * -> * -> *). JsonStr p => p Scientific Scientific
jsonScientificKey = (Scientific -> Text)
-> (Text -> Maybe Scientific)
-> Prism Text Text Scientific Scientific
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Scientific -> Text
render Text -> Maybe Scientific
readScientific (Market Scientific Scientific Scientific (Identity Scientific)
 -> Market Scientific Scientific Text (Identity Text))
-> p Text Text -> p Scientific Scientific
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
  where
    render :: Scientific -> Text
render Scientific
s
      | Int
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 Bool -> Bool -> Bool
|| Int
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1024 = String -> Text
Text.pack (FPFormat -> Maybe Int -> Scientific -> String
formatScientific FPFormat
Generic Maybe Int
forall a. Maybe a
Nothing Scientific
s)
      | Bool
otherwise = String -> Text
Text.pack (Integer -> String
forall a. Show a => a -> String
show (Scientific -> Integer
coefficient Scientific
s Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
10 Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
e))
      where
        e :: Int
e = Scientific -> Int
base10Exponent Scientific
s

-- | Integral map keys, as @aeson@ renders them.
jsonIntKey :: (Show a, JsonStr p) => APrism' Scientific a -> p a a
jsonIntKey :: forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific a
integral = APrism Text (Text, Encoding' Text) a a -> p a a
forall a. APrism Text (Text, Encoding' Text) a a -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText (APrism Text (Text, Encoding' Text) a a -> p a a)
-> APrism Text (Text, Encoding' Text) a a -> p a a
forall a b. (a -> b) -> a -> b
$ (a -> (Text, Encoding' Text))
-> (Text -> Either (Text, Encoding' Text) a)
-> forall {p :: * -> * -> *} {f :: * -> *}.
   (Choice p, Applicative f) =>
   p a (f a) -> p Text (f (Text, Encoding' Text))
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism a -> (Text, Encoding' Text)
forall {p} {a}. Show p => p -> (Text, Encoding' a)
shown ((Text -> Either (Text, Encoding' Text) a)
 -> forall {p :: * -> * -> *} {f :: * -> *}.
    (Choice p, Applicative f) =>
    p a (f a) -> p Text (f (Text, Encoding' Text)))
-> (Text -> Either (Text, Encoding' Text) a)
-> forall {p :: * -> * -> *} {f :: * -> *}.
   (Choice p, Applicative f) =>
   p a (f a) -> p Text (f (Text, Encoding' Text))
forall a b. (a -> b) -> a -> b
$ \Text
t ->
  Either (Text, Encoding' Text) a
-> (a -> Either (Text, Encoding' Text) a)
-> Maybe a
-> Either (Text, Encoding' Text) a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((Text, Encoding' Text) -> Either (Text, Encoding' Text) a
forall a b. a -> Either a b
Left (Text
t, Text -> Encoding' Text
forall a. Text -> Encoding' a
Encoding.text Text
t)) a -> Either (Text, Encoding' Text) a
forall a b. b -> Either a b
Right
    (Text -> Maybe Scientific
readScientific Text
t Maybe Scientific -> (Scientific -> Maybe a) -> Maybe a
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Getting (First a) Scientific a -> Scientific -> Maybe a
forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview (APrism' Scientific a -> Prism Scientific Scientific a a
forall s t a b. APrism s t a b -> Prism s t a b
clonePrism APrism' Scientific a
integral))
  where
    shown :: p -> (Text, Encoding' a)
shown p
a = (String -> Text
Text.pack (p -> String
forall a. Show a => a -> String
show p
a), Builder -> Encoding' a
forall a. Builder -> Encoding' a
Encoding.unsafeToEncoding
      (Char -> Builder
Builder.char7 Char
'"' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
Builder.string7 (p -> String
forall a. Show a => a -> String
show p
a) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
Builder.char7 Char
'"'))

-- | `RealFloat` map keys, as @aeson@ renders them.
jsonRealFloatKey :: (RealFloat a, Show a, JsonStr p) => p a a
jsonRealFloatKey :: forall a (p :: * -> * -> *).
(RealFloat a, Show a, JsonStr p) =>
p a a
jsonRealFloatKey = (a -> Text) -> (Text -> Maybe a) -> Prism Text Text a a
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' a -> Text
forall {p}. (RealFloat p, Show p) => p -> Text
render Text -> Maybe a
parse (Market a a a (Identity a) -> Market a a Text (Identity Text))
-> p Text Text -> p a a
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
  where
    render :: p -> Text
render p
d
      | p -> Bool
forall a. RealFloat a => a -> Bool
isInfinite p
d = if p
d p -> p -> Bool
forall a. Ord a => a -> a -> Bool
> p
0 then Text
"+inf" else Text
"-inf"
      | Bool
otherwise = String -> Text
Text.pack (p -> String
forall a. Show a => a -> String
show p
d)
    parse :: Text -> Maybe a
parse = \case
      Text
"NaN" -> a -> Maybe a
forall a. a -> Maybe a
Just (a
0a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0)
      Text
"+inf" -> a -> Maybe a
forall a. a -> Maybe a
Just (a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0)
      Text
"-inf" -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> a
forall a. Num a => a -> a
negate a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0)
      Text
t -> Scientific -> a
forall a. RealFloat a => Scientific -> a
toRealFloat (Scientific -> a) -> Maybe Scientific -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Scientific
readScientific Text
t

-- | Transform a key, if there's one.
overKey
  :: (forall k. JsonStr k => k a a -> k b b)
  -> Maybe (forall k. JsonStr k => k a a)
  -> Maybe (forall k. JsonStr k => k b b)
overKey :: forall a b.
(forall (k :: * -> * -> *). JsonStr k => k a a -> k b b)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
overKey forall (k :: * -> * -> *). JsonStr k => k a a -> k b b
f = \case
  Just forall (k :: * -> * -> *). JsonStr k => k a a
key -> (forall (k :: * -> * -> *). JsonStr k => k b b)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
forall a. a -> Maybe a
Just (k a a -> k b b
forall (k :: * -> * -> *). JsonStr k => k a a -> k b b
f k a a
forall (k :: * -> * -> *). JsonStr k => k a a
key)
  Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
Nothing -> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
forall a. Maybe a
Nothing

-- Json instances

-- base
instance Json Bool where
  json :: forall (p :: * -> * -> *). JsonVal p => p Bool Bool
json = p Bool Bool
forall (p :: * -> * -> *). JsonVal p => p Bool Bool
jsonBool
  {-# INLINE json #-}
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Bool Bool)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Bool Bool)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Bool Bool)
forall a. a -> Maybe a
Just ((Bool -> Text) -> k Bool Bool
forall a (p :: * -> * -> *).
(Bounded a, Enum a, JsonStr p) =>
(a -> Text) -> p a a
jsonEnumerated (\Bool
b -> if Bool
b then Text
"true" else Text
"false"))
instance Json Ordering where
  json :: forall (p :: * -> * -> *). JsonVal p => p Ordering Ordering
json = p Ordering Ordering -> p Ordering Ordering
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped ((Ordering -> Text) -> p Ordering Ordering
forall a (p :: * -> * -> *).
(Bounded a, Enum a, JsonStr p) =>
(a -> Text) -> p a a
jsonEnumerated (String -> Text
Text.pack (String -> Text) -> (Ordering -> String) -> Ordering -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ordering -> String
forall a. Show a => a -> String
show))
instance Json () where
  json :: forall (p :: * -> * -> *). JsonVal p => p () ()
json = (forall (q :: * -> * -> *). JsonTup p q => q () ()) -> p () ()
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple q () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
forall (q :: * -> * -> *). JsonTup p q => q () ()
oneP
  jsonOmitField :: Maybe (APrism' () ())
jsonOmitField = APrism' () () -> Maybe (APrism' () ())
forall a. a -> Maybe a
Just (() -> Prism' () ()
forall a. Eq a => a -> Prism' a ()
only ())
instance Json Void where
  json :: forall (p :: * -> * -> *). JsonVal p => p Void Void
json = p Void Void
forall (p :: * -> * -> *). CocartesianMonoidal p => p Void Void
zeroP
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Void Void)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Void Void)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Void Void)
forall a. a -> Maybe a
Just ((Void -> Text) -> (Text -> Maybe Void) -> Prism Text Text Void Void
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Void -> Text
forall a. Void -> a
absurd (Maybe Void -> Text -> Maybe Void
forall a b. a -> b -> a
const Maybe Void
forall a. Maybe a
Nothing) (Market Void Void Void (Identity Void)
 -> Market Void Void Text (Identity Text))
-> k Text Text -> k Void Void
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< k Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText)

jsonChar :: JsonStr p => p Char Char
jsonChar :: forall (p :: * -> * -> *). JsonStr p => p Char Char
jsonChar = (Char -> Text) -> (Text -> Maybe Char) -> Prism Text Text Char Char
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Char -> Text
Text.singleton Text -> Maybe Char
single (Market Char Char Char (Identity Char)
 -> Market Char Char Text (Identity Text))
-> p Text Text -> p Char Char
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
  where
    single :: Text -> Maybe Char
single Text
t = case Text -> Maybe (Char, Text)
Text.uncons Text
t of
      Just (Char
c, Text
rest) | Text -> Bool
Text.null Text
rest -> Char -> Maybe Char
forall a. a -> Maybe a
Just Char
c
      Maybe (Char, Text)
_ -> Maybe Char
forall a. Maybe a
Nothing

instance Json Char where
  json :: forall (p :: * -> * -> *). JsonVal p => p Char Char
json = p Char Char -> p Char Char
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Char Char
forall (p :: * -> * -> *). JsonStr p => p Char Char
jsonChar
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p String String
jsonList = p String String
forall (k :: * -> * -> *). JsonStr k => k String String
jsonString
  jsonKey :: Maybe (forall (p :: * -> * -> *). JsonStr p => p Char Char)
jsonKey = (forall (p :: * -> * -> *). JsonStr p => p Char Char)
-> Maybe (forall (p :: * -> * -> *). JsonStr p => p Char Char)
forall a. a -> Maybe a
Just k Char Char
forall (p :: * -> * -> *). JsonStr p => p Char Char
jsonChar
  jsonKeyList :: Maybe (forall (k :: * -> * -> *). JsonStr k => k String String)
jsonKeyList = (forall (k :: * -> * -> *). JsonStr k => k String String)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k String String)
forall a. a -> Maybe a
Just k String String
forall (k :: * -> * -> *). JsonStr k => k String String
jsonString
instance Json a => Json [a] where
  json :: forall (p :: * -> * -> *). JsonVal p => p [a] [a]
json = p [a] [a]
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
forall (p :: * -> * -> *). JsonVal p => p [a] [a]
jsonList
  {-# INLINE json #-}
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
jsonKey = forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
jsonKeyList @a
instance Json a => Json (Maybe a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Maybe a) (Maybe a)
json = p a a -> p (Maybe a) (Maybe a)
forall a b. p a b -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
JsonVal p =>
p a b -> p (Maybe a) (Maybe b)
jsonNullable p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
  jsonOmitField :: Maybe (APrism' (Maybe a) ())
jsonOmitField = APrism' (Maybe a) () -> Maybe (APrism' (Maybe a) ())
forall a. a -> Maybe a
Just APrism' (Maybe a) ()
forall a (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p () (f ()) -> p (Maybe a) (f (Maybe a))
_Nothing
instance (Json a, Json b) => Json (Either a b) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Either a b) (Either a b)
json = Text -> p a a -> p a a
forall a b. Text -> p a b -> p a b
forall (p :: * -> * -> *) a b. JsonVal p => Text -> p a b -> p a b
jsonTag Text
"Left" p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json p a a -> p b b -> p (Either a b) (Either a b)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< Text -> p b b -> p b b
forall a b. Text -> p a b -> p a b
forall (p :: * -> * -> *) a b. JsonVal p => Text -> p a b -> p a b
jsonTag Text
"Right" p b b
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p b b
json
instance Json Double where
  json :: forall (p :: * -> * -> *). JsonVal p => p Double Double
json = p Double Double -> p Double Double
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (p Double Double -> p Double Double
forall a (p :: * -> * -> *).
(RealFloat a, JsonVal p) =>
p a a -> p a a
jsonRealFloat p Double Double
forall (p :: * -> * -> *). JsonVal p => p Double Double
jsonDouble)
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Double Double)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Double Double)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Double Double)
forall a. a -> Maybe a
Just k Double Double
forall a (p :: * -> * -> *).
(RealFloat a, Show a, JsonStr p) =>
p a a
forall (k :: * -> * -> *). JsonStr k => k Double Double
jsonRealFloatKey
instance Json Float where
  json :: forall (p :: * -> * -> *). JsonVal p => p Float Float
json = p Float Float -> p Float Float
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (p Float Float -> p Float Float) -> p Float Float -> p Float Float
forall a b. (a -> b) -> a -> b
$
    p Float Float -> p Float Float
forall a (p :: * -> * -> *).
(RealFloat a, JsonVal p) =>
p a a -> p a a
jsonRealFloat ((Float -> Scientific)
-> (Scientific -> Float) -> Iso Float Float Scientific Scientific
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Float -> Scientific
forall a. RealFloat a => a -> Scientific
fromFloatDigits Scientific -> Float
forall a. RealFloat a => Scientific -> a
toRealFloat (Exchange Scientific Scientific Scientific (Identity Scientific)
 -> Exchange Scientific Scientific Float (Identity Float))
-> p Scientific Scientific -> p Float Float
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p Scientific Scientific
forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
jsonNumber)
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Float Float)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Float Float)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Float Float)
forall a. a -> Maybe a
Just k Float Float
forall a (p :: * -> * -> *).
(RealFloat a, Show a, JsonStr p) =>
p a a
forall (k :: * -> * -> *). JsonStr k => k Float Float
jsonRealFloatKey
instance (Integral a, Json a) => Json (Ratio a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Ratio a) (Ratio a)
json = (Ratio a -> (a, a))
-> ((a, a) -> Maybe (Ratio a))
-> Prism (a, a) (a, a) (Ratio a) (Ratio a)
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism'
    (\Ratio a
r -> (Ratio a -> a
forall a. Ratio a -> a
numerator Ratio a
r, Ratio a -> a
forall a. Ratio a -> a
denominator Ratio a
r))
    (\(a
n, a
d) -> a
n a -> a -> Ratio a
forall a. Integral a => a -> a -> Ratio a
% a
d Ratio a -> Maybe () -> Maybe (Ratio a)
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (a
d a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
0))
    (Market (Ratio a) (Ratio a) (Ratio a) (Identity (Ratio a))
 -> Market (Ratio a) (Ratio a) (a, a) (Identity (a, a)))
-> p (a, a) (a, a) -> p (Ratio a) (Ratio a)
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< (forall (q :: * -> * -> *). JsonObj p q => q (a, a) (a, a))
-> p (a, a) (a, a)
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject (Text
"numerator" Text -> p a a -> q a a
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json q a a -> q a a -> q (a, a) (a, a)
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< Text
"denominator" Text -> p a a -> q a a
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json)
instance HasResolution a => Json (Fixed a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Fixed a) (Fixed a)
json = p (Fixed a) (Fixed a)
forall a (p :: * -> * -> *).
(Fractional a, Real a, JsonVal p) =>
p a a
jsonRealFrac
  jsonKey :: Maybe
  (forall (k :: * -> * -> *). JsonStr k => k (Fixed a) (Fixed a))
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k (Fixed a) (Fixed a))
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k (Fixed a) (Fixed a))
forall a. a -> Maybe a
Just ((Fixed a -> Scientific)
-> (Scientific -> Fixed a)
-> Iso (Fixed a) (Fixed a) Scientific Scientific
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Fixed a -> Scientific
forall a b. (Real a, Fractional b) => a -> b
realToFrac Scientific -> Fixed a
forall a b. (Real a, Fractional b) => a -> b
realToFrac (Exchange Scientific Scientific Scientific (Identity Scientific)
 -> Exchange Scientific Scientific (Fixed a) (Identity (Fixed a)))
-> k Scientific Scientific -> k (Fixed a) (Fixed a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ k Scientific Scientific
forall (p :: * -> * -> *). JsonStr p => p Scientific Scientific
jsonScientificKey)
instance Json Int where
  json :: forall (p :: * -> * -> *). JsonVal p => p Int Int
json = p Int Int -> p Int Int
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Int Int
forall (p :: * -> * -> *). JsonVal p => p Int Int
jsonInt
  {-# INLINE json #-}
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Int Int)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Int Int)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Int Int)
forall a. a -> Maybe a
Just (APrism' Scientific Int -> k Int Int
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Int
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Int
_BoundedInteger)
instance Json Int8 where
  json :: forall (p :: * -> * -> *). JsonVal p => p Int8 Int8
json = p Int8 Int8 -> p Int8 Int8
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Int8 Int8
forall (p :: * -> * -> *). JsonVal p => p Int8 Int8
jsonInt8
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Int8 Int8)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Int8 Int8)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Int8 Int8)
forall a. a -> Maybe a
Just (APrism' Scientific Int8 -> k Int8 Int8
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Int8
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Int8
_BoundedInteger)
instance Json Int16 where
  json :: forall (p :: * -> * -> *). JsonVal p => p Int16 Int16
json = p Int16 Int16 -> p Int16 Int16
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Int16 Int16
forall (p :: * -> * -> *). JsonVal p => p Int16 Int16
jsonInt16
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Int16 Int16)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Int16 Int16)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Int16 Int16)
forall a. a -> Maybe a
Just (APrism' Scientific Int16 -> k Int16 Int16
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Int16
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Int16
_BoundedInteger)
instance Json Int32 where
  json :: forall (p :: * -> * -> *). JsonVal p => p Int32 Int32
json = p Int32 Int32 -> p Int32 Int32
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Int32 Int32
forall (p :: * -> * -> *). JsonVal p => p Int32 Int32
jsonInt32
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Int32 Int32)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Int32 Int32)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Int32 Int32)
forall a. a -> Maybe a
Just (APrism' Scientific Int32 -> k Int32 Int32
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Int32
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Int32
_BoundedInteger)
instance Json Int64 where
  json :: forall (p :: * -> * -> *). JsonVal p => p Int64 Int64
json = p Int64 Int64 -> p Int64 Int64
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Int64 Int64
forall (p :: * -> * -> *). JsonVal p => p Int64 Int64
jsonInt64
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Int64 Int64)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Int64 Int64)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Int64 Int64)
forall a. a -> Maybe a
Just (APrism' Scientific Int64 -> k Int64 Int64
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Int64
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Int64
_BoundedInteger)
instance Json Word where
  json :: forall (p :: * -> * -> *). JsonVal p => p Word Word
json = p Word Word -> p Word Word
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Word Word
forall (p :: * -> * -> *). JsonVal p => p Word Word
jsonWord
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Word Word)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Word Word)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Word Word)
forall a. a -> Maybe a
Just (APrism' Scientific Word -> k Word Word
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Word
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Word
_BoundedInteger)
instance Json Word8 where
  json :: forall (p :: * -> * -> *). JsonVal p => p Word8 Word8
json = p Word8 Word8 -> p Word8 Word8
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Word8 Word8
forall (p :: * -> * -> *). JsonVal p => p Word8 Word8
jsonWord8
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Word8 Word8)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Word8 Word8)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Word8 Word8)
forall a. a -> Maybe a
Just (APrism' Scientific Word8 -> k Word8 Word8
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Word8
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Word8
_BoundedInteger)
instance Json Word16 where
  json :: forall (p :: * -> * -> *). JsonVal p => p Word16 Word16
json = p Word16 Word16 -> p Word16 Word16
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Word16 Word16
forall (p :: * -> * -> *). JsonVal p => p Word16 Word16
jsonWord16
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Word16 Word16)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Word16 Word16)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Word16 Word16)
forall a. a -> Maybe a
Just (APrism' Scientific Word16 -> k Word16 Word16
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Word16
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Word16
_BoundedInteger)
instance Json Word32 where
  json :: forall (p :: * -> * -> *). JsonVal p => p Word32 Word32
json = p Word32 Word32 -> p Word32 Word32
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Word32 Word32
forall (p :: * -> * -> *). JsonVal p => p Word32 Word32
jsonWord32
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Word32 Word32)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Word32 Word32)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Word32 Word32)
forall a. a -> Maybe a
Just (APrism' Scientific Word32 -> k Word32 Word32
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Word32
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Word32
_BoundedInteger)
instance Json Word64 where
  json :: forall (p :: * -> * -> *). JsonVal p => p Word64 Word64
json = p Word64 Word64 -> p Word64 Word64
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Word64 Word64
forall (p :: * -> * -> *). JsonVal p => p Word64 Word64
jsonWord64
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Word64 Word64)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Word64 Word64)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Word64 Word64)
forall a. a -> Maybe a
Just (APrism' Scientific Word64 -> k Word64 Word64
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey APrism' Scientific Word64
forall a. (Integral a, Bounded a) => Prism' Scientific a
Prism' Scientific Word64
_BoundedInteger)
instance Json Integer where
  json :: forall (p :: * -> * -> *). JsonVal p => p Integer Integer
json = p Integer Integer -> p Integer Integer
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Integer Integer
forall (p :: * -> * -> *). JsonVal p => p Integer Integer
jsonInteger
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Integer Integer)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Integer Integer)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k Integer Integer)
forall a. a -> Maybe a
Just ((Market Integer Integer Integer (Identity Integer)
 -> Market Integer Integer Scientific (Identity Scientific))
-> k Integer Integer
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey Market Integer Integer Integer (Identity Integer)
-> Market Integer Integer Scientific (Identity Scientific)
Prism' Scientific Integer
_Integer)
instance Json Natural where
  json :: forall (p :: * -> * -> *). JsonVal p => p Natural Natural
json = p Natural Natural -> p Natural Natural
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Natural Natural
forall (p :: * -> * -> *). JsonVal p => p Natural Natural
jsonNatural
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Natural Natural)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Natural Natural)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k Natural Natural)
forall a. a -> Maybe a
Just ((Market Natural Natural Natural (Identity Natural)
 -> Market Natural Natural Scientific (Identity Scientific))
-> k Natural Natural
forall a (p :: * -> * -> *).
(Show a, JsonStr p) =>
APrism' Scientific a -> p a a
jsonIntKey Market Natural Natural Natural (Identity Natural)
-> Market Natural Natural Scientific (Identity Scientific)
Prism' Scientific Natural
_Natural)
instance Json CTime where json :: forall (p :: * -> * -> *). JsonVal p => p CTime CTime
json = Exchange Int64 Int64 Int64 (Identity Int64)
-> Exchange Int64 Int64 CTime (Identity CTime)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso CTime CTime Int64 Int64
coerced (Exchange Int64 Int64 Int64 (Identity Int64)
 -> Exchange Int64 Int64 CTime (Identity CTime))
-> p Int64 Int64 -> p CTime CTime
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @Int64

jsonVersion :: JsonStr p => p Version Version
jsonVersion :: forall (p :: * -> * -> *). JsonStr p => p Version Version
jsonVersion = (Version -> Text)
-> (Text -> Maybe Version) -> Prism Text Text Version Version
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (String -> Text
Text.pack (String -> Text) -> (Version -> String) -> Version -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Version -> String
showVersion) Text -> Maybe Version
version (Market Version Version Version (Identity Version)
 -> Market Version Version Text (Identity Text))
-> p Text Text -> p Version Version
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
  where
    version :: Text -> Maybe Version
version Text
t =
      [Version] -> Maybe Version
forall a. [a] -> Maybe a
listToMaybe [Version
v | (Version
v, String
"") <- ReadP Version -> ReadS Version
forall a. ReadP a -> ReadS a
readP_to_S ReadP Version
parseVersion (Text -> String
Text.unpack Text
t)]

instance Json Version where
  json :: forall (p :: * -> * -> *). JsonVal p => p Version Version
json = p Version Version -> p Version Version
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p Version Version
forall (p :: * -> * -> *). JsonStr p => p Version Version
jsonVersion
  jsonKey :: Maybe (forall (p :: * -> * -> *). JsonStr p => p Version Version)
jsonKey = (forall (p :: * -> * -> *). JsonStr p => p Version Version)
-> Maybe
     (forall (p :: * -> * -> *). JsonStr p => p Version Version)
forall a. a -> Maybe a
Just k Version Version
forall (p :: * -> * -> *). JsonStr p => p Version Version
jsonVersion
instance Json a => Json (NonEmpty a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (NonEmpty a) (NonEmpty a)
json = (NonEmpty a -> [a])
-> ([a] -> Maybe (NonEmpty a))
-> Prism [a] [a] (NonEmpty a) (NonEmpty a)
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList [a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty (Market
   (NonEmpty a) (NonEmpty a) (NonEmpty a) (Identity (NonEmpty a))
 -> Market (NonEmpty a) (NonEmpty a) [a] (Identity [a]))
-> p [a] [a] -> p (NonEmpty a) (NonEmpty a)
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< (forall (q :: * -> * -> *). JsonTup p q => q [a] [a]) -> p [a] [a]
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple (q a a -> q [a] [a]
forall a b. q a b -> q [a] [b]
forall (p :: * -> * -> *) a b. Alternator p => p a b -> p [a] [b]
someP (p a a -> q a a
forall a b. p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonTup p q =>
p a b -> q a b
jsonElem p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json))
instance Json a => Json (Solo a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Solo a) (Solo a)
json = (Solo a -> a) -> (a -> Solo a) -> Iso (Solo a) (Solo a) a a
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Solo a -> a
forall a. Solo a -> a
getSolo a -> Solo a
forall a. a -> Solo a
MkSolo (Exchange a a a (Identity a)
 -> Exchange a a (Solo a) (Identity (Solo a)))
-> p a a -> p (Solo a) (Solo a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [Solo a] [Solo a]
jsonList = ([Solo a] -> [a])
-> ([a] -> [Solo a]) -> Iso [Solo a] [Solo a] [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((Solo a -> a) -> [Solo a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map Solo a -> a
forall a. Solo a -> a
getSolo) ((a -> Solo a) -> [a] -> [Solo a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Solo a
forall a. a -> Solo a
MkSolo) (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Solo a] (Identity [Solo a]))
-> p [a] [a] -> p [Solo a] [Solo a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k (Solo a) (Solo a))
jsonKey = (forall (k :: * -> * -> *).
 JsonStr k =>
 k a a -> k (Solo a) (Solo a))
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k (Solo a) (Solo a))
forall a b.
(forall (k :: * -> * -> *). JsonStr k => k a a -> k b b)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
overKey ((Solo a -> a) -> (a -> Solo a) -> Iso (Solo a) (Solo a) a a
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Solo a -> a
forall a. Solo a -> a
getSolo a -> Solo a
forall a. a -> Solo a
MkSolo (Exchange a a a (Identity a)
 -> Exchange a a (Solo a) (Identity (Solo a)))
-> k a a -> k (Solo a) (Solo a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~) (forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
jsonKey @a)
  jsonKeyList :: Maybe (forall (k :: * -> * -> *). JsonStr k => k [Solo a] [Solo a])
jsonKeyList = (forall (k :: * -> * -> *).
 JsonStr k =>
 k [a] [a] -> k [Solo a] [Solo a])
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k [Solo a] [Solo a])
forall a b.
(forall (k :: * -> * -> *). JsonStr k => k a a -> k b b)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
overKey (([Solo a] -> [a])
-> ([a] -> [Solo a]) -> Iso [Solo a] [Solo a] [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((Solo a -> a) -> [Solo a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map Solo a -> a
forall a. Solo a -> a
getSolo) ((a -> Solo a) -> [a] -> [Solo a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Solo a
forall a. a -> Solo a
MkSolo) (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Solo a] (Identity [Solo a]))
-> k [a] [a] -> k [Solo a] [Solo a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~) (forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
jsonKeyList @a)
instance Json a => Json (Identity a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Identity a) (Identity a)
json = Exchange a a a (Identity a)
-> Exchange a a (Identity a) (Identity (Identity a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Identity a) (Identity a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Identity a) (Identity (Identity a)))
-> p a a -> p (Identity a) (Identity a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonOmitField :: Maybe (APrism' (Identity a) ())
jsonOmitField = (Market () () a (Identity a)
-> Market () () (Identity a) (Identity (Identity a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Identity a) (Identity a) a a
coerced (Market () () a (Identity a)
 -> Market () () (Identity a) (Identity (Identity a)))
-> (Market () () () (Identity ()) -> Market () () a (Identity a))
-> APrism' (Identity a) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Market () () () (Identity ()) -> Market () () a (Identity a))
 -> APrism' (Identity a) ())
-> Maybe
     (Market () () () (Identity ()) -> Market () () a (Identity a))
-> Maybe (APrism' (Identity a) ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Json a => Maybe (APrism' a ())
jsonOmitField @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [Identity a] [Identity a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [Identity a] (Identity [Identity a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Identity a] [Identity a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Identity a] (Identity [Identity a]))
-> p [a] [a] -> p [Identity a] [Identity a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
  jsonKey :: Maybe
  (forall (k :: * -> * -> *).
   JsonStr k =>
   k (Identity a) (Identity a))
jsonKey = (forall (k :: * -> * -> *).
 JsonStr k =>
 k a a -> k (Identity a) (Identity a))
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe
     (forall (k :: * -> * -> *).
      JsonStr k =>
      k (Identity a) (Identity a))
forall a b.
(forall (k :: * -> * -> *). JsonStr k => k a a -> k b b)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
overKey (Exchange a a a (Identity a)
-> Exchange a a (Identity a) (Identity (Identity a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Identity a) (Identity a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Identity a) (Identity (Identity a)))
-> k a a -> k (Identity a) (Identity a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~) (forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
jsonKey @a)
  jsonKeyList :: Maybe
  (forall (k :: * -> * -> *).
   JsonStr k =>
   k [Identity a] [Identity a])
jsonKeyList = (forall (k :: * -> * -> *).
 JsonStr k =>
 k [a] [a] -> k [Identity a] [Identity a])
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
-> Maybe
     (forall (k :: * -> * -> *).
      JsonStr k =>
      k [Identity a] [Identity a])
forall a b.
(forall (k :: * -> * -> *). JsonStr k => k a a -> k b b)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
overKey (Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [Identity a] (Identity [Identity a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Identity a] [Identity a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Identity a] (Identity [Identity a]))
-> k [a] [a] -> k [Identity a] [Identity a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~) (forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
jsonKeyList @a)
instance Json a => Json (Const a b) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Const a b) (Const a b)
json = Exchange a a a (Identity a)
-> Exchange a a (Const a b) (Identity (Const a b))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Const a b) (Const a b) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Const a b) (Identity (Const a b)))
-> p a a -> p (Const a b) (Const a b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonOmitField :: Maybe (APrism' (Const a b) ())
jsonOmitField = (Market () () a (Identity a)
-> Market () () (Const a b) (Identity (Const a b))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Const a b) (Const a b) a a
coerced (Market () () a (Identity a)
 -> Market () () (Const a b) (Identity (Const a b)))
-> (Market () () () (Identity ()) -> Market () () a (Identity a))
-> APrism' (Const a b) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Market () () () (Identity ()) -> Market () () a (Identity a))
 -> APrism' (Const a b) ())
-> Maybe
     (Market () () () (Identity ()) -> Market () () a (Identity a))
-> Maybe (APrism' (Const a b) ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Json a => Maybe (APrism' a ())
jsonOmitField @a
  jsonKey :: Maybe
  (forall (k :: * -> * -> *). JsonStr k => k (Const a b) (Const a b))
jsonKey = (forall (k :: * -> * -> *).
 JsonStr k =>
 k a a -> k (Const a b) (Const a b))
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k (Const a b) (Const a b))
forall a b.
(forall (k :: * -> * -> *). JsonStr k => k a a -> k b b)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
overKey (Exchange a a a (Identity a)
-> Exchange a a (Const a b) (Identity (Const a b))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Const a b) (Const a b) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Const a b) (Identity (Const a b)))
-> k a a -> k (Const a b) (Const a b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~) (forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
jsonKey @a)
instance Json (f (g a)) => Json (Compose f g a) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (Compose f g a) (Compose f g a)
json = Exchange (f (g a)) (f (g a)) (f (g a)) (Identity (f (g a)))
-> Exchange
     (f (g a)) (f (g a)) (Compose f g a) (Identity (Compose f g a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Compose f g a) (Compose f g a) (f (g a)) (f (g a))
coerced (Exchange (f (g a)) (f (g a)) (f (g a)) (Identity (f (g a)))
 -> Exchange
      (f (g a)) (f (g a)) (Compose f g a) (Identity (Compose f g a)))
-> p (f (g a)) (f (g a)) -> p (Compose f g a) (Compose f g a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(f (g a))
instance (Json (f a), Json (g a)) => Json (Functor.Product f g a) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (Product f g a) (Product f g a)
json = p (Product f g a) (Product f g a)
forall a (d :: Meta) (c :: Meta) (f :: * -> *) (p :: * -> * -> *).
(Generic a, Rep a ~ D1 d (C1 c f), GElements f, JsonVal p) =>
p a a
gtuple
instance (Json (f a), Json (g a)) => Json (Functor.Sum f g a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Sum f g a) (Sum f g a)
json = (Sum f g a -> Either (f a) (g a))
-> (Either (f a) (g a) -> Sum f g a)
-> Iso
     (Sum f g a) (Sum f g a) (Either (f a) (g a)) (Either (f a) (g a))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
    (\case Functor.InL f a
x -> f a -> Either (f a) (g a)
forall a b. a -> Either a b
Left f a
x; Functor.InR g a
y -> g a -> Either (f a) (g a)
forall a b. b -> Either a b
Right g a
y)
    ((f a -> Sum f g a)
-> (g a -> Sum f g a) -> Either (f a) (g a) -> Sum f g a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either f a -> Sum f g a
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
Functor.InL g a -> Sum f g a
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
Functor.InR)
    (Exchange
   (Either (f a) (g a))
   (Either (f a) (g a))
   (Either (f a) (g a))
   (Identity (Either (f a) (g a)))
 -> Exchange
      (Either (f a) (g a))
      (Either (f a) (g a))
      (Sum f g a)
      (Identity (Sum f g a)))
-> p (Either (f a) (g a)) (Either (f a) (g a))
-> p (Sum f g a) (Sum f g a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ Text -> p (f a) (f a) -> p (f a) (f a)
forall a b. Text -> p a b -> p a b
forall (p :: * -> * -> *) a b. JsonVal p => Text -> p a b -> p a b
jsonTag Text
"InL" p (f a) (f a)
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p (f a) (f a)
json p (f a) (f a)
-> p (g a) (g a) -> p (Either (f a) (g a)) (Either (f a) (g a))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< Text -> p (g a) (g a) -> p (g a) (g a)
forall a b. Text -> p a b -> p a b
forall (p :: * -> * -> *) a b. JsonVal p => Text -> p a b -> p a b
jsonTag Text
"InR" p (g a) (g a)
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p (g a) (g a)
json
instance Json a => Json (Down a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Down a) (Down a)
json = Exchange a a a (Identity a)
-> Exchange a a (Down a) (Identity (Down a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Down a) (Down a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Down a) (Identity (Down a)))
-> p a a -> p (Down a) (Down a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [Down a] [Down a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [Down a] (Identity [Down a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Down a] [Down a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Down a] (Identity [Down a]))
-> p [a] [a] -> p [Down a] [Down a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
instance Json a => Json (Monoid.Dual a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Dual a) (Dual a)
json = Exchange a a a (Identity a)
-> Exchange a a (Dual a) (Identity (Dual a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Dual a) (Dual a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Dual a) (Identity (Dual a)))
-> p a a -> p (Dual a) (Dual a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [Dual a] [Dual a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [Dual a] (Identity [Dual a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Dual a] [Dual a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Dual a] (Identity [Dual a]))
-> p [a] [a] -> p [Dual a] [Dual a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
instance Json a => Json (Monoid.First a) where json :: forall (p :: * -> * -> *). JsonVal p => p (First a) (First a)
json = Exchange (Maybe a) (Maybe a) (Maybe a) (Identity (Maybe a))
-> Exchange (Maybe a) (Maybe a) (First a) (Identity (First a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (First a) (First a) (Maybe a) (Maybe a)
coerced (Exchange (Maybe a) (Maybe a) (Maybe a) (Identity (Maybe a))
 -> Exchange (Maybe a) (Maybe a) (First a) (Identity (First a)))
-> p (Maybe a) (Maybe a) -> p (First a) (First a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(Maybe a)
instance Json a => Json (Monoid.Last a) where json :: forall (p :: * -> * -> *). JsonVal p => p (Last a) (Last a)
json = Exchange (Maybe a) (Maybe a) (Maybe a) (Identity (Maybe a))
-> Exchange (Maybe a) (Maybe a) (Last a) (Identity (Last a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Last a) (Last a) (Maybe a) (Maybe a)
coerced (Exchange (Maybe a) (Maybe a) (Maybe a) (Identity (Maybe a))
 -> Exchange (Maybe a) (Maybe a) (Last a) (Identity (Last a)))
-> p (Maybe a) (Maybe a) -> p (Last a) (Last a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(Maybe a)
instance Json a => Json (Semigroup.Min a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Min a) (Min a)
json = Exchange a a a (Identity a)
-> Exchange a a (Min a) (Identity (Min a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Min a) (Min a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Min a) (Identity (Min a)))
-> p a a -> p (Min a) (Min a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [Min a] [Min a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [Min a] (Identity [Min a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Min a] [Min a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Min a] (Identity [Min a]))
-> p [a] [a] -> p [Min a] [Min a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
instance Json a => Json (Semigroup.Max a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Max a) (Max a)
json = Exchange a a a (Identity a)
-> Exchange a a (Max a) (Identity (Max a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Max a) (Max a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Max a) (Identity (Max a)))
-> p a a -> p (Max a) (Max a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [Max a] [Max a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [Max a] (Identity [Max a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Max a] [Max a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Max a] (Identity [Max a]))
-> p [a] [a] -> p [Max a] [Max a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
instance Json a => Json (Semigroup.First a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (First a) (First a)
json = Exchange a a a (Identity a)
-> Exchange a a (First a) (Identity (First a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (First a) (First a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (First a) (Identity (First a)))
-> p a a -> p (First a) (First a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [First a] [First a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [First a] (Identity [First a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [First a] [First a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [First a] (Identity [First a]))
-> p [a] [a] -> p [First a] [First a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
instance Json a => Json (Semigroup.Last a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Last a) (Last a)
json = Exchange a a a (Identity a)
-> Exchange a a (Last a) (Identity (Last a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Last a) (Last a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Last a) (Identity (Last a)))
-> p a a -> p (Last a) (Last a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [Last a] [Last a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [Last a] (Identity [Last a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Last a] [Last a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Last a] (Identity [Last a]))
-> p [a] [a] -> p [Last a] [Last a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
instance Json a => Json (Semigroup.WrappedMonoid a) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (WrappedMonoid a) (WrappedMonoid a)
json = Exchange a a a (Identity a)
-> Exchange a a (WrappedMonoid a) (Identity (WrappedMonoid a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (WrappedMonoid a) (WrappedMonoid a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (WrappedMonoid a) (Identity (WrappedMonoid a)))
-> p a a -> p (WrappedMonoid a) (WrappedMonoid a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *).
JsonVal p =>
p [WrappedMonoid a] [WrappedMonoid a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [WrappedMonoid a] (Identity [WrappedMonoid a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [WrappedMonoid a] [WrappedMonoid a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [WrappedMonoid a] (Identity [WrappedMonoid a]))
-> p [a] [a] -> p [WrappedMonoid a] [WrappedMonoid a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
instance Json a => Json (Semigroup.Sum a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Sum a) (Sum a)
json = Exchange a a a (Identity a)
-> Exchange a a (Sum a) (Identity (Sum a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Sum a) (Sum a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Sum a) (Identity (Sum a)))
-> p a a -> p (Sum a) (Sum a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [Sum a] [Sum a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [Sum a] (Identity [Sum a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Sum a] [Sum a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Sum a] (Identity [Sum a]))
-> p [a] [a] -> p [Sum a] [Sum a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
instance Json a => Json (Semigroup.Product a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Product a) (Product a)
json = Exchange a a a (Identity a)
-> Exchange a a (Product a) (Identity (Product a))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Product a) (Product a) a a
coerced (Exchange a a a (Identity a)
 -> Exchange a a (Product a) (Identity (Product a)))
-> p a a -> p (Product a) (Product a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @a
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [Product a] [Product a]
jsonList = Exchange [a] [a] [a] (Identity [a])
-> Exchange [a] [a] [Product a] (Identity [Product a])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Product a] [Product a] [a] [a]
coerced (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] [Product a] (Identity [Product a]))
-> p [a] [a] -> p [Product a] [Product a]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p [a] [a]
jsonList @a
instance Json Semigroup.All where json :: forall (p :: * -> * -> *). JsonVal p => p All All
json = Exchange Bool Bool Bool (Identity Bool)
-> Exchange Bool Bool All (Identity All)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso All All Bool Bool
coerced (Exchange Bool Bool Bool (Identity Bool)
 -> Exchange Bool Bool All (Identity All))
-> p Bool Bool -> p All All
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @Bool
instance Json Semigroup.Any where json :: forall (p :: * -> * -> *). JsonVal p => p Any Any
json = Exchange Bool Bool Bool (Identity Bool)
-> Exchange Bool Bool Any (Identity Any)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso Any Any Bool Bool
coerced (Exchange Bool Bool Bool (Identity Bool)
 -> Exchange Bool Bool Any (Identity Any))
-> p Bool Bool -> p Any Any
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @Bool
instance Json (Proxy a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Proxy a) (Proxy a)
json = (Proxy a -> ())
-> (() -> Proxy a) -> p () () -> p (Proxy a) (Proxy a)
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 (() -> Proxy a -> ()
forall a b. a -> b -> a
const ()) (Proxy a -> () -> Proxy a
forall a b. a -> b -> a
const Proxy a
forall {k} (t :: k). Proxy t
Proxy) p () ()
forall (p :: * -> * -> *). JsonVal p => p () ()
jsonNull
  jsonOmitField :: Maybe (APrism' (Proxy a) ())
jsonOmitField = APrism' (Proxy a) () -> Maybe (APrism' (Proxy a) ())
forall a. a -> Maybe a
Just (Proxy a -> Prism' (Proxy a) ()
forall a. Eq a => a -> Prism' a ()
only Proxy a
forall {k} (t :: k). Proxy t
Proxy)
-- tuples
-- | An element of a tuple, by its projection.
projectElem :: (Json a, JsonVal p, JsonTup p q) => (s -> a) -> q s a
projectElem :: forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem s -> a
f = (s -> a) -> q a a -> q s a
forall a b c. (a -> b) -> q b c -> q a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap s -> a
f (p a a -> q a a
forall a b. p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonTup p q =>
p a b -> q a b
jsonElem p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json)
{-# INLINE projectElem #-}

instance (Json a, Json b) => Json (a, b) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (a, b) (a, b)
json = p a a -> p b b -> p (a, b) (a, b)
forall a b c d. p a b -> p c d -> p (a, c) (b, d)
forall (p :: * -> * -> *) a b c d.
JsonVal p =>
p a b -> p c d -> p (a, c) (b, d)
jsonPair p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json p b b
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p b b
json
  {-# INLINE json #-}
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [(a, b)] [(a, b)]
jsonList = p (a, b) (a, b) -> p [(a, b)] [(a, b)]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p (a, b) (a, b)
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p (a, b) (a, b)
json
  {-# INLINE jsonList #-}
instance (Json a, Json b, Json c) => Json (a, b, c) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (a, b, c) (a, b, c)
json = (forall (q :: * -> * -> *). JsonTup p q => q (a, b, c) (a, b, c))
-> p (a, b, c) (a, b, c)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *). JsonTup p q => q (a, b, c) (a, b, c))
 -> p (a, b, c) (a, b, c))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c) (a, b, c))
-> p (a, b, c) (a, b, c)
forall a b. (a -> b) -> a -> b
$ (,,)
    (a -> b -> c -> (a, b, c))
-> q (a, b, c) a -> q (a, b, c) (b -> c -> (a, b, c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c) -> a) -> q (a, b, c) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_) -> a
a)
    q (a, b, c) (b -> c -> (a, b, c))
-> q (a, b, c) b -> q (a, b, c) (c -> (a, b, c))
forall a b. q (a, b, c) (a -> b) -> q (a, b, c) a -> q (a, b, c) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c) -> b) -> q (a, b, c) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_) -> b
b)
    q (a, b, c) (c -> (a, b, c))
-> q (a, b, c) c -> q (a, b, c) (a, b, c)
forall a b. q (a, b, c) (a -> b) -> q (a, b, c) a -> q (a, b, c) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c) -> c) -> q (a, b, c) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c) -> c
c)
  {-# INLINE json #-}
  jsonList :: forall (p :: * -> * -> *). JsonVal p => p [(a, b, c)] [(a, b, c)]
jsonList = p (a, b, c) (a, b, c) -> p [(a, b, c)] [(a, b, c)]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p (a, b, c) (a, b, c)
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p (a, b, c) (a, b, c)
json
  {-# INLINE jsonList #-}
instance (Json a, Json b, Json c, Json d) => Json (a, b, c, d) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (a, b, c, d) (a, b, c, d)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d) (a, b, c, d))
-> p (a, b, c, d) (a, b, c, d)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d) (a, b, c, d))
 -> p (a, b, c, d) (a, b, c, d))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d) (a, b, c, d))
-> p (a, b, c, d) (a, b, c, d)
forall a b. (a -> b) -> a -> b
$ (,,,)
    (a -> b -> c -> d -> (a, b, c, d))
-> q (a, b, c, d) a -> q (a, b, c, d) (b -> c -> d -> (a, b, c, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d) -> a) -> q (a, b, c, d) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_) -> a
a)
    q (a, b, c, d) (b -> c -> d -> (a, b, c, d))
-> q (a, b, c, d) b -> q (a, b, c, d) (c -> d -> (a, b, c, d))
forall a b.
q (a, b, c, d) (a -> b) -> q (a, b, c, d) a -> q (a, b, c, d) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d) -> b) -> q (a, b, c, d) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_) -> b
b)
    q (a, b, c, d) (c -> d -> (a, b, c, d))
-> q (a, b, c, d) c -> q (a, b, c, d) (d -> (a, b, c, d))
forall a b.
q (a, b, c, d) (a -> b) -> q (a, b, c, d) a -> q (a, b, c, d) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d) -> c) -> q (a, b, c, d) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_) -> c
c)
    q (a, b, c, d) (d -> (a, b, c, d))
-> q (a, b, c, d) d -> q (a, b, c, d) (a, b, c, d)
forall a b.
q (a, b, c, d) (a -> b) -> q (a, b, c, d) a -> q (a, b, c, d) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d) -> d) -> q (a, b, c, d) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d) -> d
d)
instance (Json a, Json b, Json c, Json d, Json e) => Json (a, b, c, d, e) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e) (a, b, c, d, e)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e) (a, b, c, d, e))
-> p (a, b, c, d, e) (a, b, c, d, e)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e) (a, b, c, d, e))
 -> p (a, b, c, d, e) (a, b, c, d, e))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e) (a, b, c, d, e))
-> p (a, b, c, d, e) (a, b, c, d, e)
forall a b. (a -> b) -> a -> b
$ (,,,,)
    (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> q (a, b, c, d, e) a
-> q (a, b, c, d, e) (b -> c -> d -> e -> (a, b, c, d, e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e) -> a) -> q (a, b, c, d, e) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_) -> a
a)
    q (a, b, c, d, e) (b -> c -> d -> e -> (a, b, c, d, e))
-> q (a, b, c, d, e) b
-> q (a, b, c, d, e) (c -> d -> e -> (a, b, c, d, e))
forall a b.
q (a, b, c, d, e) (a -> b)
-> q (a, b, c, d, e) a -> q (a, b, c, d, e) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e) -> b) -> q (a, b, c, d, e) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_) -> b
b)
    q (a, b, c, d, e) (c -> d -> e -> (a, b, c, d, e))
-> q (a, b, c, d, e) c
-> q (a, b, c, d, e) (d -> e -> (a, b, c, d, e))
forall a b.
q (a, b, c, d, e) (a -> b)
-> q (a, b, c, d, e) a -> q (a, b, c, d, e) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e) -> c) -> q (a, b, c, d, e) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_) -> c
c)
    q (a, b, c, d, e) (d -> e -> (a, b, c, d, e))
-> q (a, b, c, d, e) d -> q (a, b, c, d, e) (e -> (a, b, c, d, e))
forall a b.
q (a, b, c, d, e) (a -> b)
-> q (a, b, c, d, e) a -> q (a, b, c, d, e) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e) -> d) -> q (a, b, c, d, e) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_) -> d
d)
    q (a, b, c, d, e) (e -> (a, b, c, d, e))
-> q (a, b, c, d, e) e -> q (a, b, c, d, e) (a, b, c, d, e)
forall a b.
q (a, b, c, d, e) (a -> b)
-> q (a, b, c, d, e) a -> q (a, b, c, d, e) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e) -> e) -> q (a, b, c, d, e) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e) -> e
e)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f )
  => Json (a, b, c, d, e, f) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f) (a, b, c, d, e, f)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f) (a, b, c, d, e, f))
-> p (a, b, c, d, e, f) (a, b, c, d, e, f)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f) (a, b, c, d, e, f))
 -> p (a, b, c, d, e, f) (a, b, c, d, e, f))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f) (a, b, c, d, e, f))
-> p (a, b, c, d, e, f) (a, b, c, d, e, f)
forall a b. (a -> b) -> a -> b
$ (,,,,,)
    (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> q (a, b, c, d, e, f) a
-> q (a, b, c, d, e, f)
     (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f) -> a) -> q (a, b, c, d, e, f) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_) -> a
a)
    q (a, b, c, d, e, f) (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> q (a, b, c, d, e, f) b
-> q (a, b, c, d, e, f) (c -> d -> e -> f -> (a, b, c, d, e, f))
forall a b.
q (a, b, c, d, e, f) (a -> b)
-> q (a, b, c, d, e, f) a -> q (a, b, c, d, e, f) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f) -> b) -> q (a, b, c, d, e, f) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_) -> b
b)
    q (a, b, c, d, e, f) (c -> d -> e -> f -> (a, b, c, d, e, f))
-> q (a, b, c, d, e, f) c
-> q (a, b, c, d, e, f) (d -> e -> f -> (a, b, c, d, e, f))
forall a b.
q (a, b, c, d, e, f) (a -> b)
-> q (a, b, c, d, e, f) a -> q (a, b, c, d, e, f) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f) -> c) -> q (a, b, c, d, e, f) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_) -> c
c)
    q (a, b, c, d, e, f) (d -> e -> f -> (a, b, c, d, e, f))
-> q (a, b, c, d, e, f) d
-> q (a, b, c, d, e, f) (e -> f -> (a, b, c, d, e, f))
forall a b.
q (a, b, c, d, e, f) (a -> b)
-> q (a, b, c, d, e, f) a -> q (a, b, c, d, e, f) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f) -> d) -> q (a, b, c, d, e, f) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_) -> d
d)
    q (a, b, c, d, e, f) (e -> f -> (a, b, c, d, e, f))
-> q (a, b, c, d, e, f) e
-> q (a, b, c, d, e, f) (f -> (a, b, c, d, e, f))
forall a b.
q (a, b, c, d, e, f) (a -> b)
-> q (a, b, c, d, e, f) a -> q (a, b, c, d, e, f) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f) -> e) -> q (a, b, c, d, e, f) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_) -> e
e)
    q (a, b, c, d, e, f) (f -> (a, b, c, d, e, f))
-> q (a, b, c, d, e, f) f
-> q (a, b, c, d, e, f) (a, b, c, d, e, f)
forall a b.
q (a, b, c, d, e, f) (a -> b)
-> q (a, b, c, d, e, f) a -> q (a, b, c, d, e, f) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f) -> f) -> q (a, b, c, d, e, f) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f) -> f
f)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f, Json g )
  => Json (a, b, c, d, e, f, g) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f, g) (a, b, c, d, e, f, g)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f, g) (a, b, c, d, e, f, g))
-> p (a, b, c, d, e, f, g) (a, b, c, d, e, f, g)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f, g) (a, b, c, d, e, f, g))
 -> p (a, b, c, d, e, f, g) (a, b, c, d, e, f, g))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f, g) (a, b, c, d, e, f, g))
-> p (a, b, c, d, e, f, g) (a, b, c, d, e, f, g)
forall a b. (a -> b) -> a -> b
$ (,,,,,,)
    (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> q (a, b, c, d, e, f, g) a
-> q (a, b, c, d, e, f, g)
     (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f, g) -> a) -> q (a, b, c, d, e, f, g) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_, g
_) -> a
a)
    q (a, b, c, d, e, f, g)
  (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> q (a, b, c, d, e, f, g) b
-> q (a, b, c, d, e, f, g)
     (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b.
q (a, b, c, d, e, f, g) (a -> b)
-> q (a, b, c, d, e, f, g) a -> q (a, b, c, d, e, f, g) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g) -> b) -> q (a, b, c, d, e, f, g) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_, g
_) -> b
b)
    q (a, b, c, d, e, f, g)
  (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> q (a, b, c, d, e, f, g) c
-> q (a, b, c, d, e, f, g)
     (d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b.
q (a, b, c, d, e, f, g) (a -> b)
-> q (a, b, c, d, e, f, g) a -> q (a, b, c, d, e, f, g) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g) -> c) -> q (a, b, c, d, e, f, g) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_, g
_) -> c
c)
    q (a, b, c, d, e, f, g) (d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> q (a, b, c, d, e, f, g) d
-> q (a, b, c, d, e, f, g) (e -> f -> g -> (a, b, c, d, e, f, g))
forall a b.
q (a, b, c, d, e, f, g) (a -> b)
-> q (a, b, c, d, e, f, g) a -> q (a, b, c, d, e, f, g) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g) -> d) -> q (a, b, c, d, e, f, g) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_, g
_) -> d
d)
    q (a, b, c, d, e, f, g) (e -> f -> g -> (a, b, c, d, e, f, g))
-> q (a, b, c, d, e, f, g) e
-> q (a, b, c, d, e, f, g) (f -> g -> (a, b, c, d, e, f, g))
forall a b.
q (a, b, c, d, e, f, g) (a -> b)
-> q (a, b, c, d, e, f, g) a -> q (a, b, c, d, e, f, g) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g) -> e) -> q (a, b, c, d, e, f, g) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_, g
_) -> e
e)
    q (a, b, c, d, e, f, g) (f -> g -> (a, b, c, d, e, f, g))
-> q (a, b, c, d, e, f, g) f
-> q (a, b, c, d, e, f, g) (g -> (a, b, c, d, e, f, g))
forall a b.
q (a, b, c, d, e, f, g) (a -> b)
-> q (a, b, c, d, e, f, g) a -> q (a, b, c, d, e, f, g) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g) -> f) -> q (a, b, c, d, e, f, g) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f, g
_) -> f
f)
    q (a, b, c, d, e, f, g) (g -> (a, b, c, d, e, f, g))
-> q (a, b, c, d, e, f, g) g
-> q (a, b, c, d, e, f, g) (a, b, c, d, e, f, g)
forall a b.
q (a, b, c, d, e, f, g) (a -> b)
-> q (a, b, c, d, e, f, g) a -> q (a, b, c, d, e, f, g) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g) -> g) -> q (a, b, c, d, e, f, g) g
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
g) -> g
g)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f, Json g, Json h )
  => Json (a, b, c, d, e, f, g, h) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h))
-> p (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h))
 -> p (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h))
-> p (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h)
forall a b. (a -> b) -> a -> b
$ (,,,,,,,)
    (a -> b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> q (a, b, c, d, e, f, g, h) a
-> q (a, b, c, d, e, f, g, h)
     (b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f, g, h) -> a) -> q (a, b, c, d, e, f, g, h) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_, g
_, h
_) -> a
a)
    q (a, b, c, d, e, f, g, h)
  (b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> q (a, b, c, d, e, f, g, h) b
-> q (a, b, c, d, e, f, g, h)
     (c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b.
q (a, b, c, d, e, f, g, h) (a -> b)
-> q (a, b, c, d, e, f, g, h) a -> q (a, b, c, d, e, f, g, h) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h) -> b) -> q (a, b, c, d, e, f, g, h) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_, g
_, h
_) -> b
b)
    q (a, b, c, d, e, f, g, h)
  (c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> q (a, b, c, d, e, f, g, h) c
-> q (a, b, c, d, e, f, g, h)
     (d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b.
q (a, b, c, d, e, f, g, h) (a -> b)
-> q (a, b, c, d, e, f, g, h) a -> q (a, b, c, d, e, f, g, h) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h) -> c) -> q (a, b, c, d, e, f, g, h) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_, g
_, h
_) -> c
c)
    q (a, b, c, d, e, f, g, h)
  (d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> q (a, b, c, d, e, f, g, h) d
-> q (a, b, c, d, e, f, g, h)
     (e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b.
q (a, b, c, d, e, f, g, h) (a -> b)
-> q (a, b, c, d, e, f, g, h) a -> q (a, b, c, d, e, f, g, h) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h) -> d) -> q (a, b, c, d, e, f, g, h) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_, g
_, h
_) -> d
d)
    q (a, b, c, d, e, f, g, h)
  (e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> q (a, b, c, d, e, f, g, h) e
-> q (a, b, c, d, e, f, g, h)
     (f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b.
q (a, b, c, d, e, f, g, h) (a -> b)
-> q (a, b, c, d, e, f, g, h) a -> q (a, b, c, d, e, f, g, h) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h) -> e) -> q (a, b, c, d, e, f, g, h) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_, g
_, h
_) -> e
e)
    q (a, b, c, d, e, f, g, h)
  (f -> g -> h -> (a, b, c, d, e, f, g, h))
-> q (a, b, c, d, e, f, g, h) f
-> q (a, b, c, d, e, f, g, h) (g -> h -> (a, b, c, d, e, f, g, h))
forall a b.
q (a, b, c, d, e, f, g, h) (a -> b)
-> q (a, b, c, d, e, f, g, h) a -> q (a, b, c, d, e, f, g, h) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h) -> f) -> q (a, b, c, d, e, f, g, h) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f, g
_, h
_) -> f
f)
    q (a, b, c, d, e, f, g, h) (g -> h -> (a, b, c, d, e, f, g, h))
-> q (a, b, c, d, e, f, g, h) g
-> q (a, b, c, d, e, f, g, h) (h -> (a, b, c, d, e, f, g, h))
forall a b.
q (a, b, c, d, e, f, g, h) (a -> b)
-> q (a, b, c, d, e, f, g, h) a -> q (a, b, c, d, e, f, g, h) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h) -> g) -> q (a, b, c, d, e, f, g, h) g
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
g, h
_) -> g
g)
    q (a, b, c, d, e, f, g, h) (h -> (a, b, c, d, e, f, g, h))
-> q (a, b, c, d, e, f, g, h) h
-> q (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h)
forall a b.
q (a, b, c, d, e, f, g, h) (a -> b)
-> q (a, b, c, d, e, f, g, h) a -> q (a, b, c, d, e, f, g, h) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h) -> h) -> q (a, b, c, d, e, f, g, h) h
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
h) -> h
h)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f, Json g, Json h, Json i )
  => Json (a, b, c, d, e, f, g, h, i) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i))
-> p (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i))
 -> p (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i))
-> p (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i)
forall a b. (a -> b) -> a -> b
$ (,,,,,,,,)
    (a
 -> b
 -> c
 -> d
 -> e
 -> f
 -> g
 -> h
 -> i
 -> (a, b, c, d, e, f, g, h, i))
-> q (a, b, c, d, e, f, g, h, i) a
-> q (a, b, c, d, e, f, g, h, i)
     (b
      -> c -> d -> e -> f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f, g, h, i) -> a)
-> q (a, b, c, d, e, f, g, h, i) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_) -> a
a)
    q (a, b, c, d, e, f, g, h, i)
  (b
   -> c -> d -> e -> f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
-> q (a, b, c, d, e, f, g, h, i) b
-> q (a, b, c, d, e, f, g, h, i)
     (c -> d -> e -> f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
forall a b.
q (a, b, c, d, e, f, g, h, i) (a -> b)
-> q (a, b, c, d, e, f, g, h, i) a
-> q (a, b, c, d, e, f, g, h, i) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i) -> b)
-> q (a, b, c, d, e, f, g, h, i) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_, g
_, h
_, i
_) -> b
b)
    q (a, b, c, d, e, f, g, h, i)
  (c -> d -> e -> f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
-> q (a, b, c, d, e, f, g, h, i) c
-> q (a, b, c, d, e, f, g, h, i)
     (d -> e -> f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
forall a b.
q (a, b, c, d, e, f, g, h, i) (a -> b)
-> q (a, b, c, d, e, f, g, h, i) a
-> q (a, b, c, d, e, f, g, h, i) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i) -> c)
-> q (a, b, c, d, e, f, g, h, i) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_, g
_, h
_, i
_) -> c
c)
    q (a, b, c, d, e, f, g, h, i)
  (d -> e -> f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
-> q (a, b, c, d, e, f, g, h, i) d
-> q (a, b, c, d, e, f, g, h, i)
     (e -> f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
forall a b.
q (a, b, c, d, e, f, g, h, i) (a -> b)
-> q (a, b, c, d, e, f, g, h, i) a
-> q (a, b, c, d, e, f, g, h, i) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i) -> d)
-> q (a, b, c, d, e, f, g, h, i) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_, g
_, h
_, i
_) -> d
d)
    q (a, b, c, d, e, f, g, h, i)
  (e -> f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
-> q (a, b, c, d, e, f, g, h, i) e
-> q (a, b, c, d, e, f, g, h, i)
     (f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
forall a b.
q (a, b, c, d, e, f, g, h, i) (a -> b)
-> q (a, b, c, d, e, f, g, h, i) a
-> q (a, b, c, d, e, f, g, h, i) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i) -> e)
-> q (a, b, c, d, e, f, g, h, i) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_, g
_, h
_, i
_) -> e
e)
    q (a, b, c, d, e, f, g, h, i)
  (f -> g -> h -> i -> (a, b, c, d, e, f, g, h, i))
-> q (a, b, c, d, e, f, g, h, i) f
-> q (a, b, c, d, e, f, g, h, i)
     (g -> h -> i -> (a, b, c, d, e, f, g, h, i))
forall a b.
q (a, b, c, d, e, f, g, h, i) (a -> b)
-> q (a, b, c, d, e, f, g, h, i) a
-> q (a, b, c, d, e, f, g, h, i) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i) -> f)
-> q (a, b, c, d, e, f, g, h, i) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f, g
_, h
_, i
_) -> f
f)
    q (a, b, c, d, e, f, g, h, i)
  (g -> h -> i -> (a, b, c, d, e, f, g, h, i))
-> q (a, b, c, d, e, f, g, h, i) g
-> q (a, b, c, d, e, f, g, h, i)
     (h -> i -> (a, b, c, d, e, f, g, h, i))
forall a b.
q (a, b, c, d, e, f, g, h, i) (a -> b)
-> q (a, b, c, d, e, f, g, h, i) a
-> q (a, b, c, d, e, f, g, h, i) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i) -> g)
-> q (a, b, c, d, e, f, g, h, i) g
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
g, h
_, i
_) -> g
g)
    q (a, b, c, d, e, f, g, h, i)
  (h -> i -> (a, b, c, d, e, f, g, h, i))
-> q (a, b, c, d, e, f, g, h, i) h
-> q (a, b, c, d, e, f, g, h, i) (i -> (a, b, c, d, e, f, g, h, i))
forall a b.
q (a, b, c, d, e, f, g, h, i) (a -> b)
-> q (a, b, c, d, e, f, g, h, i) a
-> q (a, b, c, d, e, f, g, h, i) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i) -> h)
-> q (a, b, c, d, e, f, g, h, i) h
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
h, i
_) -> h
h)
    q (a, b, c, d, e, f, g, h, i) (i -> (a, b, c, d, e, f, g, h, i))
-> q (a, b, c, d, e, f, g, h, i) i
-> q (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i)
forall a b.
q (a, b, c, d, e, f, g, h, i) (a -> b)
-> q (a, b, c, d, e, f, g, h, i) a
-> q (a, b, c, d, e, f, g, h, i) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i) -> i)
-> q (a, b, c, d, e, f, g, h, i) i
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
i) -> i
i)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f, Json g, Json h, Json i
  , Json j )
  => Json (a, b, c, d, e, f, g, h, i, j) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f, g, h, i, j) (a, b, c, d, e, f, g, h, i, j)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f, g, h, i, j) (a, b, c, d, e, f, g, h, i, j))
-> p (a, b, c, d, e, f, g, h, i, j) (a, b, c, d, e, f, g, h, i, j)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f, g, h, i, j) (a, b, c, d, e, f, g, h, i, j))
 -> p (a, b, c, d, e, f, g, h, i, j) (a, b, c, d, e, f, g, h, i, j))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f, g, h, i, j) (a, b, c, d, e, f, g, h, i, j))
-> p (a, b, c, d, e, f, g, h, i, j) (a, b, c, d, e, f, g, h, i, j)
forall a b. (a -> b) -> a -> b
$ (,,,,,,,,,)
    (a
 -> b
 -> c
 -> d
 -> e
 -> f
 -> g
 -> h
 -> i
 -> j
 -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j)
     (b
      -> c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> (a, b, c, d, e, f, g, h, i, j))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f, g, h, i, j) -> a)
-> q (a, b, c, d, e, f, g, h, i, j) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_) -> a
a)
    q (a, b, c, d, e, f, g, h, i, j)
  (b
   -> c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) b
-> q (a, b, c, d, e, f, g, h, i, j)
     (c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> (a, b, c, d, e, f, g, h, i, j))
forall a b.
q (a, b, c, d, e, f, g, h, i, j) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j) -> b)
-> q (a, b, c, d, e, f, g, h, i, j) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_) -> b
b)
    q (a, b, c, d, e, f, g, h, i, j)
  (c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) c
-> q (a, b, c, d, e, f, g, h, i, j)
     (d -> e -> f -> g -> h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
forall a b.
q (a, b, c, d, e, f, g, h, i, j) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j) -> c)
-> q (a, b, c, d, e, f, g, h, i, j) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_, g
_, h
_, i
_, j
_) -> c
c)
    q (a, b, c, d, e, f, g, h, i, j)
  (d -> e -> f -> g -> h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) d
-> q (a, b, c, d, e, f, g, h, i, j)
     (e -> f -> g -> h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
forall a b.
q (a, b, c, d, e, f, g, h, i, j) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j) -> d)
-> q (a, b, c, d, e, f, g, h, i, j) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_, g
_, h
_, i
_, j
_) -> d
d)
    q (a, b, c, d, e, f, g, h, i, j)
  (e -> f -> g -> h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) e
-> q (a, b, c, d, e, f, g, h, i, j)
     (f -> g -> h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
forall a b.
q (a, b, c, d, e, f, g, h, i, j) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j) -> e)
-> q (a, b, c, d, e, f, g, h, i, j) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_, g
_, h
_, i
_, j
_) -> e
e)
    q (a, b, c, d, e, f, g, h, i, j)
  (f -> g -> h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) f
-> q (a, b, c, d, e, f, g, h, i, j)
     (g -> h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
forall a b.
q (a, b, c, d, e, f, g, h, i, j) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j) -> f)
-> q (a, b, c, d, e, f, g, h, i, j) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f, g
_, h
_, i
_, j
_) -> f
f)
    q (a, b, c, d, e, f, g, h, i, j)
  (g -> h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) g
-> q (a, b, c, d, e, f, g, h, i, j)
     (h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
forall a b.
q (a, b, c, d, e, f, g, h, i, j) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j) -> g)
-> q (a, b, c, d, e, f, g, h, i, j) g
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
g, h
_, i
_, j
_) -> g
g)
    q (a, b, c, d, e, f, g, h, i, j)
  (h -> i -> j -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) h
-> q (a, b, c, d, e, f, g, h, i, j)
     (i -> j -> (a, b, c, d, e, f, g, h, i, j))
forall a b.
q (a, b, c, d, e, f, g, h, i, j) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j) -> h)
-> q (a, b, c, d, e, f, g, h, i, j) h
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
h, i
_, j
_) -> h
h)
    q (a, b, c, d, e, f, g, h, i, j)
  (i -> j -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) i
-> q (a, b, c, d, e, f, g, h, i, j)
     (j -> (a, b, c, d, e, f, g, h, i, j))
forall a b.
q (a, b, c, d, e, f, g, h, i, j) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j) -> i)
-> q (a, b, c, d, e, f, g, h, i, j) i
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
i, j
_) -> i
i)
    q (a, b, c, d, e, f, g, h, i, j)
  (j -> (a, b, c, d, e, f, g, h, i, j))
-> q (a, b, c, d, e, f, g, h, i, j) j
-> q (a, b, c, d, e, f, g, h, i, j) (a, b, c, d, e, f, g, h, i, j)
forall a b.
q (a, b, c, d, e, f, g, h, i, j) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j) a
-> q (a, b, c, d, e, f, g, h, i, j) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j) -> j)
-> q (a, b, c, d, e, f, g, h, i, j) j
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
j) -> j
j)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f, Json g, Json h, Json i
  , Json j, Json k )
  => Json (a, b, c, d, e, f, g, h, i, j, k) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f, g, h, i, j, k)
  (a, b, c, d, e, f, g, h, i, j, k)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f, g, h, i, j, k)
   (a, b, c, d, e, f, g, h, i, j, k))
-> p (a, b, c, d, e, f, g, h, i, j, k)
     (a, b, c, d, e, f, g, h, i, j, k)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f, g, h, i, j, k)
    (a, b, c, d, e, f, g, h, i, j, k))
 -> p (a, b, c, d, e, f, g, h, i, j, k)
      (a, b, c, d, e, f, g, h, i, j, k))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f, g, h, i, j, k)
      (a, b, c, d, e, f, g, h, i, j, k))
-> p (a, b, c, d, e, f, g, h, i, j, k)
     (a, b, c, d, e, f, g, h, i, j, k)
forall a b. (a -> b) -> a -> b
$ (,,,,,,,,,,)
    (a
 -> b
 -> c
 -> d
 -> e
 -> f
 -> g
 -> h
 -> i
 -> j
 -> k
 -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (b
      -> c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> (a, b, c, d, e, f, g, h, i, j, k))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f, g, h, i, j, k) -> a)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_) -> a
a)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (b
   -> c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) b
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> (a, b, c, d, e, f, g, h, i, j, k))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_) -> b
b)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) c
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> (a, b, c, d, e, f, g, h, i, j, k))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> c)
-> q (a, b, c, d, e, f, g, h, i, j, k) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_) -> c
c)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) d
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (e
      -> f -> g -> h -> i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> d)
-> q (a, b, c, d, e, f, g, h, i, j, k) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_, g
_, h
_, i
_, j
_, k
_) -> d
d)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (e
   -> f -> g -> h -> i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) e
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (f -> g -> h -> i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> e)
-> q (a, b, c, d, e, f, g, h, i, j, k) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_, g
_, h
_, i
_, j
_, k
_) -> e
e)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (f -> g -> h -> i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) f
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (g -> h -> i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> f)
-> q (a, b, c, d, e, f, g, h, i, j, k) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f, g
_, h
_, i
_, j
_, k
_) -> f
f)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (g -> h -> i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) g
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (h -> i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> g)
-> q (a, b, c, d, e, f, g, h, i, j, k) g
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
g, h
_, i
_, j
_, k
_) -> g
g)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (h -> i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) h
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> h)
-> q (a, b, c, d, e, f, g, h, i, j, k) h
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
h, i
_, j
_, k
_) -> h
h)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (i -> j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) i
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> i)
-> q (a, b, c, d, e, f, g, h, i, j, k) i
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
i, j
_, k
_) -> i
i)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (j -> k -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) j
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (k -> (a, b, c, d, e, f, g, h, i, j, k))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> j)
-> q (a, b, c, d, e, f, g, h, i, j, k) j
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
j, k
_) -> j
j)
    q (a, b, c, d, e, f, g, h, i, j, k)
  (k -> (a, b, c, d, e, f, g, h, i, j, k))
-> q (a, b, c, d, e, f, g, h, i, j, k) k
-> q (a, b, c, d, e, f, g, h, i, j, k)
     (a, b, c, d, e, f, g, h, i, j, k)
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k) a
-> q (a, b, c, d, e, f, g, h, i, j, k) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k) -> k)
-> q (a, b, c, d, e, f, g, h, i, j, k) k
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
k) -> k
k)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f, Json g, Json h, Json i
  , Json j, Json k, Json l )
  => Json (a, b, c, d, e, f, g, h, i, j, k, l) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f, g, h, i, j, k, l)
  (a, b, c, d, e, f, g, h, i, j, k, l)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f, g, h, i, j, k, l)
   (a, b, c, d, e, f, g, h, i, j, k, l))
-> p (a, b, c, d, e, f, g, h, i, j, k, l)
     (a, b, c, d, e, f, g, h, i, j, k, l)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f, g, h, i, j, k, l)
    (a, b, c, d, e, f, g, h, i, j, k, l))
 -> p (a, b, c, d, e, f, g, h, i, j, k, l)
      (a, b, c, d, e, f, g, h, i, j, k, l))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f, g, h, i, j, k, l)
      (a, b, c, d, e, f, g, h, i, j, k, l))
-> p (a, b, c, d, e, f, g, h, i, j, k, l)
     (a, b, c, d, e, f, g, h, i, j, k, l)
forall a b. (a -> b) -> a -> b
$ (,,,,,,,,,,,)
    (a
 -> b
 -> c
 -> d
 -> e
 -> f
 -> g
 -> h
 -> i
 -> j
 -> k
 -> l
 -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (b
      -> c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f, g, h, i, j, k, l) -> a)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_) -> a
a)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (b
   -> c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_) -> b
b)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) c
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> c)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_) -> c
c)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) d
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> d)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_) -> d
d)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) e
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> e)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_, g
_, h
_, i
_, j
_, k
_, l
_) -> e
e)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) f
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (g
      -> h -> i -> j -> k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> f)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f, g
_, h
_, i
_, j
_, k
_, l
_) -> f
f)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (g
   -> h -> i -> j -> k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) g
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (h -> i -> j -> k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> g)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) g
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
g, h
_, i
_, j
_, k
_, l
_) -> g
g)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (h -> i -> j -> k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) h
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (i -> j -> k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> h)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) h
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
h, i
_, j
_, k
_, l
_) -> h
h)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (i -> j -> k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) i
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (j -> k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> i)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) i
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
i, j
_, k
_, l
_) -> i
i)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (j -> k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) j
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> j)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) j
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
j, k
_, l
_) -> j
j)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (k -> l -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) k
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (l -> (a, b, c, d, e, f, g, h, i, j, k, l))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> k)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) k
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
k, l
_) -> k
k)
    q (a, b, c, d, e, f, g, h, i, j, k, l)
  (l -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> q (a, b, c, d, e, f, g, h, i, j, k, l) l
-> q (a, b, c, d, e, f, g, h, i, j, k, l)
     (a, b, c, d, e, f, g, h, i, j, k, l)
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l) -> l)
-> q (a, b, c, d, e, f, g, h, i, j, k, l) l
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
l) -> l
l)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f, Json g, Json h, Json i
  , Json j, Json k, Json l, Json m )
  => Json (a, b, c, d, e, f, g, h, i, j, k, l, m) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (a, b, c, d, e, f, g, h, i, j, k, l, m)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f, g, h, i, j, k, l, m)
   (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> p (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (a, b, c, d, e, f, g, h, i, j, k, l, m)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f, g, h, i, j, k, l, m)
    (a, b, c, d, e, f, g, h, i, j, k, l, m))
 -> p (a, b, c, d, e, f, g, h, i, j, k, l, m)
      (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
      (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> p (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (a, b, c, d, e, f, g, h, i, j, k, l, m)
forall a b. (a -> b) -> a -> b
$ (,,,,,,,,,,,,)
    (a
 -> b
 -> c
 -> d
 -> e
 -> f
 -> g
 -> h
 -> i
 -> j
 -> k
 -> l
 -> m
 -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (b
      -> c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> a)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_) -> a
a)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (b
   -> c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_) -> b
b)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) c
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> c)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_) -> c
c)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) d
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> d)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_) -> d
d)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) e
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> e)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_) -> e
e)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) f
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> f)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f, g
_, h
_, i
_, j
_, k
_, l
_, m
_) -> f
f)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) g
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> g)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) g
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
g, h
_, i
_, j
_, k
_, l
_, m
_) -> g
g)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) h
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (i -> j -> k -> l -> m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> h)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) h
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
h, i
_, j
_, k
_, l
_, m
_) -> h
h)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (i -> j -> k -> l -> m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) i
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (j -> k -> l -> m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> i)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) i
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
i, j
_, k
_, l
_, m
_) -> i
i)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (j -> k -> l -> m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) j
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (k -> l -> m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> j)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) j
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
j, k
_, l
_, m
_) -> j
j)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (k -> l -> m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) k
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (l -> m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> k)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) k
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
k, l
_, m
_) -> k
k)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (l -> m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) l
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> l)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) l
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
l, m
_) -> l
l)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m)
  (m -> (a, b, c, d, e, f, g, h, i, j, k, l, m))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) m
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m)
     (a, b, c, d, e, f, g, h, i, j, k, l, m)
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m) -> m)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m) m
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
m) -> m
m)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f, Json g, Json h, Json i
  , Json j, Json k, Json l, Json m, Json n )
  => Json (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
   (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> p (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
    (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
 -> p (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
      (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
      (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> p (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
forall a b. (a -> b) -> a -> b
$ (,,,,,,,,,,,,,)
    (a
 -> b
 -> c
 -> d
 -> e
 -> f
 -> g
 -> h
 -> i
 -> j
 -> k
 -> l
 -> m
 -> n
 -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (b
      -> c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> a)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_) -> a
a)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (b
   -> c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_) -> b
b)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) c
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> c)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_) -> c
c)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) d
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> d)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_) -> d
d)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) e
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> e)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_) -> e
e)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) f
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> f)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_) -> f
f)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) g
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> g)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) g
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
g, h
_, i
_, j
_, k
_, l
_, m
_, n
_) -> g
g)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) h
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> h)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) h
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
h, i
_, j
_, k
_, l
_, m
_, n
_) -> h
h)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) i
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (j
      -> k -> l -> m -> n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> i)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) i
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
i, j
_, k
_, l
_, m
_, n
_) -> i
i)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (j
   -> k -> l -> m -> n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) j
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (k -> l -> m -> n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> j)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) j
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
j, k
_, l
_, m
_, n
_) -> j
j)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (k -> l -> m -> n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) k
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (l -> m -> n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> k)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) k
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
k, l
_, m
_, n
_) -> k
k)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (l -> m -> n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) l
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (m -> n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> l)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) l
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
l, m
_, n
_) -> l
l)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (m -> n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) m
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> m)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) m
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
m, n
_) -> m
m)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  (n -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) n
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
     (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> n)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n) n
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
n) -> n
n)
instance
  ( Json a, Json b, Json c, Json d, Json e, Json f, Json g, Json h, Json i
  , Json j, Json k, Json l, Json m, Json n, Json o )
  => Json (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
json = (forall (q :: * -> * -> *).
 JsonTup p q =>
 q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
   (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> p (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple ((forall (q :: * -> * -> *).
  JsonTup p q =>
  q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
    (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
 -> p (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
      (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> (forall (q :: * -> * -> *).
    JsonTup p q =>
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
      (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> p (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
forall a b. (a -> b) -> a -> b
$ (,,,,,,,,,,,,,,)
    (a
 -> b
 -> c
 -> d
 -> e
 -> f
 -> g
 -> h
 -> i
 -> j
 -> k
 -> l
 -> m
 -> n
 -> o
 -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (b
      -> c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> a)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
a, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_, o
_) -> a
a)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (b
   -> c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (c
      -> d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
b, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_, o
_) -> b
b)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (c
   -> d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) c
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (d
      -> e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> c)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) c
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
c, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_, o
_) -> c
c)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (d
   -> e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) d
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (e
      -> f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> d)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) d
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
d, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_, o
_) -> d
d)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (e
   -> f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) e
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (f
      -> g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> e)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) e
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
e, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_, o
_) -> e
e)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (f
   -> g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) f
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (g
      -> h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> f)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) f
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
f, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_, o
_) -> f
f)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (g
   -> h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) g
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (h
      -> i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> g)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) g
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
g, h
_, i
_, j
_, k
_, l
_, m
_, n
_, o
_) -> g
g)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (h
   -> i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) h
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (i
      -> j
      -> k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> h)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) h
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
h, i
_, j
_, k
_, l
_, m
_, n
_, o
_) -> h
h)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (i
   -> j
   -> k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) i
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (j
      -> k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> i)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) i
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
i, j
_, k
_, l
_, m
_, n
_, o
_) -> i
i)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (j
   -> k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) j
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (k
      -> l
      -> m
      -> n
      -> o
      -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> j)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) j
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
j, k
_, l
_, m
_, n
_, o
_) -> j
j)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (k
   -> l
   -> m
   -> n
   -> o
   -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) k
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (l -> m -> n -> o -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> k)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) k
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
k, l
_, m
_, n
_, o
_) -> k
k)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (l -> m -> n -> o -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) l
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (m -> n -> o -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> l)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) l
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
l, m
_, n
_, o
_) -> l
l)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (m -> n -> o -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) m
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (n -> o -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> m)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) m
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
m, n
_, o
_) -> m
m)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (n -> o -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) n
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (o -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> n)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) n
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
n, o
_) -> n
n)
    q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
  (o -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o))
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) o
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
     (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
forall a b.
q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (a -> b)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) a
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> o)
-> q (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) o
forall a (p :: * -> * -> *) (q :: * -> * -> *) s.
(Json a, JsonVal p, JsonTup p q) =>
(s -> a) -> q s a
projectElem (\(a
_, b
_, c
_, d
_, e
_, f
_, g
_, h
_, i
_, j
_, k
_, l
_, m
_, n
_, o
o) -> o
o)

-- text
instance Json Text where
  json :: forall (p :: * -> * -> *). JsonVal p => p Text Text
json = p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
  {-# INLINE json #-}
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Text Text)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Text Text)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Text Text)
forall a. a -> Maybe a
Just k Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
instance Json LText.Text where
  json :: forall (p :: * -> * -> *). JsonVal p => p Text Text
json = (Text -> Text) -> (Text -> Text) -> Iso Text Text Text Text
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Text -> Text
LText.toStrict Text -> Text
LText.fromStrict (Exchange Text Text Text (Identity Text)
 -> Exchange Text Text Text (Identity Text))
-> p Text Text -> p Text Text
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Text Text)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Text Text)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Text Text)
forall a. a -> Maybe a
Just ((Text -> Text) -> (Text -> Text) -> Iso Text Text Text Text
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Text -> Text
LText.toStrict Text -> Text
LText.fromStrict (Exchange Text Text Text (Identity Text)
 -> Exchange Text Text Text (Identity Text))
-> k Text Text -> k Text Text
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ k Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText)
instance Json ShortText where
  json :: forall (p :: * -> * -> *). JsonVal p => p ShortText ShortText
json = (ShortText -> Text)
-> (Text -> ShortText) -> Iso ShortText ShortText Text Text
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ShortText -> Text
ShortText.toText Text -> ShortText
ShortText.fromText (Exchange Text Text Text (Identity Text)
 -> Exchange Text Text ShortText (Identity ShortText))
-> p Text Text -> p ShortText ShortText
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText
  jsonKey :: Maybe
  (forall (k :: * -> * -> *). JsonStr k => k ShortText ShortText)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k ShortText ShortText)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k ShortText ShortText)
forall a. a -> Maybe a
Just ((ShortText -> Text)
-> (Text -> ShortText) -> Iso ShortText ShortText Text Text
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ShortText -> Text
ShortText.toText Text -> ShortText
ShortText.fromText (Exchange Text Text Text (Identity Text)
 -> Exchange Text Text ShortText (Identity ShortText))
-> k Text Text -> k ShortText ShortText
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ k Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText)

-- scientific
instance Json Scientific where
  json :: forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
json = p Scientific Scientific
forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
jsonNumber
  jsonKey :: Maybe
  (forall (p :: * -> * -> *). JsonStr p => p Scientific Scientific)
jsonKey = (forall (p :: * -> * -> *). JsonStr p => p Scientific Scientific)
-> Maybe
     (forall (p :: * -> * -> *). JsonStr p => p Scientific Scientific)
forall a. a -> Maybe a
Just k Scientific Scientific
forall (p :: * -> * -> *). JsonStr p => p Scientific Scientific
jsonScientificKey

-- containers
instance Json a => Json (Seq a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Seq a) (Seq a)
json = (Seq a -> [a]) -> ([a] -> Seq a) -> Iso (Seq a) (Seq a) [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Seq a -> [a]
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList [a] -> Seq a
forall a. [a] -> Seq a
Seq.fromList (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] (Seq a) (Identity (Seq a)))
-> p [a] [a] -> p (Seq a) (Seq a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p a a -> p [a] [a]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
instance (Ord a, Json a) => Json (Set a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Set a) (Set a)
json = (Set a -> [a]) -> ([a] -> Set a) -> Iso (Set a) (Set a) [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Set a -> [a]
forall a. Set a -> [a]
Set.toList [a] -> Set a
forall a. Ord a => [a] -> Set a
Set.fromList (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] (Set a) (Identity (Set a)))
-> p [a] [a] -> p (Set a) (Set a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p a a -> p [a] [a]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
instance Json IntSet where
  json :: forall (p :: * -> * -> *). JsonVal p => p IntSet IntSet
json = (IntSet -> [Int])
-> ([Int] -> IntSet) -> Iso IntSet IntSet [Int] [Int]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso IntSet -> [Int]
IntSet.toList [Int] -> IntSet
IntSet.fromList (Exchange [Int] [Int] [Int] (Identity [Int])
 -> Exchange [Int] [Int] IntSet (Identity IntSet))
-> p [Int] [Int] -> p IntSet IntSet
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @[Int]
instance Json a => Json (IntMap a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (IntMap a) (IntMap a)
json = (IntMap a -> [(Int, a)])
-> ([(Int, a)] -> IntMap a)
-> Iso (IntMap a) (IntMap a) [(Int, a)] [(Int, a)]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso IntMap a -> [(Int, a)]
forall a. IntMap a -> [(Int, a)]
IntMap.toList [(Int, a)] -> IntMap a
forall a. [(Int, a)] -> IntMap a
IntMap.fromList (Exchange [(Int, a)] [(Int, a)] [(Int, a)] (Identity [(Int, a)])
 -> Exchange [(Int, a)] [(Int, a)] (IntMap a) (Identity (IntMap a)))
-> p [(Int, a)] [(Int, a)] -> p (IntMap a) (IntMap a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @[(Int, a)]
instance (Ord k, Json k, Json v) => Json (Map k v) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Map k v) (Map k v)
json = case forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
jsonKey @k of
    Just forall (k :: * -> * -> *). JsonStr k => k k k
key -> (forall (k :: * -> * -> *). JsonStr k => k k k)
-> p v v -> p (Map k v) (Map k v)
forall b a c d.
Ord b =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> p (Map a c) (Map b d)
forall (p :: * -> * -> *) b a c d.
(JsonVal p, Ord b) =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> p (Map a c) (Map b d)
jsonMap k k k
forall (k :: * -> * -> *). JsonStr k => k k k
key p v v
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p v v
json
    Maybe (forall (k :: * -> * -> *). JsonStr k => k k k)
Nothing -> (Map k v -> [(k, v)])
-> ([(k, v)] -> Map k v)
-> Iso (Map k v) (Map k v) [(k, v)] [(k, v)]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Map k v -> [(k, v)]
forall k a. Map k a -> [(k, a)]
Map.toList [(k, v)] -> Map k v
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList (Exchange [(k, v)] [(k, v)] [(k, v)] (Identity [(k, v)])
 -> Exchange [(k, v)] [(k, v)] (Map k v) (Identity (Map k v)))
-> p [(k, v)] [(k, v)] -> p (Map k v) (Map k v)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p [(k, v)] [(k, v)]
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p [(k, v)] [(k, v)]
json
instance (Typeable a, Json a) => Json (Tree a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Tree a) (Tree a)
json = p (Tree a) (Tree a) -> p (Tree a) (Tree a)
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p (Tree a) (Tree a)
forall a (d :: Meta) (c :: Meta) (f :: * -> *) (p :: * -> * -> *).
(Generic a, Rep a ~ D1 d (C1 c f), GElements f, JsonVal p) =>
p a a
gtuple

-- dlist
instance Json a => Json (DList a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (DList a) (DList a)
json = (DList a -> [a])
-> ([a] -> DList a) -> Iso (DList a) (DList a) [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso DList a -> [a]
forall a. DList a -> [a]
DList.toList [a] -> DList a
forall a. [a] -> DList a
DList.fromList (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] (DList a) (Identity (DList a)))
-> p [a] [a] -> p (DList a) (DList a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p a a -> p [a] [a]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
instance Json a => Json (DNonEmpty a) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (DNonEmpty a) (DNonEmpty a)
json = (DNonEmpty a -> NonEmpty a)
-> (NonEmpty a -> DNonEmpty a)
-> Iso (DNonEmpty a) (DNonEmpty a) (NonEmpty a) (NonEmpty a)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso DNonEmpty a -> NonEmpty a
forall a. DNonEmpty a -> NonEmpty a
DNonEmpty.toNonEmpty NonEmpty a -> DNonEmpty a
forall a. NonEmpty a -> DNonEmpty a
DNonEmpty.fromNonEmpty (Exchange
   (NonEmpty a) (NonEmpty a) (NonEmpty a) (Identity (NonEmpty a))
 -> Exchange
      (NonEmpty a) (NonEmpty a) (DNonEmpty a) (Identity (DNonEmpty a)))
-> p (NonEmpty a) (NonEmpty a) -> p (DNonEmpty a) (DNonEmpty a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(NonEmpty a)

-- vector
instance Json a => Json (Vector a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Vector a) (Vector a)
json = (Vector a -> [a])
-> ([a] -> Vector a) -> Iso (Vector a) (Vector a) [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Vector a -> [a]
forall a. Vector a -> [a]
Vector.toList [a] -> Vector a
forall a. [a] -> Vector a
Vector.fromList (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] (Vector a) (Identity (Vector a)))
-> p [a] [a] -> p (Vector a) (Vector a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p a a -> p [a] [a]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
instance (Storable a, Json a) => Json (VS.Vector a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Vector a) (Vector a)
json = (Vector a -> [a])
-> ([a] -> Vector a) -> Iso (Vector a) (Vector a) [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Vector a -> [a]
forall (v :: * -> *) a. Vector v a => v a -> [a]
VG.toList [a] -> Vector a
forall (v :: * -> *) a. Vector v a => [a] -> v a
VG.fromList (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] (Vector a) (Identity (Vector a)))
-> p [a] [a] -> p (Vector a) (Vector a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p a a -> p [a] [a]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
instance (VP.Prim a, Json a) => Json (VP.Vector a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Vector a) (Vector a)
json = (Vector a -> [a])
-> ([a] -> Vector a) -> Iso (Vector a) (Vector a) [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Vector a -> [a]
forall (v :: * -> *) a. Vector v a => v a -> [a]
VG.toList [a] -> Vector a
forall (v :: * -> *) a. Vector v a => [a] -> v a
VG.fromList (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] (Vector a) (Identity (Vector a)))
-> p [a] [a] -> p (Vector a) (Vector a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p a a -> p [a] [a]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
instance (VU.Unbox a, Json a) => Json (VU.Vector a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Vector a) (Vector a)
json = (Vector a -> [a])
-> ([a] -> Vector a) -> Iso (Vector a) (Vector a) [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Vector a -> [a]
forall (v :: * -> *) a. Vector v a => v a -> [a]
VG.toList [a] -> Vector a
forall (v :: * -> *) a. Vector v a => [a] -> v a
VG.fromList (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] (Vector a) (Identity (Vector a)))
-> p [a] [a] -> p (Vector a) (Vector a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p a a -> p [a] [a]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json

-- primitive
instance Json a => Json (Array a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Array a) (Array a)
json = (Array a -> [Item (Array a)])
-> ([Item (Array a)] -> Array a)
-> Iso (Array a) (Array a) [Item (Array a)] [Item (Array a)]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Array a -> [Item (Array a)]
forall l. IsList l => l -> [Item l]
Exts.toList [Item (Array a)] -> Array a
forall l. IsList l => [Item l] -> l
Exts.fromList (Exchange
   [Item (Array a)]
   [Item (Array a)]
   [Item (Array a)]
   (Identity [Item (Array a)])
 -> Exchange
      [Item (Array a)] [Item (Array a)] (Array a) (Identity (Array a)))
-> p [Item (Array a)] [Item (Array a)] -> p (Array a) (Array a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @[a]
instance Json a => Json (SmallArray a) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (SmallArray a) (SmallArray a)
json = (SmallArray a -> [Item (SmallArray a)])
-> ([Item (SmallArray a)] -> SmallArray a)
-> Iso
     (SmallArray a)
     (SmallArray a)
     [Item (SmallArray a)]
     [Item (SmallArray a)]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso SmallArray a -> [Item (SmallArray a)]
forall l. IsList l => l -> [Item l]
Exts.toList [Item (SmallArray a)] -> SmallArray a
forall l. IsList l => [Item l] -> l
Exts.fromList (Exchange
   [Item (SmallArray a)]
   [Item (SmallArray a)]
   [Item (SmallArray a)]
   (Identity [Item (SmallArray a)])
 -> Exchange
      [Item (SmallArray a)]
      [Item (SmallArray a)]
      (SmallArray a)
      (Identity (SmallArray a)))
-> p [Item (SmallArray a)] [Item (SmallArray a)]
-> p (SmallArray a) (SmallArray a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @[a]
instance (Prim a, Json a) => Json (PrimArray a) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (PrimArray a) (PrimArray a)
json = (PrimArray a -> [Item (PrimArray a)])
-> ([Item (PrimArray a)] -> PrimArray a)
-> Iso
     (PrimArray a)
     (PrimArray a)
     [Item (PrimArray a)]
     [Item (PrimArray a)]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso PrimArray a -> [Item (PrimArray a)]
forall l. IsList l => l -> [Item l]
Exts.toList [Item (PrimArray a)] -> PrimArray a
forall l. IsList l => [Item l] -> l
Exts.fromList (Exchange
   [Item (PrimArray a)]
   [Item (PrimArray a)]
   [Item (PrimArray a)]
   (Identity [Item (PrimArray a)])
 -> Exchange
      [Item (PrimArray a)]
      [Item (PrimArray a)]
      (PrimArray a)
      (Identity (PrimArray a)))
-> p [Item (PrimArray a)] [Item (PrimArray a)]
-> p (PrimArray a) (PrimArray a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @[a]

-- unordered-containers
instance (Eq a, Hashable a, Json a) => Json (HashSet a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (HashSet a) (HashSet a)
json = (HashSet a -> [a])
-> ([a] -> HashSet a) -> Iso (HashSet a) (HashSet a) [a] [a]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso HashSet a -> [a]
forall a. HashSet a -> [a]
HashSet.toList [a] -> HashSet a
forall a. Hashable a => [a] -> HashSet a
HashSet.fromList (Exchange [a] [a] [a] (Identity [a])
 -> Exchange [a] [a] (HashSet a) (Identity (HashSet a)))
-> p [a] [a] -> p (HashSet a) (HashSet a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p a a -> p [a] [a]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. JsonVal p => p a b -> p [a] [b]
jsonArray p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
instance (Eq k, Hashable k, Json k, Json v) => Json (HashMap k v) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (HashMap k v) (HashMap k v)
json = case forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
jsonKey @k of
    Just forall (k :: * -> * -> *). JsonStr k => k k k
key -> (forall (k :: * -> * -> *). JsonStr k => k k k)
-> p v v -> p (HashMap k v) (HashMap k v)
forall b a c d.
(Eq b, Hashable b) =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> p (HashMap a c) (HashMap b d)
forall (p :: * -> * -> *) b a c d.
(JsonVal p, Eq b, Hashable b) =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> p (HashMap a c) (HashMap b d)
jsonHashMap k k k
forall (k :: * -> * -> *). JsonStr k => k k k
key p v v
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p v v
json
    Maybe (forall (k :: * -> * -> *). JsonStr k => k k k)
Nothing -> (HashMap k v -> [(k, v)])
-> ([(k, v)] -> HashMap k v)
-> Iso (HashMap k v) (HashMap k v) [(k, v)] [(k, v)]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso HashMap k v -> [(k, v)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList [(k, v)] -> HashMap k v
forall k v. Hashable k => [(k, v)] -> HashMap k v
HashMap.fromList (Exchange [(k, v)] [(k, v)] [(k, v)] (Identity [(k, v)])
 -> Exchange
      [(k, v)] [(k, v)] (HashMap k v) (Identity (HashMap k v)))
-> p [(k, v)] [(k, v)] -> p (HashMap k v) (HashMap k v)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p [(k, v)] [(k, v)]
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p [(k, v)] [(k, v)]
json

-- aeson
instance Json Key where
  json :: forall (p :: * -> * -> *). JsonVal p => p Key Key
json = p Key Key
forall (k :: * -> * -> *). JsonStr k => k Key Key
jsonKeyText
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Key Key)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Key Key)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Key Key)
forall a. a -> Maybe a
Just k Key Key
forall (k :: * -> * -> *). JsonStr k => k Key Key
jsonKeyText
instance Json v => Json (KeyMap v) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (KeyMap v) (KeyMap v)
json = (KeyMap v -> [(Key, v)])
-> ([(Key, v)] -> KeyMap v)
-> Iso (KeyMap v) (KeyMap v) [(Key, v)] [(Key, v)]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso KeyMap v -> [(Key, v)]
forall v. KeyMap v -> [(Key, v)]
KeyMap.toList [(Key, v)] -> KeyMap v
forall v. [(Key, v)] -> KeyMap v
KeyMap.fromList
    (Exchange [(Key, v)] [(Key, v)] [(Key, v)] (Identity [(Key, v)])
 -> Exchange [(Key, v)] [(Key, v)] (KeyMap v) (Identity (KeyMap v)))
-> p [(Key, v)] [(Key, v)] -> p (KeyMap v) (KeyMap v)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ (forall (q :: * -> * -> *). JsonObj p q => q [(Key, v)] [(Key, v)])
-> p [(Key, v)] [(Key, v)]
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject ((forall (k :: * -> * -> *). JsonStr k => k Key Key)
-> p v v -> q [(Key, v)] [(Key, v)]
forall a b c d.
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
forall (p :: * -> * -> *) (q :: * -> * -> *) a b c d.
JsonObj p q =>
(forall (k :: * -> * -> *). JsonStr k => k a b)
-> p c d -> q [(a, c)] [(b, d)]
jsonDict k Key Key
forall (k :: * -> * -> *). JsonStr k => k Key Key
jsonKeyText p v v
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p v v
json)
instance Json Value where
  json :: forall (p :: * -> * -> *). JsonVal p => p Value Value
json = p Value Value
forall (p :: * -> * -> *). JsonVal p => p Value Value
jsonValue
instance Json DotNetTime where
  json :: forall (p :: * -> * -> *). JsonVal p => p DotNetTime DotNetTime
json = p DotNetTime DotNetTime -> p DotNetTime DotNetTime
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped ((DotNetTime -> Text)
-> (Text -> Maybe DotNetTime)
-> Prism Text Text DotNetTime DotNetTime
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' DotNetTime -> Text
render Text -> Maybe DotNetTime
forall {f :: * -> *}. MonadFail f => Text -> f DotNetTime
parse (Market DotNetTime DotNetTime DotNetTime (Identity DotNetTime)
 -> Market DotNetTime DotNetTime Text (Identity Text))
-> p Text Text -> p DotNetTime DotNetTime
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText)
    where
      render :: DotNetTime -> Text
render (DotNetTime UTCTime
t) = String -> Text
Text.pack
        ( TimeLocale -> String -> UTCTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
"/Date(%s" UTCTime
t
        String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> ShowS
forall a. Int -> [a] -> [a]
take Int
3 (TimeLocale -> String -> UTCTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
"%q" UTCTime
t)
        String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")/" )
      parse :: Text -> f DotNetTime
parse Text
t =
        let (Text
s, Text
m) = Int -> Text -> (Text, Text)
Text.splitAt (Text -> Int
Text.length Text
t Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
5) Text
t
        in UTCTime -> DotNetTime
DotNetTime (UTCTime -> DotNetTime) -> f UTCTime -> f DotNetTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> TimeLocale -> String -> String -> f UTCTime
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> String -> String -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale
          String
"/Date(%s%Q)/" (Text -> String
Text.unpack ([Text] -> Text
Text.concat [Text
s, Text
".", Text
m]))

-- time

-- | A time, encoded as @aeson@ encodes it.
encodedTime
  :: (a -> Encoding.Encoding' Text) -> (Text -> Either String a)
  -> Prism Text (Text, Encoding.Encoding' Text) a a
encodedTime :: forall a.
(a -> Encoding' Text)
-> (Text -> Either String a)
-> Prism Text (Text, Encoding' Text) a a
encodedTime a -> Encoding' Text
f Text -> Either String a
g = (a -> (Text, Encoding' Text))
-> (Text -> Either (Text, Encoding' Text) a)
-> Prism Text (Text, Encoding' Text) a a
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism
  (\a
a -> let encoded :: Encoding' Text
encoded = a -> Encoding' Text
f a
a in (Encoding' Text -> Text
forall {a}. Encoding' a -> Text
encodedText Encoding' Text
encoded, Encoding' Text
encoded))
  (\Text
t -> (String -> Either (Text, Encoding' Text) a)
-> (a -> Either (Text, Encoding' Text) a)
-> Either String a
-> Either (Text, Encoding' Text) a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\String
_ -> (Text, Encoding' Text) -> Either (Text, Encoding' Text) a
forall a b. a -> Either a b
Left (Text
t, Text -> Encoding' Text
forall a. Text -> Encoding' a
Encoding.text Text
t)) a -> Either (Text, Encoding' Text) a
forall a b. b -> Either a b
Right (Text -> Either String a
g Text
t))
  where
    encodedText :: Encoding' a -> Text
encodedText = (Char -> Bool) -> Text -> Text
Text.dropAround (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'"') (Text -> Text) -> (Encoding' a -> Text) -> Encoding' a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictByteString -> Text
Text.decodeLatin1
      (StrictByteString -> Text)
-> (Encoding' a -> StrictByteString) -> Encoding' a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> StrictByteString
LByteString.toStrict (ByteString -> StrictByteString)
-> (Encoding' a -> ByteString) -> Encoding' a -> StrictByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Encoding' a -> ByteString
forall a. Encoding' a -> ByteString
Encoding.encodingToLazyByteString

_Day :: Prism Text (Text, Encoding.Encoding' Text) Day Day
_Day :: Prism Text (Text, Encoding' Text) Day Day
_Day = (Day -> Encoding' Text)
-> (Text -> Either String Day)
-> Prism Text (Text, Encoding' Text) Day Day
forall a.
(a -> Encoding' Text)
-> (Text -> Either String a)
-> Prism Text (Text, Encoding' Text) a a
encodedTime Day -> Encoding' Text
forall a. Day -> Encoding' a
Encoding.day Text -> Either String Day
TimeText.parseDay
instance Json Day where
  json :: forall (p :: * -> * -> *). JsonVal p => p Day Day
json = p Day Day -> p Day Day
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (APrism Text (Text, Encoding' Text) Day Day -> p Day Day
forall a. APrism Text (Text, Encoding' Text) a a -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) Day Day
Prism Text (Text, Encoding' Text) Day Day
_Day)
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Day Day)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Day Day)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Day Day)
forall a. a -> Maybe a
Just (APrism Text (Text, Encoding' Text) Day Day -> k Day Day
forall a. APrism Text (Text, Encoding' Text) a a -> k a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) Day Day
Prism Text (Text, Encoding' Text) Day Day
_Day)

_Month :: Prism Text (Text, Encoding.Encoding' Text) Month Month
_Month :: Prism Text (Text, Encoding' Text) Month Month
_Month = (Month -> Encoding' Text)
-> (Text -> Either String Month)
-> Prism Text (Text, Encoding' Text) Month Month
forall a.
(a -> Encoding' Text)
-> (Text -> Either String a)
-> Prism Text (Text, Encoding' Text) a a
encodedTime Month -> Encoding' Text
forall a. Month -> Encoding' a
Encoding.month Text -> Either String Month
TimeText.parseMonth
instance Json Month where
  json :: forall (p :: * -> * -> *). JsonVal p => p Month Month
json = p Month Month -> p Month Month
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (APrism Text (Text, Encoding' Text) Month Month -> p Month Month
forall a. APrism Text (Text, Encoding' Text) a a -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) Month Month
Prism Text (Text, Encoding' Text) Month Month
_Month)
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Month Month)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Month Month)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k Month Month)
forall a. a -> Maybe a
Just (APrism Text (Text, Encoding' Text) Month Month -> k Month Month
forall a. APrism Text (Text, Encoding' Text) a a -> k a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) Month Month
Prism Text (Text, Encoding' Text) Month Month
_Month)

_Quarter :: Prism Text (Text, Encoding.Encoding' Text) Quarter Quarter
_Quarter :: Prism Text (Text, Encoding' Text) Quarter Quarter
_Quarter = (Quarter -> Encoding' Text)
-> (Text -> Either String Quarter)
-> Prism Text (Text, Encoding' Text) Quarter Quarter
forall a.
(a -> Encoding' Text)
-> (Text -> Either String a)
-> Prism Text (Text, Encoding' Text) a a
encodedTime Quarter -> Encoding' Text
forall a. Quarter -> Encoding' a
Encoding.quarter Text -> Either String Quarter
TimeText.parseQuarter
instance Json Quarter where
  json :: forall (p :: * -> * -> *). JsonVal p => p Quarter Quarter
json = p Quarter Quarter -> p Quarter Quarter
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (APrism Text (Text, Encoding' Text) Quarter Quarter
-> p Quarter Quarter
forall a. APrism Text (Text, Encoding' Text) a a -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) Quarter Quarter
Prism Text (Text, Encoding' Text) Quarter Quarter
_Quarter)
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k Quarter Quarter)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k Quarter Quarter)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k Quarter Quarter)
forall a. a -> Maybe a
Just (APrism Text (Text, Encoding' Text) Quarter Quarter
-> k Quarter Quarter
forall a. APrism Text (Text, Encoding' Text) a a -> k a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) Quarter Quarter
Prism Text (Text, Encoding' Text) Quarter Quarter
_Quarter)

_TimeOfDay :: Prism Text (Text, Encoding.Encoding' Text) TimeOfDay TimeOfDay
_TimeOfDay :: Prism Text (Text, Encoding' Text) TimeOfDay TimeOfDay
_TimeOfDay = (TimeOfDay -> Encoding' Text)
-> (Text -> Either String TimeOfDay)
-> Prism Text (Text, Encoding' Text) TimeOfDay TimeOfDay
forall a.
(a -> Encoding' Text)
-> (Text -> Either String a)
-> Prism Text (Text, Encoding' Text) a a
encodedTime TimeOfDay -> Encoding' Text
forall a. TimeOfDay -> Encoding' a
Encoding.timeOfDay Text -> Either String TimeOfDay
TimeText.parseTimeOfDay
instance Json TimeOfDay where
  json :: forall (p :: * -> * -> *). JsonVal p => p TimeOfDay TimeOfDay
json = p TimeOfDay TimeOfDay -> p TimeOfDay TimeOfDay
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (APrism Text (Text, Encoding' Text) TimeOfDay TimeOfDay
-> p TimeOfDay TimeOfDay
forall a. APrism Text (Text, Encoding' Text) a a -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) TimeOfDay TimeOfDay
Prism Text (Text, Encoding' Text) TimeOfDay TimeOfDay
_TimeOfDay)
  jsonKey :: Maybe
  (forall (k :: * -> * -> *). JsonStr k => k TimeOfDay TimeOfDay)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k TimeOfDay TimeOfDay)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k TimeOfDay TimeOfDay)
forall a. a -> Maybe a
Just (APrism Text (Text, Encoding' Text) TimeOfDay TimeOfDay
-> k TimeOfDay TimeOfDay
forall a. APrism Text (Text, Encoding' Text) a a -> k a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) TimeOfDay TimeOfDay
Prism Text (Text, Encoding' Text) TimeOfDay TimeOfDay
_TimeOfDay)

_LocalTime :: Prism Text (Text, Encoding.Encoding' Text) LocalTime LocalTime
_LocalTime :: Prism Text (Text, Encoding' Text) LocalTime LocalTime
_LocalTime = (LocalTime -> Encoding' Text)
-> (Text -> Either String LocalTime)
-> Prism Text (Text, Encoding' Text) LocalTime LocalTime
forall a.
(a -> Encoding' Text)
-> (Text -> Either String a)
-> Prism Text (Text, Encoding' Text) a a
encodedTime LocalTime -> Encoding' Text
forall a. LocalTime -> Encoding' a
Encoding.localTime Text -> Either String LocalTime
TimeText.parseLocalTime
instance Json LocalTime where
  json :: forall (p :: * -> * -> *). JsonVal p => p LocalTime LocalTime
json = p LocalTime LocalTime -> p LocalTime LocalTime
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (APrism Text (Text, Encoding' Text) LocalTime LocalTime
-> p LocalTime LocalTime
forall a. APrism Text (Text, Encoding' Text) a a -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) LocalTime LocalTime
Prism Text (Text, Encoding' Text) LocalTime LocalTime
_LocalTime)
  jsonKey :: Maybe
  (forall (k :: * -> * -> *). JsonStr k => k LocalTime LocalTime)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k LocalTime LocalTime)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k LocalTime LocalTime)
forall a. a -> Maybe a
Just (APrism Text (Text, Encoding' Text) LocalTime LocalTime
-> k LocalTime LocalTime
forall a. APrism Text (Text, Encoding' Text) a a -> k a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) LocalTime LocalTime
Prism Text (Text, Encoding' Text) LocalTime LocalTime
_LocalTime)

_ZonedTime :: Prism Text (Text, Encoding.Encoding' Text) ZonedTime ZonedTime
_ZonedTime :: Prism Text (Text, Encoding' Text) ZonedTime ZonedTime
_ZonedTime = (ZonedTime -> Encoding' Text)
-> (Text -> Either String ZonedTime)
-> Prism Text (Text, Encoding' Text) ZonedTime ZonedTime
forall a.
(a -> Encoding' Text)
-> (Text -> Either String a)
-> Prism Text (Text, Encoding' Text) a a
encodedTime ZonedTime -> Encoding' Text
forall a. ZonedTime -> Encoding' a
Encoding.zonedTime Text -> Either String ZonedTime
TimeText.parseZonedTime
instance Json ZonedTime where
  json :: forall (p :: * -> * -> *). JsonVal p => p ZonedTime ZonedTime
json = p ZonedTime ZonedTime -> p ZonedTime ZonedTime
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (APrism Text (Text, Encoding' Text) ZonedTime ZonedTime
-> p ZonedTime ZonedTime
forall a. APrism Text (Text, Encoding' Text) a a -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) ZonedTime ZonedTime
Prism Text (Text, Encoding' Text) ZonedTime ZonedTime
_ZonedTime)
  jsonKey :: Maybe
  (forall (k :: * -> * -> *). JsonStr k => k ZonedTime ZonedTime)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k ZonedTime ZonedTime)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k ZonedTime ZonedTime)
forall a. a -> Maybe a
Just (APrism Text (Text, Encoding' Text) ZonedTime ZonedTime
-> k ZonedTime ZonedTime
forall a. APrism Text (Text, Encoding' Text) a a -> k a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) ZonedTime ZonedTime
Prism Text (Text, Encoding' Text) ZonedTime ZonedTime
_ZonedTime)

_UTCTime :: Prism Text (Text, Encoding.Encoding' Text) UTCTime UTCTime
_UTCTime :: Prism Text (Text, Encoding' Text) UTCTime UTCTime
_UTCTime = (UTCTime -> Encoding' Text)
-> (Text -> Either String UTCTime)
-> Prism Text (Text, Encoding' Text) UTCTime UTCTime
forall a.
(a -> Encoding' Text)
-> (Text -> Either String a)
-> Prism Text (Text, Encoding' Text) a a
encodedTime UTCTime -> Encoding' Text
forall a. UTCTime -> Encoding' a
Encoding.utcTime Text -> Either String UTCTime
TimeText.parseUTCTime
instance Json UTCTime where
  json :: forall (p :: * -> * -> *). JsonVal p => p UTCTime UTCTime
json = p UTCTime UTCTime -> p UTCTime UTCTime
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (APrism Text (Text, Encoding' Text) UTCTime UTCTime
-> p UTCTime UTCTime
forall a. APrism Text (Text, Encoding' Text) a a -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) UTCTime UTCTime
Prism Text (Text, Encoding' Text) UTCTime UTCTime
_UTCTime)
  jsonKey :: Maybe (forall (k :: * -> * -> *). JsonStr k => k UTCTime UTCTime)
jsonKey = (forall (k :: * -> * -> *). JsonStr k => k UTCTime UTCTime)
-> Maybe
     (forall (k :: * -> * -> *). JsonStr k => k UTCTime UTCTime)
forall a. a -> Maybe a
Just (APrism Text (Text, Encoding' Text) UTCTime UTCTime
-> k UTCTime UTCTime
forall a. APrism Text (Text, Encoding' Text) a a -> k a a
forall (p :: * -> * -> *) a.
JsonStr p =>
APrism Text (Text, Encoding' Text) a a -> p a a
jsonEncodedText APrism Text (Text, Encoding' Text) UTCTime UTCTime
Prism Text (Text, Encoding' Text) UTCTime UTCTime
_UTCTime)
instance Json NominalDiffTime where json :: forall (p :: * -> * -> *).
JsonVal p =>
p NominalDiffTime NominalDiffTime
json = p NominalDiffTime NominalDiffTime
-> p NominalDiffTime NominalDiffTime
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p NominalDiffTime NominalDiffTime
forall a (p :: * -> * -> *).
(Fractional a, Real a, JsonVal p) =>
p a a
jsonRealFrac
instance Json DiffTime where json :: forall (p :: * -> * -> *). JsonVal p => p DiffTime DiffTime
json = p DiffTime DiffTime -> p DiffTime DiffTime
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p DiffTime DiffTime
forall a (p :: * -> * -> *).
(Fractional a, Real a, JsonVal p) =>
p a a
jsonRealFrac
instance Json SystemTime where
  json :: forall (p :: * -> * -> *). JsonVal p => p SystemTime SystemTime
json = p SystemTime SystemTime -> p SystemTime SystemTime
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped ((SystemTime -> Scientific)
-> (Scientific -> Maybe SystemTime)
-> Prism Scientific Scientific SystemTime SystemTime
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' SystemTime -> Scientific
forall {b}. Fractional b => SystemTime -> b
render Scientific -> Maybe SystemTime
parse (Market SystemTime SystemTime SystemTime (Identity SystemTime)
 -> Market SystemTime SystemTime Scientific (Identity Scientific))
-> p Scientific Scientific -> p SystemTime SystemTime
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Scientific Scientific
forall (p :: * -> * -> *). JsonVal p => p Scientific Scientific
jsonNumber)
    where
      render :: SystemTime -> b
render (MkSystemTime Int64
s Word32
ns) =
        Nano -> b
forall a b. (Real a, Fractional b) => a -> b
realToFrac (Int64 -> Nano
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
s Nano -> Nano -> Nano
forall a. Num a => a -> a -> a
+ Word32 -> Nano
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
ns Nano -> Nano -> Nano
forall a. Fractional a => a -> a -> a
/ Nano
1000000000 :: Nano)
      parse :: Scientific -> Maybe SystemTime
parse Scientific
sci = do
        n <- Scientific -> Nano
forall a b. (Real a, Fractional b) => a -> b
realToFrac (Scientific -> Nano) -> Maybe Scientific -> Maybe Nano
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Scientific -> Maybe Scientific
boundedScientific Scientific
sci :: Maybe Nano
        let
          r = Nano -> Integer
forall k (a :: k) (p :: k -> *). HasResolution a => p a -> Integer
forall (p :: * -> *). p E9 -> Integer
resolution Nano
n
          (s, ns) = floor (n * fromInteger r) `divMod` r
        Just (MkSystemTime (fromInteger s) (fromInteger ns))
instance Json CalendarDiffTime where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p CalendarDiffTime CalendarDiffTime
json = (CalendarDiffTime -> (Integer, NominalDiffTime))
-> ((Integer, NominalDiffTime) -> CalendarDiffTime)
-> p (Integer, NominalDiffTime) (Integer, NominalDiffTime)
-> p CalendarDiffTime CalendarDiffTime
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 (\(CalendarDiffTime Integer
m NominalDiffTime
t) -> (Integer
m, NominalDiffTime
t)) ((Integer -> NominalDiffTime -> CalendarDiffTime)
-> (Integer, NominalDiffTime) -> CalendarDiffTime
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Integer -> NominalDiffTime -> CalendarDiffTime
CalendarDiffTime)
    ((forall (q :: * -> * -> *).
 JsonObj p q =>
 q (Integer, NominalDiffTime) (Integer, NominalDiffTime))
-> p (Integer, NominalDiffTime) (Integer, NominalDiffTime)
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject (Text
"months" Text -> p Integer Integer -> q Integer Integer
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p Integer Integer
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p Integer Integer
json q Integer Integer
-> q NominalDiffTime NominalDiffTime
-> q (Integer, NominalDiffTime) (Integer, NominalDiffTime)
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< Text
"time" Text
-> p NominalDiffTime NominalDiffTime
-> q NominalDiffTime NominalDiffTime
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p NominalDiffTime NominalDiffTime
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *).
JsonVal p =>
p NominalDiffTime NominalDiffTime
json))
instance Json CalendarDiffDays where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p CalendarDiffDays CalendarDiffDays
json = (CalendarDiffDays -> (Integer, Integer))
-> ((Integer, Integer) -> CalendarDiffDays)
-> p (Integer, Integer) (Integer, Integer)
-> p CalendarDiffDays CalendarDiffDays
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 (\(CalendarDiffDays Integer
m Integer
d) -> (Integer
m, Integer
d)) ((Integer -> Integer -> CalendarDiffDays)
-> (Integer, Integer) -> CalendarDiffDays
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Integer -> Integer -> CalendarDiffDays
CalendarDiffDays)
    ((forall (q :: * -> * -> *).
 JsonObj p q =>
 q (Integer, Integer) (Integer, Integer))
-> p (Integer, Integer) (Integer, Integer)
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject (Text
"months" Text -> p Integer Integer -> q Integer Integer
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p Integer Integer
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p Integer Integer
json q Integer Integer
-> q Integer Integer -> q (Integer, Integer) (Integer, Integer)
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< Text
"days" Text -> p Integer Integer -> q Integer Integer
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p Integer Integer
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p Integer Integer
json))

-- | Days of the week, named as @aeson@ names them.
weekdays :: JsonStr p => p DayOfWeek DayOfWeek
weekdays :: forall (p :: * -> * -> *). JsonStr p => p DayOfWeek DayOfWeek
weekdays = (DayOfWeek -> Int) -> [(Text, DayOfWeek)] -> p DayOfWeek DayOfWeek
forall a. (a -> Int) -> [(Text, a)] -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
(a -> Int) -> [(Text, a)] -> p a a
jsonEnumWith (\DayOfWeek
day -> DayOfWeek -> Int
forall a. Enum a => a -> Int
fromEnum DayOfWeek
day Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
  [ (Text -> Text
Text.toLower (String -> Text
Text.pack (DayOfWeek -> String
forall a. Show a => a -> String
show DayOfWeek
day)), DayOfWeek
day)
  | DayOfWeek
day <- [DayOfWeek
Monday, DayOfWeek
Tuesday, DayOfWeek
Wednesday, DayOfWeek
Thursday, DayOfWeek
Friday, DayOfWeek
Saturday, DayOfWeek
Sunday]
  ]

instance Json DayOfWeek where
  json :: forall (p :: * -> * -> *). JsonVal p => p DayOfWeek DayOfWeek
json = p DayOfWeek DayOfWeek -> p DayOfWeek DayOfWeek
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p DayOfWeek DayOfWeek
forall (p :: * -> * -> *). JsonStr p => p DayOfWeek DayOfWeek
weekdays
  jsonKey :: Maybe
  (forall (p :: * -> * -> *). JsonStr p => p DayOfWeek DayOfWeek)
jsonKey = (forall (p :: * -> * -> *). JsonStr p => p DayOfWeek DayOfWeek)
-> Maybe
     (forall (p :: * -> * -> *). JsonStr p => p DayOfWeek DayOfWeek)
forall a. a -> Maybe a
Just (k DayOfWeek DayOfWeek -> k DayOfWeek DayOfWeek
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped k DayOfWeek DayOfWeek
forall (p :: * -> * -> *). JsonStr p => p DayOfWeek DayOfWeek
weekdays)

-- | Quarters of the year, named as @aeson@ names them.
quarters :: JsonStr p => p QuarterOfYear QuarterOfYear
quarters :: forall (p :: * -> * -> *).
JsonStr p =>
p QuarterOfYear QuarterOfYear
quarters = (QuarterOfYear -> Text) -> p QuarterOfYear QuarterOfYear
forall a (p :: * -> * -> *).
(Bounded a, Enum a, JsonStr p) =>
(a -> Text) -> p a a
jsonEnumerated (Text -> Text
Text.toLower (Text -> Text) -> (QuarterOfYear -> Text) -> QuarterOfYear -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack (String -> Text)
-> (QuarterOfYear -> String) -> QuarterOfYear -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QuarterOfYear -> String
forall a. Show a => a -> String
show)

instance Json QuarterOfYear where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p QuarterOfYear QuarterOfYear
json = p QuarterOfYear QuarterOfYear -> p QuarterOfYear QuarterOfYear
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p QuarterOfYear QuarterOfYear
forall (p :: * -> * -> *).
JsonStr p =>
p QuarterOfYear QuarterOfYear
quarters
  jsonKey :: Maybe
  (forall (p :: * -> * -> *).
   JsonStr p =>
   p QuarterOfYear QuarterOfYear)
jsonKey = (forall (p :: * -> * -> *).
 JsonStr p =>
 p QuarterOfYear QuarterOfYear)
-> Maybe
     (forall (p :: * -> * -> *).
      JsonStr p =>
      p QuarterOfYear QuarterOfYear)
forall a. a -> Maybe a
Just (k QuarterOfYear QuarterOfYear -> k QuarterOfYear QuarterOfYear
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped k QuarterOfYear QuarterOfYear
forall (p :: * -> * -> *).
JsonStr p =>
p QuarterOfYear QuarterOfYear
quarters)

-- uuid-types

jsonUUID :: JsonStr p => p UUID UUID
jsonUUID :: forall (p :: * -> * -> *). JsonStr p => p UUID UUID
jsonUUID = (UUID -> Text) -> (Text -> Maybe UUID) -> Prism Text Text UUID UUID
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' UUID -> Text
UUID.toText Text -> Maybe UUID
UUID.fromText (Market UUID UUID UUID (Identity UUID)
 -> Market UUID UUID Text (Identity Text))
-> p Text Text -> p UUID UUID
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText

instance Json UUID where
  json :: forall (p :: * -> * -> *). JsonVal p => p UUID UUID
json = p UUID UUID -> p UUID UUID
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p UUID UUID
forall (p :: * -> * -> *). JsonStr p => p UUID UUID
jsonUUID
  jsonKey :: Maybe (forall (p :: * -> * -> *). JsonStr p => p UUID UUID)
jsonKey = (forall (p :: * -> * -> *). JsonStr p => p UUID UUID)
-> Maybe (forall (p :: * -> * -> *). JsonStr p => p UUID UUID)
forall a. a -> Maybe a
Just k UUID UUID
forall (p :: * -> * -> *). JsonStr p => p UUID UUID
jsonUUID

-- network-uri

jsonURI :: JsonStr p => p URI URI
jsonURI :: forall (p :: * -> * -> *). JsonStr p => p URI URI
jsonURI = (URI -> Text) -> (Text -> Maybe URI) -> Prism Text Text URI URI
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism'
  (\URI
uri -> String -> Text
Text.pack (ShowS -> URI -> ShowS
URI.uriToString ShowS
forall a. a -> a
id URI
uri String
""))
  (String -> Maybe URI
URI.parseURI (String -> Maybe URI) -> (Text -> String) -> Text -> Maybe URI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
Text.unpack)
  (Market URI URI URI (Identity URI)
 -> Market URI URI Text (Identity Text))
-> p Text Text -> p URI URI
forall (p :: * -> * -> *) b a t s.
Cochoice p =>
APrism b a t s -> p a b -> p s t
?< p Text Text
forall (k :: * -> * -> *). JsonStr k => k Text Text
jsonText

instance Json URI where
  json :: forall (p :: * -> * -> *). JsonVal p => p URI URI
json = p URI URI -> p URI URI
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped p URI URI
forall (p :: * -> * -> *). JsonStr p => p URI URI
jsonURI
  jsonKey :: Maybe (forall (p :: * -> * -> *). JsonStr p => p URI URI)
jsonKey = (forall (p :: * -> * -> *). JsonStr p => p URI URI)
-> Maybe (forall (p :: * -> * -> *). JsonStr p => p URI URI)
forall a. a -> Maybe a
Just k URI URI
forall (p :: * -> * -> *). JsonStr p => p URI URI
jsonURI

-- data-fix
instance (Typeable f, Json (f (Fix f))) => Json (Fix f) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Fix f) (Fix f)
json = p (Fix f) (Fix f) -> p (Fix f) (Fix f)
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped ((Fix f -> f (Fix f))
-> (f (Fix f) -> Fix f)
-> Iso (Fix f) (Fix f) (f (Fix f)) (f (Fix f))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Fix f -> f (Fix f)
forall (f :: * -> *). Fix f -> f (Fix f)
unFix f (Fix f) -> Fix f
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (Exchange
   (f (Fix f)) (f (Fix f)) (f (Fix f)) (Identity (f (Fix f)))
 -> Exchange (f (Fix f)) (f (Fix f)) (Fix f) (Identity (Fix f)))
-> p (f (Fix f)) (f (Fix f)) -> p (Fix f) (Fix f)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p (f (Fix f)) (f (Fix f))
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p (f (Fix f)) (f (Fix f))
json)
instance (Functor f, Typeable f, Json (f (Fix f))) => Json (Mu f) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Mu f) (Mu f)
json = (Mu f -> Fix f)
-> (Fix f -> Mu f) -> Iso (Mu f) (Mu f) (Fix f) (Fix f)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((f (Fix f) -> Fix f) -> Mu f -> Fix f
forall (f :: * -> *) a. (f a -> a) -> Mu f -> a
foldMu f (Fix f) -> Fix f
forall (f :: * -> *). f (Fix f) -> Fix f
Fix) ((Fix f -> f (Fix f)) -> Fix f -> Mu f
forall (f :: * -> *) a. Functor f => (a -> f a) -> a -> Mu f
unfoldMu Fix f -> f (Fix f)
forall (f :: * -> *). Fix f -> f (Fix f)
unFix) (Exchange (Fix f) (Fix f) (Fix f) (Identity (Fix f))
 -> Exchange (Fix f) (Fix f) (Mu f) (Identity (Mu f)))
-> p (Fix f) (Fix f) -> p (Mu f) (Mu f)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(Fix f)
instance (Functor f, Typeable f, Json (f (Fix f))) => Json (Nu f) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Nu f) (Nu f)
json = (Nu f -> Fix f)
-> (Fix f -> Nu f) -> Iso (Nu f) (Nu f) (Fix f) (Fix f)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((f (Fix f) -> Fix f) -> Nu f -> Fix f
forall (f :: * -> *) a. Functor f => (f a -> a) -> Nu f -> a
foldNu f (Fix f) -> Fix f
forall (f :: * -> *). f (Fix f) -> Fix f
Fix) ((Fix f -> f (Fix f)) -> Fix f -> Nu f
forall a (f :: * -> *). (a -> f a) -> a -> Nu f
unfoldNu Fix f -> f (Fix f)
forall (f :: * -> *). Fix f -> f (Fix f)
unFix) (Exchange (Fix f) (Fix f) (Fix f) (Identity (Fix f))
 -> Exchange (Fix f) (Fix f) (Nu f) (Identity (Nu f)))
-> p (Fix f) (Fix f) -> p (Nu f) (Nu f)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(Fix f)

-- jsonTag
instance Json b => Json (Tagged a b) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Tagged a b) (Tagged a b)
json = Exchange b b b (Identity b)
-> Exchange b b (Tagged a b) (Identity (Tagged a b))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Tagged a b) (Tagged a b) b b
coerced (Exchange b b b (Identity b)
 -> Exchange b b (Tagged a b) (Identity (Tagged a b)))
-> p b b -> p (Tagged a b) (Tagged a b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @b
  jsonOmitField :: Maybe (APrism' (Tagged a b) ())
jsonOmitField = (Market () () b (Identity b)
-> Market () () (Tagged a b) (Identity (Tagged a b))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Tagged a b) (Tagged a b) b b
coerced (Market () () b (Identity b)
 -> Market () () (Tagged a b) (Identity (Tagged a b)))
-> (Market () () () (Identity ()) -> Market () () b (Identity b))
-> APrism' (Tagged a b) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Market () () () (Identity ()) -> Market () () b (Identity b))
 -> APrism' (Tagged a b) ())
-> Maybe
     (Market () () () (Identity ()) -> Market () () b (Identity b))
-> Maybe (APrism' (Tagged a b) ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Json a => Maybe (APrism' a ())
jsonOmitField @b
  jsonKey :: Maybe
  (forall (k :: * -> * -> *).
   JsonStr k =>
   k (Tagged a b) (Tagged a b))
jsonKey = (forall (k :: * -> * -> *).
 JsonStr k =>
 k b b -> k (Tagged a b) (Tagged a b))
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
-> Maybe
     (forall (k :: * -> * -> *).
      JsonStr k =>
      k (Tagged a b) (Tagged a b))
forall a b.
(forall (k :: * -> * -> *). JsonStr k => k a a -> k b b)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
overKey (Exchange b b b (Identity b)
-> Exchange b b (Tagged a b) (Identity (Tagged a b))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso (Tagged a b) (Tagged a b) b b
coerced (Exchange b b b (Identity b)
 -> Exchange b b (Tagged a b) (Identity (Tagged a b)))
-> k b b -> k (Tagged a b) (Tagged a b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~) (forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
jsonKey @b)
  jsonKeyList :: Maybe
  (forall (k :: * -> * -> *).
   JsonStr k =>
   k [Tagged a b] [Tagged a b])
jsonKeyList = (forall (k :: * -> * -> *).
 JsonStr k =>
 k [b] [b] -> k [Tagged a b] [Tagged a b])
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k [b] [b])
-> Maybe
     (forall (k :: * -> * -> *).
      JsonStr k =>
      k [Tagged a b] [Tagged a b])
forall a b.
(forall (k :: * -> * -> *). JsonStr k => k a a -> k b b)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k a a)
-> Maybe (forall (k :: * -> * -> *). JsonStr k => k b b)
overKey (Exchange [b] [b] [b] (Identity [b])
-> Exchange [b] [b] [Tagged a b] (Identity [Tagged a b])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [Tagged a b] [Tagged a b] [b] [b]
coerced (Exchange [b] [b] [b] (Identity [b])
 -> Exchange [b] [b] [Tagged a b] (Identity [Tagged a b]))
-> k [b] [b] -> k [Tagged a b] [Tagged a b]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~) (forall a.
Json a =>
Maybe (forall (k :: * -> * -> *). JsonStr k => k [a] [a])
jsonKeyList @b)

-- these
instance (Json a, Json b) => Json (These a b) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (These a b) (These a b)
json = [p (These a b) (These a b)] -> p (These a b) (These a b)
forall (f :: * -> *) a.
(Foldable f, DisjunctiveMonoid a) =>
f a -> a
orP
    [ Market (a, b) (a, b) (a, b) (Identity (a, b))
-> Market (a, b) (a, b) (These a b) (Identity (These a b))
forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (a, b) (f (a, b)) -> p (These a b) (f (These a b))
_These (Market (a, b) (a, b) (a, b) (Identity (a, b))
 -> Market (a, b) (a, b) (These a b) (Identity (These a b)))
-> p (a, b) (a, b) -> p (These a b) (These a b)
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? (forall (q :: * -> * -> *). JsonObj p q => q (a, b) (a, b))
-> p (a, b) (a, b)
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObjectStrict (Text
"This" Text -> p a a -> q a a
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json q a a -> q b b -> q (a, b) (a, b)
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< Text
"That" Text -> p b b -> q b b
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p b b
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p b b
json)
    , Market a a a (Identity a)
-> Market a a (These a b) (Identity (These a b))
forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f a) -> p (These a b) (f (These a b))
_This (Market a a a (Identity a)
 -> Market a a (These a b) (Identity (These a b)))
-> p a a -> p (These a b) (These a b)
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? Text -> p a a -> p a a
forall a b. Text -> p a b -> p a b
forall (p :: * -> * -> *) a b. JsonVal p => Text -> p a b -> p a b
jsonTag Text
"This" p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
    , Market b b b (Identity b)
-> Market b b (These a b) (Identity (These a b))
forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p b (f b) -> p (These a b) (f (These a b))
_That (Market b b b (Identity b)
 -> Market b b (These a b) (Identity (These a b)))
-> p b b -> p (These a b) (These a b)
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? Text -> p b b -> p b b
forall a b. Text -> p a b -> p a b
forall (p :: * -> * -> *) a b. JsonVal p => Text -> p a b -> p a b
jsonTag Text
"That" p b b
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p b b
json
    ]
instance (Json (f a), Json (g a)) => Json (These1 f g a) where
  json :: forall (p :: * -> * -> *).
JsonVal p =>
p (These1 f g a) (These1 f g a)
json = (These1 f g a -> These (f a) (g a))
-> (These (f a) (g a) -> These1 f g a)
-> Iso
     (These1 f g a)
     (These1 f g a)
     (These (f a) (g a))
     (These (f a) (g a))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso These1 f g a -> These (f a) (g a)
forall {f :: * -> *} {g :: * -> *} {a}.
These1 f g a -> These (f a) (g a)
fromThese1 These (f a) (g a) -> These1 f g a
forall {f :: * -> *} {a} {g :: * -> *}.
These (f a) (g a) -> These1 f g a
toThese1 (Exchange
   (These (f a) (g a))
   (These (f a) (g a))
   (These (f a) (g a))
   (Identity (These (f a) (g a)))
 -> Exchange
      (These (f a) (g a))
      (These (f a) (g a))
      (These1 f g a)
      (Identity (These1 f g a)))
-> p (These (f a) (g a)) (These (f a) (g a))
-> p (These1 f g a) (These1 f g a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(These (f a) (g a))
    where
      fromThese1 :: These1 f g a -> These (f a) (g a)
fromThese1 = \case
        This1 f a
a -> f a -> These (f a) (g a)
forall a b. a -> These a b
This f a
a
        That1 g a
b -> g a -> These (f a) (g a)
forall a b. b -> These a b
That g a
b
        These1 f a
a g a
b -> f a -> g a -> These (f a) (g a)
forall a b. a -> b -> These a b
These f a
a g a
b
      toThese1 :: These (f a) (g a) -> These1 f g a
toThese1 = \case
        This f a
a -> f a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1 f a
a
        That g a
b -> g a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1 g a
b
        These f a
a g a
b -> f a -> g a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
a g a
b

-- strict
instance Json a => Json (Strict.Maybe a) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Maybe a) (Maybe a)
json = (Maybe a -> Maybe a)
-> (Maybe a -> Maybe a)
-> Iso (Maybe a) (Maybe a) (Maybe a) (Maybe a)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Maybe a -> Maybe a
forall lazy strict. Strict lazy strict => strict -> lazy
Strict.toLazy Maybe a -> Maybe a
forall lazy strict. Strict lazy strict => lazy -> strict
Strict.toStrict (Exchange (Maybe a) (Maybe a) (Maybe a) (Identity (Maybe a))
 -> Exchange (Maybe a) (Maybe a) (Maybe a) (Identity (Maybe a)))
-> p (Maybe a) (Maybe a) -> p (Maybe a) (Maybe a)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(Maybe a)
  jsonOmitField :: Maybe (APrism' (Maybe a) ())
jsonOmitField = APrism' (Maybe a) () -> Maybe (APrism' (Maybe a) ())
forall a. a -> Maybe a
Just (Maybe a -> (Maybe a -> Bool) -> Prism' (Maybe a) ()
forall a. a -> (a -> Bool) -> Prism' a ()
nearly Maybe a
forall a. Maybe a
Strict.Nothing Maybe a -> Bool
forall a. Maybe a -> Bool
Strict.isNothing)
instance (Json a, Json b) => Json (Strict.Either a b) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Either a b) (Either a b)
json = (Either a b -> Either a b)
-> (Either a b -> Either a b)
-> Iso (Either a b) (Either a b) (Either a b) (Either a b)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Either a b -> Either a b
forall lazy strict. Strict lazy strict => strict -> lazy
Strict.toLazy Either a b -> Either a b
forall lazy strict. Strict lazy strict => lazy -> strict
Strict.toStrict (Exchange
   (Either a b) (Either a b) (Either a b) (Identity (Either a b))
 -> Exchange
      (Either a b) (Either a b) (Either a b) (Identity (Either a b)))
-> p (Either a b) (Either a b) -> p (Either a b) (Either a b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(Either a b)
instance (Json a, Json b) => Json (Strict.These a b) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (These a b) (These a b)
json = (These a b -> These a b)
-> (These a b -> These a b)
-> Iso (These a b) (These a b) (These a b) (These a b)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso These a b -> These a b
forall lazy strict. Strict lazy strict => strict -> lazy
Strict.toLazy These a b -> These a b
forall lazy strict. Strict lazy strict => lazy -> strict
Strict.toStrict (Exchange
   (These a b) (These a b) (These a b) (Identity (These a b))
 -> Exchange
      (These a b) (These a b) (These a b) (Identity (These a b)))
-> p (These a b) (These a b) -> p (These a b) (These a b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(These a b)
instance (Json a, Json b) => Json (Strict.Pair a b) where
  json :: forall (p :: * -> * -> *). JsonVal p => p (Pair a b) (Pair a b)
json = (Pair a b -> (a, b))
-> ((a, b) -> Pair a b) -> Iso (Pair a b) (Pair a b) (a, b) (a, b)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Pair a b -> (a, b)
forall lazy strict. Strict lazy strict => strict -> lazy
Strict.toLazy (a, b) -> Pair a b
forall lazy strict. Strict lazy strict => lazy -> strict
Strict.toStrict (Exchange (a, b) (a, b) (a, b) (Identity (a, b))
 -> Exchange (a, b) (a, b) (Pair a b) (Identity (Pair a b)))
-> p (a, b) (a, b) -> p (Pair a b) (Pair a b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
json @(a, b)

-- Generics

-- | The `GHC.Generic` `Json` grammar, by @aeson@'s default options.
instance
  ( GHC.Generic a, GHC.Rep a ~ GHC.D1 d f, GSum f, Typeable a
  , EnumTag (AllNullary f) a
  ) => Json (GHC.Generically a) where
    json :: forall (p :: * -> * -> *).
JsonVal p =>
p (Generically a) (Generically a)
json = (Generically a -> a)
-> (a -> Generically a)
-> p a a
-> p (Generically a) (Generically a)
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 (\(GHC.Generically a
a) -> a
a) a -> Generically a
forall a. a -> Generically a
GHC.Generically
      (Options -> p a a
forall a (d :: Meta) (f :: * -> *) (p :: * -> * -> *).
(Generic a, Rep a ~ D1 d f, GSum f, Typeable a,
 EnumTag (AllNullary f) a, JsonVal p) =>
Options -> p a a
jsonGeneric Options
Aeson.defaultOptions)
    {-# INLINABLE json #-}

{- | The `GHC.Generic` `Json` grammar by @aeson@'s `Aeson.Options`,
compatible with @aeson@'s generic instances by the same options,
defined as a `rule` named by its `Typeable` type, so that each
instantiation of a parametric type is its own (possibly recursive)
definition.
-}
jsonGeneric
  :: forall a d f p
   . ( GHC.Generic a, GHC.Rep a ~ GHC.D1 d f, GSum f, Typeable a
     , EnumTag (AllNullary f) a, JsonVal p )
  => Aeson.Options -> p a a
jsonGeneric :: forall a (d :: Meta) (f :: * -> *) (p :: * -> * -> *).
(Generic a, Rep a ~ D1 d f, GSum f, Typeable a,
 EnumTag (AllNullary f) a, JsonVal p) =>
Options -> p a a
jsonGeneric Options
opts = p a a -> p a a
forall a (p :: * -> * -> *).
(Typeable a, Ruled (p a a)) =>
p a a -> p a a
ruleTyped (p a a -> p a a) -> p a a -> p a a
forall a b. (a -> b) -> a -> b
$ case (forall (enum :: Bool) a. EnumTag enum a => Maybe (a -> Int)
enumIndex @(AllNullary f) @a, forall (f :: * -> *) x. GSum f => Options -> Maybe [(Text, f x)]
gtable @f Options
opts) of
  (Just a -> Int
indexOf, Just [(Text, f (ZonkAny 1))]
table)
    | Options -> Bool
Aeson.allNullaryToStringTag Options
opts
    , forall (f :: * -> *). GSum f => Int
gconCount @f Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 Bool -> Bool -> Bool
|| Options -> Bool
Aeson.tagSingleConstructors Options
opts ->
        (a -> Int) -> [(Text, a)] -> p a a
forall a. (a -> Int) -> [(Text, a)] -> p a a
forall (p :: * -> * -> *) a.
JsonStr p =>
(a -> Int) -> [(Text, a)] -> p a a
jsonEnumWith a -> Int
indexOf [(Text
tag, Rep a (ZonkAny 1) -> a
forall a x. Generic a => Rep a x -> a
forall x. Rep a x -> a
GHC.to (f (ZonkAny 1) -> M1 D d f (ZonkAny 1)
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 f (ZonkAny 1)
v)) | (Text
tag, f (ZonkAny 1)
v) <- [(Text, f (ZonkAny 1))]
table]
  (Maybe (a -> Int), Maybe [(Text, f (ZonkAny 1))])
_ -> (a -> f (ZonkAny 2))
-> (f (ZonkAny 2) -> a)
-> p (f (ZonkAny 2)) (f (ZonkAny 2))
-> p a a
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 (M1 D d f (ZonkAny 2) -> f (ZonkAny 2)
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1 (M1 D d f (ZonkAny 2) -> f (ZonkAny 2))
-> (a -> M1 D d f (ZonkAny 2)) -> a -> f (ZonkAny 2)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> M1 D d f (ZonkAny 2)
a -> Rep a (ZonkAny 2)
forall x. a -> Rep a x
forall a x. Generic a => a -> Rep a x
GHC.from) (Rep a (ZonkAny 2) -> a
forall a x. Generic a => Rep a x -> a
forall x. Rep a x -> a
GHC.to (Rep a (ZonkAny 2) -> a)
-> (f (ZonkAny 2) -> Rep a (ZonkAny 2)) -> f (ZonkAny 2) -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (ZonkAny 2) -> M1 D d f (ZonkAny 2)
f (ZonkAny 2) -> Rep a (ZonkAny 2)
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1) (Options -> p (f (ZonkAny 2)) (f (ZonkAny 2))
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
gsum Options
opts)
{-# INLINE jsonGeneric #-}

-- | Whether a `GHC.Generic` representation's constructors are all nullary.
type AllNullary :: (Type -> Type) -> Bool
type family AllNullary f where
  AllNullary (f GHC.:+: g) = AllNullary f && AllNullary g
  AllNullary (GHC.C1 c GHC.U1) = 'True
  AllNullary f = 'False

{- | The index of an enumeration's constructor, by `Exts.dataToTag#`,
which only enumerations need, since newtypes have no `Exts.DataToTag`.
-}
class EnumTag (enum :: Bool) a where
  enumIndex :: Maybe (a -> Int)
instance Exts.DataToTag a => EnumTag 'True a where
  enumIndex :: Maybe (a -> Int)
enumIndex = (a -> Int) -> Maybe (a -> Int)
forall a. a -> Maybe a
Just (\a
a -> Int# -> Int
Exts.I# (a -> Int#
forall a. DataToTag a => a -> Int#
Exts.dataToTag# a
a))
instance EnumTag 'False a where
  enumIndex :: Maybe (a -> Int)
enumIndex = Maybe (a -> Int)
forall a. Maybe a
Nothing

gsum :: forall f p x. (GSum f, JsonVal p) => Aeson.Options -> p (f x) (f x)
gsum :: forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
gsum Options
opts
  | forall (f :: * -> *). GSum f => Int
gconCount @f Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1, Bool -> Bool
not (Options -> Bool
Aeson.tagSingleConstructors Options
opts) = Options -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (f x) (f x)
gcons Options
opts
  | Options -> Bool
Aeson.allNullaryToStringTag Options
opts, Just p (f x) (f x)
names <- Options -> Maybe (p (f x) (f x))
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> Maybe (p (f x) (f x))
forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> Maybe (p (f x) (f x))
genum Options
opts = p (f x) (f x)
names
  | Bool
otherwise = case Options -> SumEncoding
Aeson.sumEncoding Options
opts of
      Aeson.TaggedObject String
tagField String
contentsField ->
        Options -> Text -> Text -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> Text -> Text -> p (f x) (f x)
forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> Text -> Text -> p (f x) (f x)
gtagged Options
opts (String -> Text
Text.pack String
tagField) (String -> Text
Text.pack String
contentsField)
      SumEncoding
Aeson.UntaggedValue -> Options -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (f x) (f x)
guntagged Options
opts
      SumEncoding
Aeson.ObjectWithSingleField -> Options -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (f x) (f x)
gsingleField Options
opts
      SumEncoding
Aeson.TwoElemArray -> Options -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (f x) (f x)
gtwoElements Options
opts
{-# INLINE gsum #-}

-- | An object, rejecting other properties by `Aeson.rejectUnknownFields`.
gobject
  :: JsonVal p => Aeson.Options -> (forall q. JsonObj p q => q a b) -> p a b
gobject :: forall (p :: * -> * -> *) a b.
JsonVal p =>
Options
-> (forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
gobject Options
opts forall (q :: * -> * -> *). JsonObj p q => q a b
obj
  | Options -> Bool
Aeson.rejectUnknownFields Options
opts = (forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObjectStrict q a b
forall (q :: * -> * -> *). JsonObj p q => q a b
obj
  | Bool
otherwise = (forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall a b.
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
jsonObject q a b
forall (q :: * -> * -> *). JsonObj p q => q a b
obj
{-# INLINE gobject #-}

class GSum f where
  gconCount :: Int
  -- | The contents of a constructor, by itself.
  gcons :: JsonVal p => Aeson.Options -> p (f x) (f x)
  -- | Constructor names, when all constructors are nullary.
  genum :: JsonVal p => Aeson.Options -> Maybe (p (f x) (f x))
  -- | Constructors, by their names, when all constructors are nullary.
  gtable :: Aeson.Options -> Maybe [(Text, f x)]
  -- | Constructors by `Aeson.TaggedObject`, with tag & contents fields.
  gtagged :: JsonVal p => Aeson.Options -> Text -> Text -> p (f x) (f x)
  -- | Constructors by `Aeson.UntaggedValue`.
  guntagged :: JsonVal p => Aeson.Options -> p (f x) (f x)
  -- | Constructors by `Aeson.ObjectWithSingleField`.
  gsingleField :: JsonVal p => Aeson.Options -> p (f x) (f x)
  -- | Constructors by `Aeson.TwoElemArray`.
  gtwoElements :: JsonVal p => Aeson.Options -> p (f x) (f x)

instance (GSum f, GSum g) => GSum (f GHC.:+: g) where
  gconCount :: Int
gconCount = forall (f :: * -> *). GSum f => Int
gconCount @f Int -> Int -> Int
forall a. Num a => a -> a -> a
+ forall (f :: * -> *). GSum f => Int
gconCount @g
  gcons :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> p ((:+:) f g x) ((:+:) f g x)
gcons Options
opts = Exchange
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Identity (Either (f x) (g x)))
-> Exchange
     (Either (f x) (g x))
     (Either (f x) (g x))
     ((:+:) f g x)
     (Identity ((:+:) f g x))
forall (f :: * -> *) (g :: * -> *) x (p :: * -> * -> *)
       (f :: * -> *).
(Profunctor p, Functor f) =>
p (Either (f x) (g x)) (f (Either (f x) (g x)))
-> p ((:+:) f g x) (f ((:+:) f g x))
sumIso (Exchange
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Identity (Either (f x) (g x)))
 -> Exchange
      (Either (f x) (g x))
      (Either (f x) (g x))
      ((:+:) f g x)
      (Identity ((:+:) f g x)))
-> p (Either (f x) (g x)) (Either (f x) (g x))
-> p ((:+:) f g x) ((:+:) f g x)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ Options -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (f x) (f x)
gcons Options
opts p (f x) (f x)
-> p (g x) (g x) -> p (Either (f x) (g x)) (Either (f x) (g x))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< Options -> p (g x) (g x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (g x) (g x)
gcons Options
opts
  genum :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> Maybe (p ((:+:) f g x) ((:+:) f g x))
genum Options
opts =
    (p (f x) (f x) -> p (g x) (g x) -> p ((:+:) f g x) ((:+:) f g x))
-> Maybe (p (f x) (f x))
-> Maybe (p (g x) (g x))
-> Maybe (p ((:+:) f g x) ((:+:) f g x))
forall a b c. (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (\p (f x) (f x)
l p (g x) (g x)
r -> Exchange
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Identity (Either (f x) (g x)))
-> Exchange
     (Either (f x) (g x))
     (Either (f x) (g x))
     ((:+:) f g x)
     (Identity ((:+:) f g x))
forall (f :: * -> *) (g :: * -> *) x (p :: * -> * -> *)
       (f :: * -> *).
(Profunctor p, Functor f) =>
p (Either (f x) (g x)) (f (Either (f x) (g x)))
-> p ((:+:) f g x) (f ((:+:) f g x))
sumIso (Exchange
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Identity (Either (f x) (g x)))
 -> Exchange
      (Either (f x) (g x))
      (Either (f x) (g x))
      ((:+:) f g x)
      (Identity ((:+:) f g x)))
-> p (Either (f x) (g x)) (Either (f x) (g x))
-> p ((:+:) f g x) ((:+:) f g x)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p (f x) (f x)
l p (f x) (f x)
-> p (g x) (g x) -> p (Either (f x) (g x)) (Either (f x) (g x))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p (g x) (g x)
r) (forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> Maybe (p (f x) (f x))
genum @f Options
opts) (forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> Maybe (p (f x) (f x))
genum @g Options
opts)
  gtable :: forall x. Options -> Maybe [(Text, (:+:) f g x)]
gtable Options
opts = ([(Text, f x)] -> [(Text, g x)] -> [(Text, (:+:) f g x)])
-> Maybe [(Text, f x)]
-> Maybe [(Text, g x)]
-> Maybe [(Text, (:+:) f g x)]
forall a b c. (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
    (\[(Text, f x)]
l [(Text, g x)]
r -> ((Text, f x) -> (Text, (:+:) f g x))
-> [(Text, f x)] -> [(Text, (:+:) f g x)]
forall a b. (a -> b) -> [a] -> [b]
map ((f x -> (:+:) f g x) -> (Text, f x) -> (Text, (:+:) f g x)
forall a b. (a -> b) -> (Text, a) -> (Text, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f x -> (:+:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
GHC.L1) [(Text, f x)]
l [(Text, (:+:) f g x)]
-> [(Text, (:+:) f g x)] -> [(Text, (:+:) f g x)]
forall a. Semigroup a => a -> a -> a
<> ((Text, g x) -> (Text, (:+:) f g x))
-> [(Text, g x)] -> [(Text, (:+:) f g x)]
forall a b. (a -> b) -> [a] -> [b]
map ((g x -> (:+:) f g x) -> (Text, g x) -> (Text, (:+:) f g x)
forall a b. (a -> b) -> (Text, a) -> (Text, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap g x -> (:+:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
GHC.R1) [(Text, g x)]
r)
    (forall (f :: * -> *) x. GSum f => Options -> Maybe [(Text, f x)]
gtable @f Options
opts) (forall (f :: * -> *) x. GSum f => Options -> Maybe [(Text, f x)]
gtable @g Options
opts)
  gtagged :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> Text -> Text -> p ((:+:) f g x) ((:+:) f g x)
gtagged Options
opts Text
tagField Text
contentsField = Exchange
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Identity (Either (f x) (g x)))
-> Exchange
     (Either (f x) (g x))
     (Either (f x) (g x))
     ((:+:) f g x)
     (Identity ((:+:) f g x))
forall (f :: * -> *) (g :: * -> *) x (p :: * -> * -> *)
       (f :: * -> *).
(Profunctor p, Functor f) =>
p (Either (f x) (g x)) (f (Either (f x) (g x)))
-> p ((:+:) f g x) (f ((:+:) f g x))
sumIso
    (Exchange
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Identity (Either (f x) (g x)))
 -> Exchange
      (Either (f x) (g x))
      (Either (f x) (g x))
      ((:+:) f g x)
      (Identity ((:+:) f g x)))
-> p (Either (f x) (g x)) (Either (f x) (g x))
-> p ((:+:) f g x) ((:+:) f g x)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ Options -> Text -> Text -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> Text -> Text -> p (f x) (f x)
forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> Text -> Text -> p (f x) (f x)
gtagged Options
opts Text
tagField Text
contentsField
    p (f x) (f x)
-> p (g x) (g x) -> p (Either (f x) (g x)) (Either (f x) (g x))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< Options -> Text -> Text -> p (g x) (g x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> Text -> Text -> p (f x) (f x)
forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> Text -> Text -> p (g x) (g x)
gtagged Options
opts Text
tagField Text
contentsField
  guntagged :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> p ((:+:) f g x) ((:+:) f g x)
guntagged Options
opts = Exchange
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Identity (Either (f x) (g x)))
-> Exchange
     (Either (f x) (g x))
     (Either (f x) (g x))
     ((:+:) f g x)
     (Identity ((:+:) f g x))
forall (f :: * -> *) (g :: * -> *) x (p :: * -> * -> *)
       (f :: * -> *).
(Profunctor p, Functor f) =>
p (Either (f x) (g x)) (f (Either (f x) (g x)))
-> p ((:+:) f g x) (f ((:+:) f g x))
sumIso (Exchange
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Identity (Either (f x) (g x)))
 -> Exchange
      (Either (f x) (g x))
      (Either (f x) (g x))
      ((:+:) f g x)
      (Identity ((:+:) f g x)))
-> p (Either (f x) (g x)) (Either (f x) (g x))
-> p ((:+:) f g x) ((:+:) f g x)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ Options -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (f x) (f x)
guntagged Options
opts p (f x) (f x)
-> p (g x) (g x) -> p (Either (f x) (g x)) (Either (f x) (g x))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< Options -> p (g x) (g x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (g x) (g x)
guntagged Options
opts
  gsingleField :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> p ((:+:) f g x) ((:+:) f g x)
gsingleField Options
opts = Exchange
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Identity (Either (f x) (g x)))
-> Exchange
     (Either (f x) (g x))
     (Either (f x) (g x))
     ((:+:) f g x)
     (Identity ((:+:) f g x))
forall (f :: * -> *) (g :: * -> *) x (p :: * -> * -> *)
       (f :: * -> *).
(Profunctor p, Functor f) =>
p (Either (f x) (g x)) (f (Either (f x) (g x)))
-> p ((:+:) f g x) (f ((:+:) f g x))
sumIso (Exchange
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Identity (Either (f x) (g x)))
 -> Exchange
      (Either (f x) (g x))
      (Either (f x) (g x))
      ((:+:) f g x)
      (Identity ((:+:) f g x)))
-> p (Either (f x) (g x)) (Either (f x) (g x))
-> p ((:+:) f g x) ((:+:) f g x)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ Options -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (f x) (f x)
gsingleField Options
opts p (f x) (f x)
-> p (g x) (g x) -> p (Either (f x) (g x)) (Either (f x) (g x))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< Options -> p (g x) (g x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (g x) (g x)
gsingleField Options
opts
  gtwoElements :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> p ((:+:) f g x) ((:+:) f g x)
gtwoElements Options
opts = Exchange
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Either (f x) (g x))
  (Identity (Either (f x) (g x)))
-> Exchange
     (Either (f x) (g x))
     (Either (f x) (g x))
     ((:+:) f g x)
     (Identity ((:+:) f g x))
forall (f :: * -> *) (g :: * -> *) x (p :: * -> * -> *)
       (f :: * -> *).
(Profunctor p, Functor f) =>
p (Either (f x) (g x)) (f (Either (f x) (g x)))
-> p ((:+:) f g x) (f ((:+:) f g x))
sumIso (Exchange
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Either (f x) (g x))
   (Identity (Either (f x) (g x)))
 -> Exchange
      (Either (f x) (g x))
      (Either (f x) (g x))
      ((:+:) f g x)
      (Identity ((:+:) f g x)))
-> p (Either (f x) (g x)) (Either (f x) (g x))
-> p ((:+:) f g x) ((:+:) f g x)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ Options -> p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (f x) (f x)
gtwoElements Options
opts p (f x) (f x)
-> p (g x) (g x) -> p (Either (f x) (g x)) (Either (f x) (g x))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
CocartesianMonoidal p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< Options -> p (g x) (g x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => Options -> p (g x) (g x)
gtwoElements Options
opts
  {-# INLINE gconCount #-}
  {-# INLINE gcons #-}
  {-# INLINE genum #-}
  {-# INLINE gtable #-}
  {-# INLINE gtagged #-}
  {-# INLINE guntagged #-}
  {-# INLINE gsingleField #-}
  {-# INLINE gtwoElements #-}

sumIso :: Iso' ((f GHC.:+: g) x) (Either (f x) (g x))
sumIso :: forall (f :: * -> *) (g :: * -> *) x (p :: * -> * -> *)
       (f :: * -> *).
(Profunctor p, Functor f) =>
p (Either (f x) (g x)) (f (Either (f x) (g x)))
-> p ((:+:) f g x) (f ((:+:) f g x))
sumIso = ((:+:) f g x -> Either (f x) (g x))
-> (Either (f x) (g x) -> (:+:) f g x)
-> Iso
     ((:+:) f g x)
     ((:+:) f g x)
     (Either (f x) (g x))
     (Either (f x) (g x))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
  (\case GHC.L1 f x
a -> f x -> Either (f x) (g x)
forall a b. a -> Either a b
Left f x
a; GHC.R1 g x
b -> g x -> Either (f x) (g x)
forall a b. b -> Either a b
Right g x
b)
  ((f x -> (:+:) f g x)
-> (g x -> (:+:) f g x) -> Either (f x) (g x) -> (:+:) f g x
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either f x -> (:+:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
GHC.L1 g x -> (:+:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
GHC.R1)

instance (GHC.Constructor c, GFields f, GContents f, GNullary f)
  => GSum (GHC.C1 c f) where
    gconCount :: Int
gconCount = Int
1
    gcons :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> p (C1 c f x) (C1 c f x)
gcons Options
opts = f x -> M1 C c f x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 (f x -> M1 C c f x) -> p (f x) (f x) -> p (f x) (M1 C c f x)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> p a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p (f x) (f x)
contents p (f x) (M1 C c f x)
-> (M1 C c f x -> f x) -> p (M1 C c f x) (M1 C c f x)
forall a b c (q :: * -> * -> *).
Coercible b a =>
p b c -> q a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# M1 C c f x -> f x
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1
      where
        contents :: p (f x) (f x)
contents
          | forall (c :: Meta). Constructor c => Bool
gconIsRecord @c = case Maybe (p (f x) (f x))
forall (f :: * -> *) (p :: * -> * -> *) x.
(GFields f, JsonVal p) =>
Maybe (p (f x) (f x))
forall (p :: * -> * -> *) x. JsonVal p => Maybe (p (f x) (f x))
gfield of
              Just p (f x) (f x)
field | Options -> Bool
Aeson.unwrapUnaryRecords Options
opts -> p (f x) (f x)
field
              Maybe (p (f x) (f x))
_ -> Options
-> (forall (q :: * -> * -> *). JsonObj p q => q (f x) (f x))
-> p (f x) (f x)
forall (p :: * -> * -> *) a b.
JsonVal p =>
Options
-> (forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
gobject Options
opts (Options -> q (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GFields f, JsonVal p, JsonObj p q) =>
Options -> q (f x) (f x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonObj p q) =>
Options -> q (f x) (f x)
gfields Options
opts)
          | Bool
otherwise = p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GContents f, JsonVal p) =>
p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => p (f x) (f x)
gcontents
    genum :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> Maybe (p (C1 c f x) (C1 c f x))
genum Options
opts = forall (f :: * -> *) x. GNullary f => Maybe (f x)
gnullary @f Maybe (f x)
-> (f x -> p (C1 c f x) (C1 c f x))
-> Maybe (p (C1 c f x) (C1 c f x))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \f x
v ->
      (C1 c f x -> ())
-> (() -> C1 c f x) -> p () () -> p (C1 c f x) (C1 c f x)
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 (() -> C1 c f x -> ()
forall a b. a -> b -> a
const ()) (C1 c f x -> () -> C1 c f x
forall a b. a -> b -> a
const (f x -> C1 c f x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 f x
v)) (String -> p () ()
forall a. IsString a => String -> a
fromString (forall (c :: Meta). Constructor c => Options -> String
gconTag @c Options
opts))
    gtable :: forall x. Options -> Maybe [(Text, C1 c f x)]
gtable Options
opts =
      forall (f :: * -> *) x. GNullary f => Maybe (f x)
gnullary @f Maybe (f x)
-> (f x -> [(Text, C1 c f x)]) -> Maybe [(Text, C1 c f x)]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \f x
v -> [(String -> Text
Text.pack (forall (c :: Meta). Constructor c => Options -> String
gconTag @c Options
opts), f x -> C1 c f x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 f x
v)]
    gtagged :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> Text -> Text -> p (C1 c f x) (C1 c f x)
gtagged Options
opts Text
tagField Text
contentsField =
      f x -> M1 C c f x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 (f x -> M1 C c f x) -> p (f x) (f x) -> p (f x) (M1 C c f x)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> p a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. Options
-> (forall (q :: * -> * -> *). JsonObj p q => q (f x) (f x))
-> p (f x) (f x)
forall (p :: * -> * -> *) a b.
JsonVal p =>
Options
-> (forall (q :: * -> * -> *). JsonObj p q => q a b) -> p a b
gobject Options
opts (q () ()
forall (p :: * -> * -> *) (q :: * -> * -> *).
(JsonVal p, JsonObj p q) =>
q () ()
tag q () () -> q (f x) (f x) -> q (f x) (f x)
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* q (f x) (f x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonObj p q) =>
q (f x) (f x)
contents) p (f x) (M1 C c f x)
-> (M1 C c f x -> f x) -> p (M1 C c f x) (M1 C c f x)
forall a b c (q :: * -> * -> *).
Coercible b a =>
p b c -> q a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# M1 C c f x -> f x
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1
      where
        tag :: (JsonVal p, JsonObj p q) => q () ()
        tag :: forall (p :: * -> * -> *) (q :: * -> * -> *).
(JsonVal p, JsonObj p q) =>
q () ()
tag = Text
tagField Text -> p () () -> q () ()
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: String -> p () ()
forall a. IsString a => String -> a
fromString (forall (c :: Meta). Constructor c => Options -> String
gconTag @c Options
opts)
        contents :: (JsonVal p, JsonObj p q) => q (f x) (f x)
        contents :: forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonObj p q) =>
q (f x) (f x)
contents
          | forall (c :: Meta). Constructor c => Bool
gconIsRecord @c = Options -> q (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GFields f, JsonVal p, JsonObj p q) =>
Options -> q (f x) (f x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonObj p q) =>
Options -> q (f x) (f x)
gfields Options
opts
          | Just f x
v <- forall (f :: * -> *) x. GNullary f => Maybe (f x)
gnullary @f = (f x -> ()) -> (() -> f x) -> q () () -> q (f x) (f x)
forall a b c d. (a -> b) -> (c -> d) -> q b c -> q a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (() -> f x -> ()
forall a b. a -> b -> a
const ()) (f x -> () -> f x
forall a b. a -> b -> a
const f x
v) q () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP
          | Bool
otherwise = Text
contentsField Text -> p (f x) (f x) -> q (f x) (f x)
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GContents f, JsonVal p) =>
p (f x) (f x)
forall (p :: * -> * -> *) x. JsonVal p => p (f x) (f x)
gcontents
    guntagged :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> p (C1 c f x) (C1 c f x)
guntagged Options
opts = case forall (f :: * -> *) x. GNullary f => Maybe (f x)
gnullary @f of
      Just f x
v | Bool -> Bool
not (forall (c :: Meta). Constructor c => Bool
gconIsRecord @c) ->
        (C1 c f x -> ())
-> (() -> C1 c f x) -> p () () -> p (C1 c f x) (C1 c f x)
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 (() -> C1 c f x -> ()
forall a b. a -> b -> a
const ()) (C1 c f x -> () -> C1 c f x
forall a b. a -> b -> a
const (f x -> C1 c f x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 f x
v)) (String -> p () ()
forall a. IsString a => String -> a
fromString (forall (c :: Meta). Constructor c => Options -> String
gconTag @c Options
opts))
      Maybe (f x)
_ -> Options -> p (C1 c f x) (C1 c f x)
forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> p (C1 c f x) (C1 c f x)
gcons Options
opts
    gsingleField :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> p (C1 c f x) (C1 c f x)
gsingleField Options
opts =
      Text -> p (C1 c f x) (C1 c f x) -> p (C1 c f x) (C1 c f x)
forall a b. Text -> p a b -> p a b
forall (p :: * -> * -> *) a b. JsonVal p => Text -> p a b -> p a b
jsonTag (String -> Text
Text.pack (forall (c :: Meta). Constructor c => Options -> String
gconTag @c Options
opts)) (forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
gcons @(GHC.C1 c f) Options
opts)
    gtwoElements :: forall (p :: * -> * -> *) x.
JsonVal p =>
Options -> p (C1 c f x) (C1 c f x)
gtwoElements Options
opts = (C1 c f x -> ((), C1 c f x))
-> (((), C1 c f x) -> C1 c f x)
-> p ((), C1 c f x) ((), C1 c f x)
-> p (C1 c f x) (C1 c f x)
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 ((),) ((), C1 c f x) -> C1 c f x
forall a b. (a, b) -> b
snd
      (p () ()
-> p (C1 c f x) (C1 c f x) -> p ((), C1 c f x) ((), C1 c f x)
forall a b c d. p a b -> p c d -> p (a, c) (b, d)
forall (p :: * -> * -> *) a b c d.
JsonVal p =>
p a b -> p c d -> p (a, c) (b, d)
jsonPair (String -> p () ()
forall a. IsString a => String -> a
fromString (forall (c :: Meta). Constructor c => Options -> String
gconTag @c Options
opts)) (forall (f :: * -> *) (p :: * -> * -> *) x.
(GSum f, JsonVal p) =>
Options -> p (f x) (f x)
gcons @(GHC.C1 c f) Options
opts))
    {-# INLINE gconCount #-}
    {-# INLINE gcons #-}
    {-# INLINE genum #-}
    {-# INLINE gtable #-}
    {-# INLINE gtagged #-}
    {-# INLINE guntagged #-}
    {-# INLINE gsingleField #-}
    {-# INLINE gtwoElements #-}

-- | A constructor's tag, by `Aeson.constructorTagModifier`.
gconTag :: forall (c :: GHC.Meta). GHC.Constructor c => Aeson.Options -> String
gconTag :: forall (c :: Meta). Constructor c => Options -> String
gconTag Options
opts = Options -> ShowS
Aeson.constructorTagModifier Options
opts (forall (c :: Meta). Constructor c => String
gconName @c)

gconName :: forall (c :: GHC.Meta). GHC.Constructor c => String
gconName :: forall (c :: Meta). Constructor c => String
gconName = M1 C c U1 () -> String
forall {k} (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> String
forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
       (a :: k1).
t c f a -> String
GHC.conName (U1 () -> M1 C c U1 ()
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 U1 ()
forall k (p :: k). U1 p
GHC.U1 :: GHC.C1 c GHC.U1 ())

gconIsRecord :: forall (c :: GHC.Meta). GHC.Constructor c => Bool
gconIsRecord :: forall (c :: Meta). Constructor c => Bool
gconIsRecord = M1 C c U1 () -> Bool
forall {k} (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> Bool
forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
       (a :: k1).
t c f a -> Bool
GHC.conIsRecord (U1 () -> M1 C c U1 ()
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 U1 ()
forall k (p :: k). U1 p
GHC.U1 :: GHC.C1 c GHC.U1 ())

gselName :: forall (s :: GHC.Meta). GHC.Selector s => String
gselName :: forall (s :: Meta). Selector s => String
gselName = M1 S s U1 () -> String
forall {k} (s :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Selector s =>
t s f a -> String
forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
       (a :: k1).
t s f a -> String
GHC.selName (U1 () -> M1 S s U1 ()
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 U1 ()
forall k (p :: k). U1 p
GHC.U1 :: GHC.S1 s GHC.U1 ())

class GFields f where
  -- | A record's fields, by `Aeson.fieldLabelModifier`.
  gfields :: (JsonVal p, JsonObj p q) => Aeson.Options -> q (f x) (f x)
  -- | A record's field, when it's its only field.
  gfield :: JsonVal p => Maybe (p (f x) (f x))
instance (GHC.Selector s, Json a) => GFields (GHC.S1 s (GHC.K1 i a)) where
  gfields :: forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonObj p q) =>
Options -> q (S1 s (K1 i a) x) (S1 s (K1 i a) x)
gfields Options
opts = (K1 i a x -> M1 S s (K1 i a) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 (K1 i a x -> M1 S s (K1 i a) x)
-> (a -> K1 i a x) -> a -> M1 S s (K1 i a) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> K1 i a x
forall k i c (p :: k). c -> K1 i c p
GHC.K1) (a -> M1 S s (K1 i a) x) -> q a a -> q a (M1 S s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> q a b -> q a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. q a a
forall (p :: * -> * -> *) (q :: * -> * -> *).
(JsonVal p, JsonObj p q) =>
q a a
property q a (M1 S s (K1 i a) x)
-> (M1 S s (K1 i a) x -> a)
-> q (M1 S s (K1 i a) x) (M1 S s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible b a =>
q b c -> q a b -> q a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# K1 i a x -> a
forall k i c (p :: k). K1 i c p -> c
GHC.unK1 (K1 i a x -> a)
-> (M1 S s (K1 i a) x -> K1 i a x) -> M1 S s (K1 i a) x -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. M1 S s (K1 i a) x -> K1 i a x
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1
    where
      key :: Text
key = String -> Text
Text.pack (Options -> ShowS
Aeson.fieldLabelModifier Options
opts (forall (s :: Meta). Selector s => String
gselName @s))
      -- An omittable field, by `jsonOmitField`.
      property :: (JsonVal p, JsonObj p q) => q a a
      property :: forall (p :: * -> * -> *) (q :: * -> * -> *).
(JsonVal p, JsonObj p q) =>
q a a
property = case forall a. Json a => Maybe (APrism' a ())
jsonOmitField @a of
        Just APrism' a ()
omitted
          | Options -> Bool
Aeson.allowOmittedFields Options
opts Bool -> Bool -> Bool
|| Options -> Bool
Aeson.omitNothingFields Options
opts ->
              APrism' a () -> ((() -> a) -> (a -> Either a ()) -> q a a) -> q a a
forall s t a b r.
APrism s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r
withPrism APrism' a ()
omitted (((() -> a) -> (a -> Either a ()) -> q a a) -> q a a)
-> ((() -> a) -> (a -> Either a ()) -> q a a) -> q a a
forall a b. (a -> b) -> a -> b
$ \() -> a
omit a -> Either a ()
match ->
                let
                  present :: a -> Maybe a
present a
a
                    | Options -> Bool
Aeson.omitNothingFields Options
opts, Right () <- a -> Either a ()
match a
a =
                        Maybe a
forall a. Maybe a
Nothing
                    | Bool
otherwise = a -> Maybe a
forall a. a -> Maybe a
Just a
a
                in (a -> Maybe a) -> (Maybe a -> a) -> q (Maybe a) (Maybe a) -> q a a
forall a b c d. (a -> b) -> (c -> d) -> q b c -> q a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> Maybe a
present (a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe (() -> a
omit ())) (Text
key Text -> p a a -> q (Maybe a) (Maybe a)
forall a b. Text -> p a b -> q (Maybe a) (Maybe b)
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q (Maybe a) (Maybe b)
?: p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json)
        Maybe (APrism' a ())
_ -> Text
key Text -> p a a -> q a a
forall a b. Text -> p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonObj p q =>
Text -> p a b -> q a b
!: p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json
  gfield :: forall (p :: * -> * -> *) x.
JsonVal p =>
Maybe (p (S1 s (K1 i a) x) (S1 s (K1 i a) x))
gfield = p (M1 S s (K1 i a) x) (M1 S s (K1 i a) x)
-> Maybe (p (M1 S s (K1 i a) x) (M1 S s (K1 i a) x))
forall a. a -> Maybe a
Just ((K1 i a x -> M1 S s (K1 i a) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 (K1 i a x -> M1 S s (K1 i a) x)
-> (a -> K1 i a x) -> a -> M1 S s (K1 i a) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> K1 i a x
forall k i c (p :: k). c -> K1 i c p
GHC.K1) (a -> M1 S s (K1 i a) x) -> p a a -> p a (M1 S s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> p a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json p a (M1 S s (K1 i a) x)
-> (M1 S s (K1 i a) x -> a)
-> p (M1 S s (K1 i a) x) (M1 S s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible b a =>
p b c -> q a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# K1 i a x -> a
forall k i c (p :: k). K1 i c p -> c
GHC.unK1 (K1 i a x -> a)
-> (M1 S s (K1 i a) x -> K1 i a x) -> M1 S s (K1 i a) x -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. M1 S s (K1 i a) x -> K1 i a x
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1)
  {-# INLINE gfields #-}
  {-# INLINE gfield #-}
instance (GFields f, GFields g) => GFields (f GHC.:*: g) where
  gfields :: forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonObj p q) =>
Options -> q ((:*:) f g x) ((:*:) f g x)
gfields Options
opts = ((:*:) f g x -> f x)
-> ((:*:) f g x -> g x)
-> (f x -> g x -> (:*:) f g x)
-> q (f x) (f x)
-> q (g x) (g x)
-> q ((:*:) f g x) ((:*:) f g x)
forall (p :: * -> * -> *) s a c b d t.
Monoidal p =>
(s -> a) -> (s -> c) -> (b -> d -> t) -> p a b -> p c d -> p s t
dimap2 (\(f x
a GHC.:*: g x
_) -> f x
a) (\(f x
_ GHC.:*: g x
b) -> g x
b) f x -> g x -> (:*:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(GHC.:*:)
    (Options -> q (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GFields f, JsonVal p, JsonObj p q) =>
Options -> q (f x) (f x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonObj p q) =>
Options -> q (f x) (f x)
gfields Options
opts) (Options -> q (g x) (g x)
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GFields f, JsonVal p, JsonObj p q) =>
Options -> q (f x) (f x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonObj p q) =>
Options -> q (g x) (g x)
gfields Options
opts)
  gfield :: forall (p :: * -> * -> *) x.
JsonVal p =>
Maybe (p ((:*:) f g x) ((:*:) f g x))
gfield = Maybe (p ((:*:) f g x) ((:*:) f g x))
forall a. Maybe a
Nothing
  {-# INLINE gfields #-}
  {-# INLINE gfield #-}
instance GFields GHC.U1 where
  gfields :: forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonObj p q) =>
Options -> q (U1 x) (U1 x)
gfields Options
_ = (U1 x -> ()) -> (() -> U1 x) -> q () () -> q (U1 x) (U1 x)
forall a b c d. (a -> b) -> (c -> d) -> q b c -> q a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (() -> U1 x -> ()
forall a b. a -> b -> a
const ()) (U1 x -> () -> U1 x
forall a b. a -> b -> a
const U1 x
forall k (p :: k). U1 p
GHC.U1) q () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP
  gfield :: forall (p :: * -> * -> *) x. JsonVal p => Maybe (p (U1 x) (U1 x))
gfield = Maybe (p (U1 x) (U1 x))
forall a. Maybe a
Nothing

class GElements f where
  gelements :: (JsonVal p, JsonTup p q) => q (f x) (f x)
  -- | A single field's grammar, or else `Nothing` for other products.
  gelement :: Maybe (forall p. JsonVal p => p (f x) (f x))
instance Json a => GElements (GHC.S1 s (GHC.K1 i a)) where
  gelements :: forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonTup p q) =>
q (S1 s (K1 i a) x) (S1 s (K1 i a) x)
gelements = (K1 i a x -> M1 S s (K1 i a) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 (K1 i a x -> M1 S s (K1 i a) x)
-> (a -> K1 i a x) -> a -> M1 S s (K1 i a) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> K1 i a x
forall k i c (p :: k). c -> K1 i c p
GHC.K1) (a -> M1 S s (K1 i a) x) -> q a a -> q a (M1 S s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> q a b -> q a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a a -> q a a
forall a b. p a b -> q a b
forall (p :: * -> * -> *) (q :: * -> * -> *) a b.
JsonTup p q =>
p a b -> q a b
jsonElem p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json q a (M1 S s (K1 i a) x)
-> (M1 S s (K1 i a) x -> a)
-> q (M1 S s (K1 i a) x) (M1 S s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible b a =>
q b c -> q a b -> q a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# K1 i a x -> a
forall k i c (p :: k). K1 i c p -> c
GHC.unK1 (K1 i a x -> a)
-> (M1 S s (K1 i a) x -> K1 i a x) -> M1 S s (K1 i a) x -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. M1 S s (K1 i a) x -> K1 i a x
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1
  gelement :: forall x.
Maybe
  (forall (p :: * -> * -> *).
   JsonVal p =>
   p (S1 s (K1 i a) x) (S1 s (K1 i a) x))
gelement = (forall (p :: * -> * -> *).
 JsonVal p =>
 p (S1 s (K1 i a) x) (S1 s (K1 i a) x))
-> Maybe
     (forall (p :: * -> * -> *).
      JsonVal p =>
      p (S1 s (K1 i a) x) (S1 s (K1 i a) x))
forall a. a -> Maybe a
Just ((K1 i a x -> S1 s (K1 i a) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 (K1 i a x -> S1 s (K1 i a) x)
-> (a -> K1 i a x) -> a -> S1 s (K1 i a) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> K1 i a x
forall k i c (p :: k). c -> K1 i c p
GHC.K1) (a -> S1 s (K1 i a) x) -> p a a -> p a (S1 s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> p a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json p a (S1 s (K1 i a) x)
-> (S1 s (K1 i a) x -> a) -> p (S1 s (K1 i a) x) (S1 s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible b a =>
p b c -> q a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# K1 i a x -> a
forall k i c (p :: k). K1 i c p -> c
GHC.unK1 (K1 i a x -> a)
-> (S1 s (K1 i a) x -> K1 i a x) -> S1 s (K1 i a) x -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. S1 s (K1 i a) x -> K1 i a x
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1)
  {-# INLINE gelements #-}
  {-# INLINE gelement #-}
instance (GElements f, GElements g) => GElements (f GHC.:*: g) where
  gelements :: forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonTup p q) =>
q ((:*:) f g x) ((:*:) f g x)
gelements = ((:*:) f g x -> f x)
-> ((:*:) f g x -> g x)
-> (f x -> g x -> (:*:) f g x)
-> q (f x) (f x)
-> q (g x) (g x)
-> q ((:*:) f g x) ((:*:) f g x)
forall (p :: * -> * -> *) s a c b d t.
Monoidal p =>
(s -> a) -> (s -> c) -> (b -> d -> t) -> p a b -> p c d -> p s t
dimap2
    (\(f x
a GHC.:*: g x
_) -> f x
a) (\(f x
_ GHC.:*: g x
b) -> g x
b) f x -> g x -> (:*:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(GHC.:*:) q (f x) (f x)
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GElements f, JsonVal p, JsonTup p q) =>
q (f x) (f x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonTup p q) =>
q (f x) (f x)
gelements q (g x) (g x)
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GElements f, JsonVal p, JsonTup p q) =>
q (f x) (f x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonTup p q) =>
q (g x) (g x)
gelements
  gelement :: forall x.
Maybe
  (forall (p :: * -> * -> *).
   JsonVal p =>
   p ((:*:) f g x) ((:*:) f g x))
gelement = Maybe
  (forall (p :: * -> * -> *).
   JsonVal p =>
   p ((:*:) f g x) ((:*:) f g x))
forall a. Maybe a
Nothing
  {-# INLINE gelements #-}
  {-# INLINE gelement #-}
instance GElements GHC.U1 where
  gelements :: forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonTup p q) =>
q (U1 x) (U1 x)
gelements = (U1 x -> ()) -> (() -> U1 x) -> q () () -> q (U1 x) (U1 x)
forall a b c d. (a -> b) -> (c -> d) -> q b c -> q a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (() -> U1 x -> ()
forall a b. a -> b -> a
const ()) (U1 x -> () -> U1 x
forall a b. a -> b -> a
const U1 x
forall k (p :: k). U1 p
GHC.U1) q () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP
  gelement :: forall x.
Maybe (forall (p :: * -> * -> *). JsonVal p => p (U1 x) (U1 x))
gelement = Maybe (forall (p :: * -> * -> *). JsonVal p => p (U1 x) (U1 x))
forall a. Maybe a
Nothing

-- | The `GHC.Generic` tuple of a single constructor's positional fields.
gtuple
  :: (GHC.Generic a, GHC.Rep a ~ GHC.D1 d (GHC.C1 c f), GElements f, JsonVal p)
  => p a a
gtuple :: forall a (d :: Meta) (c :: Meta) (f :: * -> *) (p :: * -> * -> *).
(Generic a, Rep a ~ D1 d (C1 c f), GElements f, JsonVal p) =>
p a a
gtuple = (a -> f (ZonkAny 0))
-> (f (ZonkAny 0) -> a)
-> p (f (ZonkAny 0)) (f (ZonkAny 0))
-> p a a
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 (M1 C c f (ZonkAny 0) -> f (ZonkAny 0)
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1 (M1 C c f (ZonkAny 0) -> f (ZonkAny 0))
-> (a -> M1 C c f (ZonkAny 0)) -> a -> f (ZonkAny 0)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. M1 D d (C1 c f) (ZonkAny 0) -> M1 C c f (ZonkAny 0)
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1 (M1 D d (C1 c f) (ZonkAny 0) -> M1 C c f (ZonkAny 0))
-> (a -> M1 D d (C1 c f) (ZonkAny 0)) -> a -> M1 C c f (ZonkAny 0)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> M1 D d (C1 c f) (ZonkAny 0)
a -> Rep a (ZonkAny 0)
forall x. a -> Rep a x
forall a x. Generic a => a -> Rep a x
GHC.from) (Rep a (ZonkAny 0) -> a
forall a x. Generic a => Rep a x -> a
forall x. Rep a x -> a
GHC.to (Rep a (ZonkAny 0) -> a)
-> (f (ZonkAny 0) -> Rep a (ZonkAny 0)) -> f (ZonkAny 0) -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. M1 C c f (ZonkAny 0) -> M1 D d (C1 c f) (ZonkAny 0)
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 (M1 C c f (ZonkAny 0) -> M1 D d (C1 c f) (ZonkAny 0))
-> (f (ZonkAny 0) -> M1 C c f (ZonkAny 0))
-> f (ZonkAny 0)
-> M1 D d (C1 c f) (ZonkAny 0)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (ZonkAny 0) -> M1 C c f (ZonkAny 0)
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1)
  ((forall (q :: * -> * -> *).
 JsonTup p q =>
 q (f (ZonkAny 0)) (f (ZonkAny 0)))
-> p (f (ZonkAny 0)) (f (ZonkAny 0))
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple q (f (ZonkAny 0)) (f (ZonkAny 0))
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GElements f, JsonVal p, JsonTup p q) =>
q (f x) (f x)
forall (q :: * -> * -> *).
JsonTup p q =>
q (f (ZonkAny 0)) (f (ZonkAny 0))
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonTup p q) =>
q (f x) (f x)
gelements)
{-# INLINE gtuple #-}

class GContents f where
  gcontents :: JsonVal p => p (f x) (f x)
instance Json a => GContents (GHC.S1 s (GHC.K1 i a)) where
  gcontents :: forall (p :: * -> * -> *) x.
JsonVal p =>
p (S1 s (K1 i a) x) (S1 s (K1 i a) x)
gcontents = (K1 i a x -> M1 S s (K1 i a) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
GHC.M1 (K1 i a x -> M1 S s (K1 i a) x)
-> (a -> K1 i a x) -> a -> M1 S s (K1 i a) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> K1 i a x
forall k i c (p :: k). c -> K1 i c p
GHC.K1) (a -> M1 S s (K1 i a) x) -> p a a -> p a (M1 S s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> p a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a a
forall a (p :: * -> * -> *). (Json a, JsonVal p) => p a a
forall (p :: * -> * -> *). JsonVal p => p a a
json p a (M1 S s (K1 i a) x)
-> (M1 S s (K1 i a) x -> a)
-> p (M1 S s (K1 i a) x) (M1 S s (K1 i a) x)
forall a b c (q :: * -> * -> *).
Coercible b a =>
p b c -> q a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# K1 i a x -> a
forall k i c (p :: k). K1 i c p -> c
GHC.unK1 (K1 i a x -> a)
-> (M1 S s (K1 i a) x -> K1 i a x) -> M1 S s (K1 i a) x -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. M1 S s (K1 i a) x -> K1 i a x
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
GHC.unM1
  {-# INLINE gcontents #-}
-- | Two fields are a `jsonPair`, & others a `jsonTuple`.
instance (GElements f, GElements g) => GContents (f GHC.:*: g) where
  gcontents :: forall p x. JsonVal p => p ((f GHC.:*: g) x) ((f GHC.:*: g) x)
  gcontents :: forall (p :: * -> * -> *) x.
JsonVal p =>
p ((:*:) f g x) ((:*:) f g x)
gcontents = case forall (f :: * -> *) x.
GElements f =>
Maybe (forall (p :: * -> * -> *). JsonVal p => p (f x) (f x))
gelement @f @x of
    Just forall (p :: * -> * -> *). JsonVal p => p (f x) (f x)
a -> case forall (f :: * -> *) x.
GElements f =>
Maybe (forall (p :: * -> * -> *). JsonVal p => p (f x) (f x))
gelement @g @x of
      Just forall (p :: * -> * -> *). JsonVal p => p (g x) (g x)
b -> ((:*:) f g x -> (f x, g x))
-> ((f x, g x) -> (:*:) f g x)
-> p (f x, g x) (f x, g x)
-> p ((:*:) f g x) ((:*:) f g x)
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
        (\(f x
x GHC.:*: g x
y) -> (f x
x, g x
y)) ((f x -> g x -> (:*:) f g x) -> (f x, g x) -> (:*:) f g x
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry f x -> g x -> (:*:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(GHC.:*:)) (p (f x) (f x) -> p (g x) (g x) -> p (f x, g x) (f x, g x)
forall a b c d. p a b -> p c d -> p (a, c) (b, d)
forall (p :: * -> * -> *) a b c d.
JsonVal p =>
p a b -> p c d -> p (a, c) (b, d)
jsonPair p (f x) (f x)
forall (p :: * -> * -> *). JsonVal p => p (f x) (f x)
a p (g x) (g x)
forall (p :: * -> * -> *). JsonVal p => p (g x) (g x)
b)
      Maybe (forall (p :: * -> * -> *). JsonVal p => p (g x) (g x))
Nothing -> (forall (q :: * -> * -> *).
 JsonTup p q =>
 q ((:*:) f g x) ((:*:) f g x))
-> p ((:*:) f g x) ((:*:) f g x)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple q ((:*:) f g x) ((:*:) f g x)
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GElements f, JsonVal p, JsonTup p q) =>
q (f x) (f x)
forall (q :: * -> * -> *).
JsonTup p q =>
q ((:*:) f g x) ((:*:) f g x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonTup p q) =>
q ((:*:) f g x) ((:*:) f g x)
gelements
    Maybe (forall (p :: * -> * -> *). JsonVal p => p (f x) (f x))
Nothing -> (forall (q :: * -> * -> *).
 JsonTup p q =>
 q ((:*:) f g x) ((:*:) f g x))
-> p ((:*:) f g x) ((:*:) f g x)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple q ((:*:) f g x) ((:*:) f g x)
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GElements f, JsonVal p, JsonTup p q) =>
q (f x) (f x)
forall (q :: * -> * -> *).
JsonTup p q =>
q ((:*:) f g x) ((:*:) f g x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonTup p q) =>
q ((:*:) f g x) ((:*:) f g x)
gelements
  {-# INLINE gcontents #-}
instance GContents GHC.U1 where
  gcontents :: forall (p :: * -> * -> *) x. JsonVal p => p (U1 x) (U1 x)
gcontents = (forall (q :: * -> * -> *). JsonTup p q => q (U1 x) (U1 x))
-> p (U1 x) (U1 x)
forall a b.
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
forall (p :: * -> * -> *) a b.
JsonVal p =>
(forall (q :: * -> * -> *). JsonTup p q => q a b) -> p a b
jsonTuple q (U1 x) (U1 x)
forall (f :: * -> *) (p :: * -> * -> *) (q :: * -> * -> *) x.
(GElements f, JsonVal p, JsonTup p q) =>
q (f x) (f x)
forall (q :: * -> * -> *). JsonTup p q => q (U1 x) (U1 x)
forall (p :: * -> * -> *) (q :: * -> * -> *) x.
(JsonVal p, JsonTup p q) =>
q (U1 x) (U1 x)
gelements

class GNullary f where
  gnullary :: Maybe (f x)
instance GNullary GHC.U1 where
  gnullary :: forall x. Maybe (U1 x)
gnullary = U1 x -> Maybe (U1 x)
forall a. a -> Maybe a
Just U1 x
forall k (p :: k). U1 p
GHC.U1
instance GNullary (GHC.S1 s f) where
  gnullary :: forall x. Maybe (S1 s f x)
gnullary = Maybe (S1 s f x)
forall a. Maybe a
Nothing
  {-# INLINE gnullary #-}
instance GNullary (f GHC.:*: g) where
  gnullary :: forall x. Maybe ((:*:) f g x)
gnullary = Maybe ((:*:) f g x)
forall a. Maybe a
Nothing
  {-# INLINE gnullary #-}