{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Autodocodec.Codec where
import Control.Monad
import Control.Monad.State
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
import qualified Data.Aeson as JSON
import qualified Data.Aeson.Types as JSON
import Data.Coerce (Coercible)
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Hashable
import Data.List (intersperse)
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NE
import Data.Map (Map)
import Data.Scientific as Scientific
import Data.Set (Set)
import qualified Data.Set as S
import Data.Text (Text)
import qualified Data.Text as T
import Data.Validity
import Data.Validity.Scientific ()
import Data.Vector (Vector)
import qualified Data.Vector as V
import Data.Void
import Data.Word
import GHC.Generics (Generic)
import Numeric.Natural
#if MIN_VERSION_aeson(2,0,0)
import Data.Aeson.KeyMap (KeyMap)
import qualified Data.Aeson.KeyMap as KM
#endif
type role Codec _ representational representational
data Codec context input output where
NullCodec ::
(Coercible a (), Coercible b ()) =>
ValueCodec a b
BoolCodec ::
(Coercible a Bool, Coercible b Bool) =>
Maybe Text ->
ValueCodec a b
StringCodec ::
(Coercible a Text, Coercible b Text) =>
Maybe Text ->
ValueCodec a b
IntegerCodec ::
(Coercible a Integer, Coercible b Integer) =>
Maybe Text ->
Bounds Integer ->
ValueCodec a b
NumberCodec ::
(Coercible a Scientific, Coercible b Scientific) =>
Maybe Text ->
Bounds Scientific ->
ValueCodec a b
HashMapCodec ::
(Eq k, Hashable k, FromJSONKey k, ToJSONKey k, Coercible a (HashMap k v), Coercible b (HashMap k v)) =>
JSONCodec v ->
ValueCodec a b
MapCodec ::
(Ord k, FromJSONKey k, ToJSONKey k, Coercible a (Map k v), Coercible b (Map k v)) =>
JSONCodec v ->
ValueCodec a b
ValueCodec ::
(Coercible JSON.Value a, Coercible JSON.Value b) =>
ValueCodec a b
ArrayOfCodec ::
(Coercible a (Vector input), Coercible b (Vector output)) =>
Maybe Text ->
ValueCodec input output ->
ValueCodec a b
ObjectOfCodec ::
Maybe Text ->
ObjectCodec input output ->
ValueCodec input output
EqCodec ::
(Show value, Eq value, Coercible a value, Coercible b value) =>
value ->
JSONCodec value ->
ValueCodec a b
BimapCodec ::
(oldOutput -> Either String newOutput) ->
(newInput -> oldInput) ->
Codec context oldInput oldOutput ->
Codec context newInput newOutput
EitherCodec ::
(Coercible a (Either input1 input2), Coercible b (Either output1 output2)) =>
!Union ->
Codec context input1 output1 ->
Codec context input2 output2 ->
Codec context a b
DiscriminatedUnionCodec ::
Text ->
(input -> (Discriminator, ObjectCodec input ())) ->
HashMap Discriminator (Text, ObjectCodec Void output) ->
ObjectCodec input output
::
Text ->
ValueCodec input output ->
ValueCodec input output
ReferenceCodec ::
Text ->
~(ValueCodec input output) ->
ValueCodec input output
RequiredKeyCodec ::
Text ->
ValueCodec input output ->
Maybe Text ->
ObjectCodec input output
OptionalKeyCodec ::
(Coercible a (Maybe input), Coercible b (Maybe output)) =>
Text ->
ValueCodec input output ->
Maybe Text ->
ObjectCodec a b
OptionalKeyWithDefaultCodec ::
(Coercible b value) =>
Text ->
ValueCodec value value ->
value ->
Maybe Text ->
ObjectCodec value b
OptionalKeyWithOmittedDefaultCodec ::
(Eq value, Coercible a value, Coercible b value) =>
Text ->
ValueCodec value value ->
value ->
Maybe Text ->
ObjectCodec a b
PureCodec ::
output ->
ObjectCodec void output
ApCodec ::
ObjectCodec input (output -> newOutput) ->
ObjectCodec input output ->
ObjectCodec input newOutput
data Bounds a = Bounds
{
forall a. Bounds a -> Maybe a
boundsLower :: !(Maybe a),
forall a. Bounds a -> Maybe a
boundsUpper :: !(Maybe a)
}
deriving (Int -> Bounds a -> ShowS
[Bounds a] -> ShowS
Bounds a -> String
(Int -> Bounds a -> ShowS)
-> (Bounds a -> String) -> ([Bounds a] -> ShowS) -> Show (Bounds a)
forall a. Show a => Int -> Bounds a -> ShowS
forall a. Show a => [Bounds a] -> ShowS
forall a. Show a => Bounds a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Bounds a -> ShowS
showsPrec :: Int -> Bounds a -> ShowS
$cshow :: forall a. Show a => Bounds a -> String
show :: Bounds a -> String
$cshowList :: forall a. Show a => [Bounds a] -> ShowS
showList :: [Bounds a] -> ShowS
Show, Bounds a -> Bounds a -> Bool
(Bounds a -> Bounds a -> Bool)
-> (Bounds a -> Bounds a -> Bool) -> Eq (Bounds a)
forall a. Eq a => Bounds a -> Bounds a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Bounds a -> Bounds a -> Bool
== :: Bounds a -> Bounds a -> Bool
$c/= :: forall a. Eq a => Bounds a -> Bounds a -> Bool
/= :: Bounds a -> Bounds a -> Bool
Eq, Eq (Bounds a)
Eq (Bounds a) =>
(Bounds a -> Bounds a -> Ordering)
-> (Bounds a -> Bounds a -> Bool)
-> (Bounds a -> Bounds a -> Bool)
-> (Bounds a -> Bounds a -> Bool)
-> (Bounds a -> Bounds a -> Bool)
-> (Bounds a -> Bounds a -> Bounds a)
-> (Bounds a -> Bounds a -> Bounds a)
-> Ord (Bounds a)
Bounds a -> Bounds a -> Bool
Bounds a -> Bounds a -> Ordering
Bounds a -> Bounds a -> Bounds 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 (Bounds a)
forall a. Ord a => Bounds a -> Bounds a -> Bool
forall a. Ord a => Bounds a -> Bounds a -> Ordering
forall a. Ord a => Bounds a -> Bounds a -> Bounds a
$ccompare :: forall a. Ord a => Bounds a -> Bounds a -> Ordering
compare :: Bounds a -> Bounds a -> Ordering
$c< :: forall a. Ord a => Bounds a -> Bounds a -> Bool
< :: Bounds a -> Bounds a -> Bool
$c<= :: forall a. Ord a => Bounds a -> Bounds a -> Bool
<= :: Bounds a -> Bounds a -> Bool
$c> :: forall a. Ord a => Bounds a -> Bounds a -> Bool
> :: Bounds a -> Bounds a -> Bool
$c>= :: forall a. Ord a => Bounds a -> Bounds a -> Bool
>= :: Bounds a -> Bounds a -> Bool
$cmax :: forall a. Ord a => Bounds a -> Bounds a -> Bounds a
max :: Bounds a -> Bounds a -> Bounds a
$cmin :: forall a. Ord a => Bounds a -> Bounds a -> Bounds a
min :: Bounds a -> Bounds a -> Bounds a
Ord, (forall x. Bounds a -> Rep (Bounds a) x)
-> (forall x. Rep (Bounds a) x -> Bounds a) -> Generic (Bounds a)
forall x. Rep (Bounds a) x -> Bounds a
forall x. Bounds a -> Rep (Bounds a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Bounds a) x -> Bounds a
forall a x. Bounds a -> Rep (Bounds a) x
$cfrom :: forall a x. Bounds a -> Rep (Bounds a) x
from :: forall x. Bounds a -> Rep (Bounds a) x
$cto :: forall a x. Rep (Bounds a) x -> Bounds a
to :: forall x. Rep (Bounds a) x -> Bounds a
Generic, (forall a b. (a -> b) -> Bounds a -> Bounds b)
-> (forall a b. a -> Bounds b -> Bounds a) -> Functor Bounds
forall a b. a -> Bounds b -> Bounds a
forall a b. (a -> b) -> Bounds a -> Bounds b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Bounds a -> Bounds b
fmap :: forall a b. (a -> b) -> Bounds a -> Bounds b
$c<$ :: forall a b. a -> Bounds b -> Bounds a
<$ :: forall a b. a -> Bounds b -> Bounds a
Functor)
instance (Validity a) => Validity (Bounds a)
emptyBounds :: Bounds a
emptyBounds :: forall a. Bounds a
emptyBounds = Maybe a -> Maybe a -> Bounds a
forall a. Maybe a -> Maybe a -> Bounds a
Bounds Maybe a
forall a. Maybe a
Nothing Maybe a
forall a. Maybe a
Nothing
boundedBounds :: (Bounded a) => Bounds a
boundedBounds :: forall a. Bounded a => Bounds a
boundedBounds =
Bounds
{ boundsLower :: Maybe a
boundsLower = a -> Maybe a
forall a. a -> Maybe a
Just a
forall a. Bounded a => a
minBound,
boundsUpper :: Maybe a
boundsUpper = a -> Maybe a
forall a. a -> Maybe a
Just a
forall a. Bounded a => a
maxBound
}
checkBounds :: (Show a, Ord a) => Bounds a -> a -> Either String a
checkBounds :: forall a. (Show a, Ord a) => Bounds a -> a -> Either String a
checkBounds Bounds {Maybe a
boundsLower :: forall a. Bounds a -> Maybe a
boundsUpper :: forall a. Bounds a -> Maybe a
boundsLower :: Maybe a
boundsUpper :: Maybe a
..} a
s =
case Maybe a
boundsLower of
Just a
lo | a
s a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
lo -> String -> Either String a
forall a b. a -> Either a b
Left (String -> Either String a) -> String -> Either String a
forall a b. (a -> b) -> a -> b
$ [String] -> String
unwords [String
"Number", a -> String
forall a. Show a => a -> String
show a
s, String
"is smaller than the lower bound", a -> String
forall a. Show a => a -> String
show a
lo]
Maybe a
_ -> case Maybe a
boundsUpper of
Just a
hi | a
s a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
hi -> String -> Either String a
forall a b. a -> Either a b
Left (String -> Either String a) -> String -> Either String a
forall a b. (a -> b) -> a -> b
$ [String] -> String
unwords [String
"Number", a -> String
forall a. Show a => a -> String
show a
s, String
"is bigger than the upper bound", a -> String
forall a. Show a => a -> String
show a
hi]
Maybe a
_ -> a -> Either String a
forall a b. b -> Either a b
Right a
s
data IntegerBoundsSymbolic
= BitUInt !Word8
| BitSInt !Word8
| OtherIntegerBounds !(Maybe IntegerSymbolic) !(Maybe IntegerSymbolic)
guessIntegerBoundsSymbolic :: Bounds Integer -> IntegerBoundsSymbolic
guessIntegerBoundsSymbolic :: Bounds Integer -> IntegerBoundsSymbolic
guessIntegerBoundsSymbolic Bounds {Maybe Integer
boundsLower :: forall a. Bounds a -> Maybe a
boundsUpper :: forall a. Bounds a -> Maybe a
boundsLower :: Maybe Integer
boundsUpper :: Maybe Integer
..} =
case (Integer -> IntegerSymbolic
guessIntegerSymbolic (Integer -> IntegerSymbolic)
-> Maybe Integer -> Maybe IntegerSymbolic
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Integer
boundsLower, Integer -> IntegerSymbolic
guessIntegerSymbolic (Integer -> IntegerSymbolic)
-> Maybe Integer -> Maybe IntegerSymbolic
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Integer
boundsUpper) of
(Just IntegerSymbolic
Zero, Just (PowerOf2MinusOne Word8
w)) -> Word8 -> IntegerBoundsSymbolic
BitUInt Word8
w
(Just (MinusPowerOf2 Word8
w1), Just (PowerOf2MinusOne Word8
w2)) | Word8
w1 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
w2 -> Word8 -> IntegerBoundsSymbolic
BitSInt (Word8 -> Word8
forall a. Enum a => a -> a
succ Word8
w1)
(Maybe IntegerSymbolic
l, Maybe IntegerSymbolic
u) -> Maybe IntegerSymbolic
-> Maybe IntegerSymbolic -> IntegerBoundsSymbolic
OtherIntegerBounds Maybe IntegerSymbolic
l Maybe IntegerSymbolic
u
data IntegerSymbolic
= Zero
| PowerOf2 !Word8
| PowerOf2MinusOne !Word8
| MinusPowerOf2 !Word8
| MinusPowerOf2MinusOne !Word8
| OtherInteger !Integer
guessIntegerSymbolic :: Integer -> IntegerSymbolic
guessIntegerSymbolic :: Integer -> IntegerSymbolic
guessIntegerSymbolic Integer
i =
let log2Rounded :: Word8
log2Rounded :: Word8
log2Rounded = Double -> Word8
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Double -> Double -> Double
forall a. Floating a => a -> a -> a
logBase Double
2 (Integer -> Double
forall a. Num a => Integer -> a
fromInteger (Integer -> Integer
forall a. Num a => a -> a
abs Integer
i)) :: Double)
guess :: Integer
guess :: Integer
guess = Integer
2 Integer -> Word8 -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Word8
log2Rounded
in if
| Integer
i Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
0 -> IntegerSymbolic
Zero
| Integer
guess Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
i -> Word8 -> IntegerSymbolic
PowerOf2 Word8
log2Rounded
| (Integer
guess Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
1) Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
i -> Word8 -> IntegerSymbolic
PowerOf2MinusOne Word8
log2Rounded
| -Integer
guess Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
i -> Word8 -> IntegerSymbolic
MinusPowerOf2 Word8
log2Rounded
| -(Integer
guess Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
1) Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
i -> Word8 -> IntegerSymbolic
MinusPowerOf2MinusOne Word8
log2Rounded
| Bool
otherwise -> Integer -> IntegerSymbolic
OtherInteger Integer
i
data Union
=
PossiblyJointUnion
|
DisjointUnion
deriving (Int -> Union -> ShowS
[Union] -> ShowS
Union -> String
(Int -> Union -> ShowS)
-> (Union -> String) -> ([Union] -> ShowS) -> Show Union
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Union -> ShowS
showsPrec :: Int -> Union -> ShowS
$cshow :: Union -> String
show :: Union -> String
$cshowList :: [Union] -> ShowS
showList :: [Union] -> ShowS
Show, Union -> Union -> Bool
(Union -> Union -> Bool) -> (Union -> Union -> Bool) -> Eq Union
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Union -> Union -> Bool
== :: Union -> Union -> Bool
$c/= :: Union -> Union -> Bool
/= :: Union -> Union -> Bool
Eq, (forall x. Union -> Rep Union x)
-> (forall x. Rep Union x -> Union) -> Generic Union
forall x. Rep Union x -> Union
forall x. Union -> Rep Union x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Union -> Rep Union x
from :: forall x. Union -> Rep Union x
$cto :: forall x. Rep Union x -> Union
to :: forall x. Rep Union x -> Union
Generic)
instance Validity Union
type ValueCodec = Codec JSON.Value
type ObjectCodec = Codec JSON.Object
type JSONCodec a = ValueCodec a a
type JSONObjectCodec a = ObjectCodec a a
showCodecABit :: Codec context input output -> String
showCodecABit :: forall context input output. Codec context input output -> String
showCodecABit = (ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String
"") (ShowS -> String)
-> (Codec context input output -> ShowS)
-> Codec context input output
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (State (Set Text) ShowS -> Set Text -> ShowS
forall s a. State s a -> s -> a
`evalState` Set Text
forall a. Set a
S.empty) (State (Set Text) ShowS -> ShowS)
-> (Codec context input output -> State (Set Text) ShowS)
-> Codec context input output
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Codec context input output -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
0
where
go :: Int -> Codec context input output -> State (Set Text) ShowS
go :: forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
d = \case
Codec context input output
NullCodec -> ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"NullCodec"
BoolCodec Maybe Text
mName -> ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"BoolCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName
StringCodec Maybe Text
mName -> ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"StringCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName
IntegerCodec Maybe Text
mName Bounds Integer
mbs -> ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"IntegerCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bounds Integer -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Bounds Integer
mbs
NumberCodec Maybe Text
mName Bounds Scientific
mbs -> ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"NumberCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bounds Scientific -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Bounds Scientific
mbs
ArrayOfCodec Maybe Text
mName ValueCodec input output
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ArrayOfCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ValueCodec input output -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ValueCodec input output
c
ObjectOfCodec Maybe Text
mName ObjectCodec input output
oc -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ObjectOfCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ObjectCodec input output -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ObjectCodec input output
oc
Codec context input output
ValueCodec -> ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ValueCodec"
MapCodec JSONCodec v
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"MapCodec" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> JSONCodec v -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 JSONCodec v
c
HashMapCodec JSONCodec v
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"HashMapCodec" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> JSONCodec v -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 JSONCodec v
c
EqCodec value
value JSONCodec value
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"EqCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> value -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 value
value ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> JSONCodec value -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 JSONCodec value
c
BimapCodec oldOutput -> Either String output
_ input -> oldInput
_ Codec context oldInput oldOutput
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"BimapCodec _ _ " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Codec context oldInput oldOutput -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 Codec context oldInput oldOutput
c
EitherCodec Union
u Codec context input1 output1
c1 Codec context input2 output2
c2 -> (\ShowS
s1 ShowS
s2 -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"EitherCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Union -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Union
u ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s1 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s2) (ShowS -> ShowS -> ShowS)
-> State (Set Text) ShowS
-> StateT (Set Text) Identity (ShowS -> ShowS)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Codec context input1 output1 -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 Codec context input1 output1
c1 StateT (Set Text) Identity (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall a b.
StateT (Set Text) Identity (a -> b)
-> StateT (Set Text) Identity a -> StateT (Set Text) Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Codec context input2 output2 -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 Codec context input2 output2
c2
DiscriminatedUnionCodec Text
propertyName input -> (Text, ObjectCodec input ())
_ HashMap Text (Text, ObjectCodec Void output)
mapping -> do
[ShowS]
cs <- ((Text, (Text, ObjectCodec Void output)) -> State (Set Text) ShowS)
-> [(Text, (Text, ObjectCodec Void output))]
-> StateT (Set Text) Identity [ShowS]
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 (\(Text
n, (Text
_, ObjectCodec Void output
c)) -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen Bool
True (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ Text -> ShowS
forall a. Show a => a -> ShowS
shows Text
n ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
", " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ObjectCodec Void output -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ObjectCodec Void output
c) ([(Text, (Text, ObjectCodec Void output))]
-> StateT (Set Text) Identity [ShowS])
-> [(Text, (Text, ObjectCodec Void output))]
-> StateT (Set Text) Identity [ShowS]
forall a b. (a -> b) -> a -> b
$ HashMap Text (Text, ObjectCodec Void output)
-> [(Text, (Text, ObjectCodec Void output))]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList HashMap Text (Text, ObjectCodec Void output)
mapping
let csList :: ShowS
csList = String -> ShowS
showString String
"[" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ShowS -> ShowS -> ShowS) -> ShowS -> [ShowS] -> ShowS
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ShowS
forall a. a -> a
id (ShowS -> [ShowS] -> [ShowS]
forall a. a -> [a] -> [a]
intersperse (String -> ShowS
showString String
", ") [ShowS]
cs) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"]"
ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"DiscriminatedUnionCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
propertyName ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" _ " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
csList
CommentCodec Text
comment ValueCodec input output
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"CommentCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
comment ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ValueCodec input output -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ValueCodec input output
c
ReferenceCodec Text
name ValueCodec input output
c -> do
Bool
alreadySeen <- (Set Text -> Bool) -> StateT (Set Text) Identity Bool
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
S.member Text
name)
if Bool
alreadySeen
then ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ReferenceCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
name
else do
(Set Text -> Set Text) -> StateT (Set Text) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (Text -> Set Text -> Set Text
forall a. Ord a => a -> Set a -> Set a
S.insert Text
name)
ShowS
s <- Int -> ValueCodec input output -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ValueCodec input output
c
ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ReferenceCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
name ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s
RequiredKeyCodec Text
k ValueCodec input output
c Maybe Text
mdoc -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"RequiredKeyCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
k ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mdoc ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ValueCodec input output -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ValueCodec input output
c
OptionalKeyCodec Text
k ValueCodec input output
c Maybe Text
mdoc -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"OptionalKeyCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
k ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mdoc ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ValueCodec input output -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ValueCodec input output
c
OptionalKeyWithDefaultCodec Text
k ValueCodec input input
c input
_ Maybe Text
mdoc -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"OptionalKeyWithDefaultCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
k ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" _ " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mdoc) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ValueCodec input input -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ValueCodec input input
c
OptionalKeyWithOmittedDefaultCodec Text
k ValueCodec value value
c value
_ Maybe Text
mdoc -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"OptionalKeyWithOmittedDefaultCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
k ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" _ " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Text -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mdoc) (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ValueCodec value value -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ValueCodec value value
c
PureCodec output
_ -> ShowS -> State (Set Text) ShowS
forall a. a -> StateT (Set Text) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShowS -> State (Set Text) ShowS)
-> ShowS -> State (Set Text) ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"PureCodec _"
ApCodec ObjectCodec input (output -> output)
oc1 ObjectCodec input output
oc2 -> (\ShowS
s1 ShowS
s2 -> Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ApCodec " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s1 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s2) (ShowS -> ShowS -> ShowS)
-> State (Set Text) ShowS
-> StateT (Set Text) Identity (ShowS -> ShowS)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> ObjectCodec input (output -> output) -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ObjectCodec input (output -> output)
oc1 StateT (Set Text) Identity (ShowS -> ShowS)
-> State (Set Text) ShowS -> State (Set Text) ShowS
forall a b.
StateT (Set Text) Identity (a -> b)
-> StateT (Set Text) Identity a -> StateT (Set Text) Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> ObjectCodec input output -> State (Set Text) ShowS
forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ObjectCodec input output
oc2
rmapCodec ::
(oldOutput -> newOutput) ->
Codec context input oldOutput ->
Codec context input newOutput
rmapCodec :: forall oldOutput newOutput context input.
(oldOutput -> newOutput)
-> Codec context input oldOutput -> Codec context input newOutput
rmapCodec oldOutput -> newOutput
f = (oldOutput -> newOutput)
-> (input -> input)
-> Codec context input oldOutput
-> Codec context input newOutput
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec oldOutput -> newOutput
f input -> input
forall a. a -> a
id
instance Functor (Codec context input) where
fmap :: forall a b.
(a -> b) -> Codec context input a -> Codec context input b
fmap = (a -> b) -> Codec context input a -> Codec context input b
forall oldOutput newOutput context input.
(oldOutput -> newOutput)
-> Codec context input oldOutput -> Codec context input newOutput
rmapCodec
lmapCodec ::
(newInput -> oldInput) ->
Codec context oldInput output ->
Codec context newInput output
lmapCodec :: forall newInput oldInput context output.
(newInput -> oldInput)
-> Codec context oldInput output -> Codec context newInput output
lmapCodec newInput -> oldInput
g = (output -> output)
-> (newInput -> oldInput)
-> Codec context oldInput output
-> Codec context newInput output
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec output -> output
forall a. a -> a
id newInput -> oldInput
g
(.=) :: ObjectCodec oldInput output -> (newInput -> oldInput) -> ObjectCodec newInput output
.= :: forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
(.=) = ((newInput -> oldInput)
-> ObjectCodec oldInput output -> ObjectCodec newInput output)
-> ObjectCodec oldInput output
-> (newInput -> oldInput)
-> ObjectCodec newInput output
forall a b c. (a -> b -> c) -> b -> a -> c
flip (newInput -> oldInput)
-> ObjectCodec oldInput output -> ObjectCodec newInput output
forall newInput oldInput context output.
(newInput -> oldInput)
-> Codec context oldInput output -> Codec context newInput output
lmapCodec
dimapCodec ::
(oldOutput -> newOutput) ->
(newInput -> oldInput) ->
Codec context oldInput oldOutput ->
Codec context newInput newOutput
dimapCodec :: forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec oldOutput -> newOutput
f newInput -> oldInput
g = (oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec (newOutput -> Either String newOutput
forall a b. b -> Either a b
Right (newOutput -> Either String newOutput)
-> (oldOutput -> newOutput) -> oldOutput -> Either String newOutput
forall b c a. (b -> c) -> (a -> b) -> a -> c
. oldOutput -> newOutput
f) newInput -> oldInput
g
pureCodec :: output -> ObjectCodec input output
pureCodec :: forall output input. output -> ObjectCodec input output
pureCodec = output -> ObjectCodec input output
forall output input. output -> ObjectCodec input output
PureCodec
apCodec :: ObjectCodec input (output -> newOutput) -> ObjectCodec input output -> ObjectCodec input newOutput
apCodec :: forall input output newOutput.
ObjectCodec input (output -> newOutput)
-> ObjectCodec input output -> ObjectCodec input newOutput
apCodec = ObjectCodec input (output -> newOutput)
-> ObjectCodec input output -> ObjectCodec input newOutput
forall input output newOutput.
ObjectCodec input (output -> newOutput)
-> ObjectCodec input output -> ObjectCodec input newOutput
ApCodec
instance Applicative (ObjectCodec input) where
pure :: forall a. a -> ObjectCodec input a
pure = a -> ObjectCodec input a
forall output input. output -> ObjectCodec input output
pureCodec
<*> :: forall a b.
ObjectCodec input (a -> b)
-> ObjectCodec input a -> ObjectCodec input b
(<*>) = ObjectCodec input (a -> b)
-> ObjectCodec input a -> ObjectCodec input b
forall input output newOutput.
ObjectCodec input (output -> newOutput)
-> ObjectCodec input output -> ObjectCodec input newOutput
apCodec
maybeCodec :: ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec :: forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec =
(Either () output -> Maybe output)
-> (Maybe input -> Either () input)
-> Codec Value (Either () input) (Either () output)
-> Codec Value (Maybe input) (Maybe output)
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Either () output -> Maybe output
forall {a}. Either () a -> Maybe a
f Maybe input -> Either () input
forall {b}. Maybe b -> Either () b
g
(Codec Value (Either () input) (Either () output)
-> Codec Value (Maybe input) (Maybe output))
-> (ValueCodec input output
-> Codec Value (Either () input) (Either () output))
-> ValueCodec input output
-> Codec Value (Maybe input) (Maybe output)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Codec Value () ()
-> ValueCodec input output
-> Codec Value (Either () input) (Either () output)
forall context input1 output1 input2 output2.
Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
possiblyJointEitherCodec Codec Value () ()
nullCodec
where
f :: Either () a -> Maybe a
f = \case
Left () -> Maybe a
forall a. Maybe a
Nothing
Right a
r -> a -> Maybe a
forall a. a -> Maybe a
Just a
r
g :: Maybe b -> Either () b
g = \case
Maybe b
Nothing -> () -> Either () b
forall a b. a -> Either a b
Left ()
Just b
r -> b -> Either () b
forall a b. b -> Either a b
Right b
r
eitherCodec ::
Codec context input1 output1 ->
Codec context input2 output2 ->
Codec context (Either input1 input2) (Either output1 output2)
eitherCodec :: forall context input1 output1 input2 output2.
Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
eitherCodec = Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
forall context input1 output1 input2 output2.
Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
possiblyJointEitherCodec
disjointEitherCodec ::
Codec context input1 output1 ->
Codec context input2 output2 ->
Codec context (Either input1 input2) (Either output1 output2)
disjointEitherCodec :: forall context input1 output1 input2 output2.
Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
disjointEitherCodec = Union
-> Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
forall a value v b output1 output2 context.
(Coercible a (Either value v),
Coercible b (Either output1 output2)) =>
Union
-> Codec context value output1
-> Codec context v output2
-> Codec context a b
EitherCodec Union
DisjointUnion
possiblyJointEitherCodec ::
Codec context input1 output1 ->
Codec context input2 output2 ->
Codec context (Either input1 input2) (Either output1 output2)
possiblyJointEitherCodec :: forall context input1 output1 input2 output2.
Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
possiblyJointEitherCodec = Union
-> Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
forall a value v b output1 output2 context.
(Coercible a (Either value v),
Coercible b (Either output1 output2)) =>
Union
-> Codec context value output1
-> Codec context v output2
-> Codec context a b
EitherCodec Union
PossiblyJointUnion
type Discriminator = Text
mapToEncoder :: b -> Codec context b any -> Codec context a ()
mapToEncoder :: forall b context any a.
b -> Codec context b any -> Codec context a ()
mapToEncoder b
b = (any -> ())
-> (a -> b) -> Codec context b any -> Codec context a ()
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec (() -> any -> ()
forall a b. a -> b -> a
const ()) (b -> a -> b
forall a b. a -> b -> a
const b
b)
mapToDecoder :: (b -> a) -> Codec context any b -> Codec context Void a
mapToDecoder :: forall b a context any.
(b -> a) -> Codec context any b -> Codec context Void a
mapToDecoder b -> a
f = (b -> a)
-> (Void -> any) -> Codec context any b -> Codec context Void a
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec b -> a
f Void -> any
forall a. Void -> a
absurd
discriminatedUnionCodec ::
Text ->
(input -> (Discriminator, ObjectCodec input ())) ->
HashMap Discriminator (Text, ObjectCodec Void output) ->
ObjectCodec input output
discriminatedUnionCodec :: forall input output.
Text
-> (input -> (Text, ObjectCodec input ()))
-> HashMap Text (Text, ObjectCodec Void output)
-> ObjectCodec input output
discriminatedUnionCodec = Text
-> (input -> (Text, ObjectCodec input ()))
-> HashMap Text (Text, ObjectCodec Void output)
-> ObjectCodec input output
forall input output.
Text
-> (input -> (Text, ObjectCodec input ()))
-> HashMap Text (Text, ObjectCodec Void output)
-> ObjectCodec input output
DiscriminatedUnionCodec
bimapCodec ::
(oldOutput -> Either String newOutput) ->
(newInput -> oldInput) ->
Codec context oldInput oldOutput ->
Codec context newInput newOutput
bimapCodec :: forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec oldOutput -> Either String newOutput
f newInput -> oldInput
g =
\case
BimapCodec oldOutput -> Either String oldOutput
f' oldInput -> oldInput
g' Codec context oldInput oldOutput
c -> (oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
BimapCodec (oldOutput -> Either String oldOutput
f' (oldOutput -> Either String oldOutput)
-> (oldOutput -> Either String newOutput)
-> oldOutput
-> Either String newOutput
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> oldOutput -> Either String newOutput
f) (oldInput -> oldInput
g' (oldInput -> oldInput)
-> (newInput -> oldInput) -> newInput -> oldInput
forall b c a. (b -> c) -> (a -> b) -> a -> c
. newInput -> oldInput
g) Codec context oldInput oldOutput
c
Codec context oldInput oldOutput
c -> (oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
BimapCodec oldOutput -> Either String newOutput
f newInput -> oldInput
g Codec context oldInput oldOutput
c
vectorCodec :: ValueCodec input output -> ValueCodec (Vector input) (Vector output)
vectorCodec :: forall input output.
ValueCodec input output
-> ValueCodec (Vector input) (Vector output)
vectorCodec = Maybe Text
-> ValueCodec input output
-> ValueCodec (Vector input) (Vector output)
forall a value b v.
(Coercible a (Vector value), Coercible b (Vector v)) =>
Maybe Text -> ValueCodec value v -> ValueCodec a b
ArrayOfCodec Maybe Text
forall a. Maybe a
Nothing
listCodec :: ValueCodec input output -> ValueCodec [input] [output]
listCodec :: forall input output.
ValueCodec input output -> ValueCodec [input] [output]
listCodec = (Vector output -> [output])
-> ([input] -> Vector input)
-> Codec Value (Vector input) (Vector output)
-> Codec Value [input] [output]
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Vector output -> [output]
forall a. Vector a -> [a]
V.toList [input] -> Vector input
forall a. [a] -> Vector a
V.fromList (Codec Value (Vector input) (Vector output)
-> Codec Value [input] [output])
-> (ValueCodec input output
-> Codec Value (Vector input) (Vector output))
-> ValueCodec input output
-> Codec Value [input] [output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueCodec input output
-> Codec Value (Vector input) (Vector output)
forall input output.
ValueCodec input output
-> ValueCodec (Vector input) (Vector output)
vectorCodec
optionalKeyCodec :: Text -> ValueCodec input output -> Maybe Text -> ObjectCodec (Maybe input) (Maybe output)
optionalKeyCodec :: forall input output.
Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec (Maybe input) (Maybe output)
optionalKeyCodec = Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec (Maybe input) (Maybe output)
forall a value b v.
(Coercible a (Maybe value), Coercible b (Maybe v)) =>
Text -> ValueCodec value v -> Maybe Text -> ObjectCodec a b
OptionalKeyCodec
optionalKeyWithDefaultCodec ::
Text ->
ValueCodec value value ->
value ->
Maybe Text ->
ObjectCodec value value
optionalKeyWithDefaultCodec :: forall value.
Text
-> ValueCodec value value
-> value
-> Maybe Text
-> ObjectCodec value value
optionalKeyWithDefaultCodec = Text
-> ValueCodec value value
-> value
-> Maybe Text
-> ObjectCodec value value
forall b value.
Coercible b value =>
Text
-> ValueCodec value value
-> value
-> Maybe Text
-> ObjectCodec value b
OptionalKeyWithDefaultCodec
nonEmptyCodec :: ValueCodec input output -> ValueCodec (NonEmpty input) (NonEmpty output)
nonEmptyCodec :: forall input output.
ValueCodec input output
-> ValueCodec (NonEmpty input) (NonEmpty output)
nonEmptyCodec = ([output] -> Either String (NonEmpty output))
-> (NonEmpty input -> [input])
-> Codec Value [input] [output]
-> Codec Value (NonEmpty input) (NonEmpty output)
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec [output] -> Either String (NonEmpty output)
forall {a}. [a] -> Either String (NonEmpty a)
parseNonEmptyList NonEmpty input -> [input]
forall a. NonEmpty a -> [a]
NE.toList (Codec Value [input] [output]
-> Codec Value (NonEmpty input) (NonEmpty output))
-> (ValueCodec input output -> Codec Value [input] [output])
-> ValueCodec input output
-> Codec Value (NonEmpty input) (NonEmpty output)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueCodec input output -> Codec Value [input] [output]
forall input output.
ValueCodec input output -> ValueCodec [input] [output]
listCodec
where
parseNonEmptyList :: [a] -> Either String (NonEmpty a)
parseNonEmptyList [a]
l = case [a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [a]
l of
Maybe (NonEmpty a)
Nothing -> String -> Either String (NonEmpty a)
forall a b. a -> Either a b
Left String
"Expected a nonempty list, but got an empty list."
Just NonEmpty a
ne -> NonEmpty a -> Either String (NonEmpty a)
forall a b. b -> Either a b
Right NonEmpty a
ne
singleOrListCodec :: ValueCodec input output -> ValueCodec [input] [output]
singleOrListCodec :: forall input output.
ValueCodec input output -> ValueCodec [input] [output]
singleOrListCodec ValueCodec input output
c = (Either output [output] -> [output])
-> ([input] -> Either input [input])
-> Codec Value (Either input [input]) (Either output [output])
-> Codec Value [input] [output]
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Either output [output] -> [output]
forall {a}. Either a [a] -> [a]
f [input] -> Either input [input]
forall {a}. [a] -> Either a [a]
g (Codec Value (Either input [input]) (Either output [output])
-> Codec Value [input] [output])
-> Codec Value (Either input [input]) (Either output [output])
-> Codec Value [input] [output]
forall a b. (a -> b) -> a -> b
$ ValueCodec input output
-> Codec Value [input] [output]
-> Codec Value (Either input [input]) (Either output [output])
forall context input1 output1 input2 output2.
Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
eitherCodec ValueCodec input output
c (Codec Value [input] [output]
-> Codec Value (Either input [input]) (Either output [output]))
-> Codec Value [input] [output]
-> Codec Value (Either input [input]) (Either output [output])
forall a b. (a -> b) -> a -> b
$ ValueCodec input output -> Codec Value [input] [output]
forall input output.
ValueCodec input output -> ValueCodec [input] [output]
listCodec ValueCodec input output
c
where
f :: Either a [a] -> [a]
f = \case
Left a
v -> [a
v]
Right [a]
vs -> [a]
vs
g :: [a] -> Either a [a]
g = \case
[a
v] -> a -> Either a [a]
forall a b. a -> Either a b
Left a
v
[a]
vs -> [a] -> Either a [a]
forall a b. b -> Either a b
Right [a]
vs
singleOrNonEmptyCodec :: ValueCodec input output -> ValueCodec (NonEmpty input) (NonEmpty output)
singleOrNonEmptyCodec :: forall input output.
ValueCodec input output
-> ValueCodec (NonEmpty input) (NonEmpty output)
singleOrNonEmptyCodec ValueCodec input output
c = (Either output (NonEmpty output) -> NonEmpty output)
-> (NonEmpty input -> Either input (NonEmpty input))
-> Codec
Value
(Either input (NonEmpty input))
(Either output (NonEmpty output))
-> Codec Value (NonEmpty input) (NonEmpty output)
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Either output (NonEmpty output) -> NonEmpty output
forall {a}. Either a (NonEmpty a) -> NonEmpty a
f NonEmpty input -> Either input (NonEmpty input)
forall {a}. NonEmpty a -> Either a (NonEmpty a)
g (Codec
Value
(Either input (NonEmpty input))
(Either output (NonEmpty output))
-> Codec Value (NonEmpty input) (NonEmpty output))
-> Codec
Value
(Either input (NonEmpty input))
(Either output (NonEmpty output))
-> Codec Value (NonEmpty input) (NonEmpty output)
forall a b. (a -> b) -> a -> b
$ ValueCodec input output
-> Codec Value (NonEmpty input) (NonEmpty output)
-> Codec
Value
(Either input (NonEmpty input))
(Either output (NonEmpty output))
forall context input1 output1 input2 output2.
Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
eitherCodec ValueCodec input output
c (Codec Value (NonEmpty input) (NonEmpty output)
-> Codec
Value
(Either input (NonEmpty input))
(Either output (NonEmpty output)))
-> Codec Value (NonEmpty input) (NonEmpty output)
-> Codec
Value
(Either input (NonEmpty input))
(Either output (NonEmpty output))
forall a b. (a -> b) -> a -> b
$ ValueCodec input output
-> Codec Value (NonEmpty input) (NonEmpty output)
forall input output.
ValueCodec input output
-> ValueCodec (NonEmpty input) (NonEmpty output)
nonEmptyCodec ValueCodec input output
c
where
f :: Either a (NonEmpty a) -> NonEmpty a
f = \case
Left a
v -> a
v a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| []
Right NonEmpty a
vs -> NonEmpty a
vs
g :: NonEmpty a -> Either a (NonEmpty a)
g = \case
a
v :| [] -> a -> Either a (NonEmpty a)
forall a b. a -> Either a b
Left a
v
NonEmpty a
vs -> NonEmpty a -> Either a (NonEmpty a)
forall a b. b -> Either a b
Right NonEmpty a
vs
requiredFieldWith ::
Text ->
ValueCodec input output ->
Text ->
ObjectCodec input output
requiredFieldWith :: forall input output.
Text -> ValueCodec input output -> Text -> ObjectCodec input output
requiredFieldWith Text
key ValueCodec input output
c Text
doc = Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec input output
forall input output.
Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec input output
RequiredKeyCodec Text
key ValueCodec input output
c (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
doc)
requiredFieldWith' ::
Text ->
ValueCodec input output ->
ObjectCodec input output
requiredFieldWith' :: forall input output.
Text -> ValueCodec input output -> ObjectCodec input output
requiredFieldWith' Text
key ValueCodec input output
c = Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec input output
forall input output.
Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec input output
RequiredKeyCodec Text
key ValueCodec input output
c Maybe Text
forall a. Maybe a
Nothing
optionalFieldWith ::
Text ->
ValueCodec input output ->
Text ->
ObjectCodec (Maybe input) (Maybe output)
optionalFieldWith :: forall input output.
Text
-> ValueCodec input output
-> Text
-> ObjectCodec (Maybe input) (Maybe output)
optionalFieldWith Text
key ValueCodec input output
c Text
doc = Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec (Maybe input) (Maybe output)
forall a value b v.
(Coercible a (Maybe value), Coercible b (Maybe v)) =>
Text -> ValueCodec value v -> Maybe Text -> ObjectCodec a b
OptionalKeyCodec Text
key ValueCodec input output
c (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
doc)
optionalFieldWith' ::
Text ->
ValueCodec input output ->
ObjectCodec (Maybe input) (Maybe output)
optionalFieldWith' :: forall input output.
Text
-> ValueCodec input output
-> ObjectCodec (Maybe input) (Maybe output)
optionalFieldWith' Text
key ValueCodec input output
c = Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec (Maybe input) (Maybe output)
forall a value b v.
(Coercible a (Maybe value), Coercible b (Maybe v)) =>
Text -> ValueCodec value v -> Maybe Text -> ObjectCodec a b
OptionalKeyCodec Text
key ValueCodec input output
c Maybe Text
forall a. Maybe a
Nothing
optionalFieldWithDefaultWith ::
Text ->
JSONCodec output ->
output ->
Text ->
ObjectCodec output output
optionalFieldWithDefaultWith :: forall output.
Text
-> JSONCodec output -> output -> Text -> ObjectCodec output output
optionalFieldWithDefaultWith Text
key JSONCodec output
c output
defaultValue Text
doc = Text
-> JSONCodec output
-> output
-> Maybe Text
-> ObjectCodec output output
forall b value.
Coercible b value =>
Text
-> ValueCodec value value
-> value
-> Maybe Text
-> ObjectCodec value b
OptionalKeyWithDefaultCodec Text
key JSONCodec output
c output
defaultValue (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
doc)
optionalFieldWithDefaultWith' ::
Text ->
JSONCodec output ->
output ->
ObjectCodec output output
optionalFieldWithDefaultWith' :: forall output.
Text -> JSONCodec output -> output -> ObjectCodec output output
optionalFieldWithDefaultWith' Text
key JSONCodec output
c output
defaultValue = Text
-> JSONCodec output
-> output
-> Maybe Text
-> ObjectCodec output output
forall b value.
Coercible b value =>
Text
-> ValueCodec value value
-> value
-> Maybe Text
-> ObjectCodec value b
OptionalKeyWithDefaultCodec Text
key JSONCodec output
c output
defaultValue Maybe Text
forall a. Maybe a
Nothing
optionalFieldOrNullWithDefaultWith ::
(Eq output) =>
Text ->
JSONCodec output ->
output ->
Text ->
ObjectCodec output output
optionalFieldOrNullWithDefaultWith :: forall output.
Eq output =>
Text
-> JSONCodec output -> output -> Text -> ObjectCodec output output
optionalFieldOrNullWithDefaultWith Text
key JSONCodec output
c output
defaultValue Text
doc = (Maybe output -> output)
-> (output -> Maybe output)
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Maybe output -> output
f output -> Maybe output
g (Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output)
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output
forall a b. (a -> b) -> a -> b
$ Text
-> JSONCodec (Maybe output)
-> Maybe output
-> Text
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
forall output.
Text
-> JSONCodec output -> output -> Text -> ObjectCodec output output
optionalFieldWithDefaultWith Text
key (JSONCodec output -> JSONCodec (Maybe output)
forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec JSONCodec output
c) (output -> Maybe output
forall a. a -> Maybe a
Just output
defaultValue) Text
doc
where
f :: Maybe output -> output
f = \case
Just output
v -> output
v
Maybe output
Nothing -> output
defaultValue
g :: output -> Maybe output
g output
v = if output
v output -> output -> Bool
forall a. Eq a => a -> a -> Bool
== output
defaultValue then Maybe output
forall a. Maybe a
Nothing else output -> Maybe output
forall a. a -> Maybe a
Just output
v
optionalFieldOrNullWithDefaultWith' ::
(Eq output) =>
Text ->
JSONCodec output ->
output ->
ObjectCodec output output
optionalFieldOrNullWithDefaultWith' :: forall output.
Eq output =>
Text -> JSONCodec output -> output -> ObjectCodec output output
optionalFieldOrNullWithDefaultWith' Text
key JSONCodec output
c output
defaultValue = (Maybe output -> output)
-> (output -> Maybe output)
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Maybe output -> output
f output -> Maybe output
g (Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output)
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output
forall a b. (a -> b) -> a -> b
$ Text
-> JSONCodec (Maybe output)
-> Maybe output
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
forall output.
Text -> JSONCodec output -> output -> ObjectCodec output output
optionalFieldWithDefaultWith' Text
key (JSONCodec output -> JSONCodec (Maybe output)
forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec JSONCodec output
c) (output -> Maybe output
forall a. a -> Maybe a
Just output
defaultValue)
where
f :: Maybe output -> output
f = \case
Just output
v -> output
v
Maybe output
Nothing -> output
defaultValue
g :: output -> Maybe output
g output
v = if output
v output -> output -> Bool
forall a. Eq a => a -> a -> Bool
== output
defaultValue then Maybe output
forall a. Maybe a
Nothing else output -> Maybe output
forall a. a -> Maybe a
Just output
v
optionalFieldWithOmittedDefaultWith ::
(Eq output) =>
Text ->
JSONCodec output ->
output ->
Text ->
ObjectCodec output output
optionalFieldWithOmittedDefaultWith :: forall output.
Eq output =>
Text
-> JSONCodec output -> output -> Text -> ObjectCodec output output
optionalFieldWithOmittedDefaultWith Text
key JSONCodec output
c output
defaultValue Text
doc = Text
-> JSONCodec output
-> output
-> Maybe Text
-> ObjectCodec output output
forall value a b.
(Eq value, Coercible a value, Coercible b value) =>
Text
-> ValueCodec value value -> value -> Maybe Text -> ObjectCodec a b
OptionalKeyWithOmittedDefaultCodec Text
key JSONCodec output
c output
defaultValue (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
doc)
optionalFieldWithOmittedDefaultWith' ::
(Eq output) =>
Text ->
JSONCodec output ->
output ->
ObjectCodec output output
optionalFieldWithOmittedDefaultWith' :: forall output.
Eq output =>
Text -> JSONCodec output -> output -> ObjectCodec output output
optionalFieldWithOmittedDefaultWith' Text
key JSONCodec output
c output
defaultValue = Text
-> JSONCodec output
-> output
-> Maybe Text
-> ObjectCodec output output
forall value a b.
(Eq value, Coercible a value, Coercible b value) =>
Text
-> ValueCodec value value -> value -> Maybe Text -> ObjectCodec a b
OptionalKeyWithOmittedDefaultCodec Text
key JSONCodec output
c output
defaultValue Maybe Text
forall a. Maybe a
Nothing
optionalFieldOrNullWithOmittedDefaultWith ::
(Eq output) =>
Text ->
JSONCodec output ->
output ->
Text ->
ObjectCodec output output
optionalFieldOrNullWithOmittedDefaultWith :: forall output.
Eq output =>
Text
-> JSONCodec output -> output -> Text -> ObjectCodec output output
optionalFieldOrNullWithOmittedDefaultWith Text
key JSONCodec output
c output
defaultValue Text
doc = (Maybe output -> output)
-> (output -> Maybe output)
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Maybe output -> output
f output -> Maybe output
g (Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output)
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output
forall a b. (a -> b) -> a -> b
$ Text
-> JSONCodec (Maybe output)
-> Maybe output
-> Text
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
forall output.
Eq output =>
Text
-> JSONCodec output -> output -> Text -> ObjectCodec output output
optionalFieldWithOmittedDefaultWith Text
key (JSONCodec output -> JSONCodec (Maybe output)
forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec JSONCodec output
c) (output -> Maybe output
forall a. a -> Maybe a
Just output
defaultValue) Text
doc
where
f :: Maybe output -> output
f = \case
Just output
v -> output
v
Maybe output
Nothing -> output
defaultValue
g :: output -> Maybe output
g output
v = if output
v output -> output -> Bool
forall a. Eq a => a -> a -> Bool
== output
defaultValue then Maybe output
forall a. Maybe a
Nothing else output -> Maybe output
forall a. a -> Maybe a
Just output
v
optionalFieldOrNullWithOmittedDefaultWith' ::
(Eq output) =>
Text ->
JSONCodec output ->
output ->
ObjectCodec output output
optionalFieldOrNullWithOmittedDefaultWith' :: forall output.
Eq output =>
Text -> JSONCodec output -> output -> ObjectCodec output output
optionalFieldOrNullWithOmittedDefaultWith' Text
key JSONCodec output
c output
defaultValue = (Maybe output -> output)
-> (output -> Maybe output)
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Maybe output -> output
f output -> Maybe output
g (Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output)
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
-> Codec (KeyMap Value) output output
forall a b. (a -> b) -> a -> b
$ Text
-> JSONCodec (Maybe output)
-> Maybe output
-> Codec (KeyMap Value) (Maybe output) (Maybe output)
forall output.
Eq output =>
Text -> JSONCodec output -> output -> ObjectCodec output output
optionalFieldWithOmittedDefaultWith' Text
key (JSONCodec output -> JSONCodec (Maybe output)
forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec JSONCodec output
c) (output -> Maybe output
forall a. a -> Maybe a
Just output
defaultValue)
where
f :: Maybe output -> output
f = \case
Just output
v -> output
v
Maybe output
Nothing -> output
defaultValue
g :: output -> Maybe output
g output
v = if output
v output -> output -> Bool
forall a. Eq a => a -> a -> Bool
== output
defaultValue then Maybe output
forall a. Maybe a
Nothing else output -> Maybe output
forall a. a -> Maybe a
Just output
v
optionalFieldOrNullWith ::
Text ->
ValueCodec input output ->
Text ->
ObjectCodec (Maybe input) (Maybe output)
optionalFieldOrNullWith :: forall input output.
Text
-> ValueCodec input output
-> Text
-> ObjectCodec (Maybe input) (Maybe output)
optionalFieldOrNullWith Text
key ValueCodec input output
c Text
doc = ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output)
forall input output.
ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output)
orNullHelper (ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output))
-> ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output)
forall a b. (a -> b) -> a -> b
$ Text
-> ValueCodec (Maybe input) (Maybe output)
-> Maybe Text
-> ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
forall a value b v.
(Coercible a (Maybe value), Coercible b (Maybe v)) =>
Text -> ValueCodec value v -> Maybe Text -> ObjectCodec a b
OptionalKeyCodec Text
key (ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec ValueCodec input output
c) (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
doc)
optionalFieldOrNullWith' ::
Text ->
ValueCodec input output ->
ObjectCodec (Maybe input) (Maybe output)
optionalFieldOrNullWith' :: forall input output.
Text
-> ValueCodec input output
-> ObjectCodec (Maybe input) (Maybe output)
optionalFieldOrNullWith' Text
key ValueCodec input output
c = ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output)
forall input output.
ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output)
orNullHelper (ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output))
-> ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output)
forall a b. (a -> b) -> a -> b
$ Text
-> ValueCodec (Maybe input) (Maybe output)
-> Maybe Text
-> ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
forall a value b v.
(Coercible a (Maybe value), Coercible b (Maybe v)) =>
Text -> ValueCodec value v -> Maybe Text -> ObjectCodec a b
OptionalKeyCodec Text
key (ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec ValueCodec input output
c) Maybe Text
forall a. Maybe a
Nothing
(<?>) ::
ValueCodec input output ->
Text ->
ValueCodec input output
<?> :: forall input output.
ValueCodec input output -> Text -> ValueCodec input output
(<?>) = (Text -> ValueCodec input output -> ValueCodec input output)
-> ValueCodec input output -> Text -> ValueCodec input output
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> ValueCodec input output -> ValueCodec input output
forall input output.
Text -> ValueCodec input output -> ValueCodec input output
CommentCodec
(<??>) ::
ValueCodec input output ->
[Text] ->
ValueCodec input output
<??> :: forall input output.
ValueCodec input output -> [Text] -> ValueCodec input output
(<??>) ValueCodec input output
c [Text]
ls = Text -> ValueCodec input output -> ValueCodec input output
forall input output.
Text -> ValueCodec input output -> ValueCodec input output
CommentCodec ([Text] -> Text
T.unlines [Text]
ls) ValueCodec input output
c
hashMapCodec ::
(Eq k, Hashable k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v ->
JSONCodec (HashMap k v)
hashMapCodec :: forall k v.
(Eq k, Hashable k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v -> JSONCodec (HashMap k v)
hashMapCodec = JSONCodec v -> ValueCodec (HashMap k v) (HashMap k v)
forall value a v b.
(Eq value, Hashable value, FromJSONKey value, ToJSONKey value,
Coercible a (HashMap value v), Coercible b (HashMap value v)) =>
JSONCodec v -> ValueCodec a b
HashMapCodec
mapCodec ::
(Ord k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v ->
JSONCodec (Map k v)
mapCodec :: forall k v.
(Ord k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v -> JSONCodec (Map k v)
mapCodec = JSONCodec v -> ValueCodec (Map k v) (Map k v)
forall value a v b.
(Ord value, FromJSONKey value, ToJSONKey value,
Coercible a (Map value v), Coercible b (Map value v)) =>
JSONCodec v -> ValueCodec a b
MapCodec
#if MIN_VERSION_aeson(2,0,0)
keyMapCodec ::
JSONCodec v ->
JSONCodec (KeyMap v)
keyMapCodec :: forall v. JSONCodec v -> JSONCodec (KeyMap v)
keyMapCodec = case Maybe (Coercion (Map Key Any) (KeyMap Any))
forall v. Maybe (Coercion (Map Key v) (KeyMap v))
KM.coercionToMap of
Just Coercion (Map Key Any) (KeyMap Any)
_ -> (Map Key v -> KeyMap v)
-> (KeyMap v -> Map Key v)
-> Codec Value (Map Key v) (Map Key v)
-> JSONCodec (KeyMap v)
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Map Key v -> KeyMap v
forall v. Map Key v -> KeyMap v
KM.fromMap KeyMap v -> Map Key v
forall v. KeyMap v -> Map Key v
KM.toMap (Codec Value (Map Key v) (Map Key v) -> JSONCodec (KeyMap v))
-> (JSONCodec v -> Codec Value (Map Key v) (Map Key v))
-> JSONCodec v
-> JSONCodec (KeyMap v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSONCodec v -> Codec Value (Map Key v) (Map Key v)
forall k v.
(Ord k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v -> JSONCodec (Map k v)
mapCodec
Maybe (Coercion (Map Key Any) (KeyMap Any))
Nothing -> (HashMap Key v -> KeyMap v)
-> (KeyMap v -> HashMap Key v)
-> Codec Value (HashMap Key v) (HashMap Key v)
-> JSONCodec (KeyMap v)
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec HashMap Key v -> KeyMap v
forall v. HashMap Key v -> KeyMap v
KM.fromHashMap KeyMap v -> HashMap Key v
forall v. KeyMap v -> HashMap Key v
KM.toHashMap (Codec Value (HashMap Key v) (HashMap Key v)
-> JSONCodec (KeyMap v))
-> (JSONCodec v -> Codec Value (HashMap Key v) (HashMap Key v))
-> JSONCodec v
-> JSONCodec (KeyMap v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSONCodec v -> Codec Value (HashMap Key v) (HashMap Key v)
forall k v.
(Eq k, Hashable k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v -> JSONCodec (HashMap k v)
hashMapCodec
#endif
valueCodec :: JSONCodec JSON.Value
valueCodec :: JSONCodec Value
valueCodec = JSONCodec Value
forall a b.
(Coercible Value a, Coercible Value b) =>
ValueCodec a b
ValueCodec
nullCodec :: JSONCodec ()
nullCodec :: Codec Value () ()
nullCodec = Codec Value () ()
forall a b. (Coercible a (), Coercible b ()) => ValueCodec a b
NullCodec
boolCodec :: JSONCodec Bool
boolCodec :: JSONCodec Bool
boolCodec = Maybe Text -> JSONCodec Bool
forall a b.
(Coercible a Bool, Coercible b Bool) =>
Maybe Text -> ValueCodec a b
BoolCodec Maybe Text
forall a. Maybe a
Nothing
textCodec :: JSONCodec Text
textCodec :: JSONCodec Text
textCodec = Maybe Text -> JSONCodec Text
forall a b.
(Coercible a Text, Coercible b Text) =>
Maybe Text -> ValueCodec a b
StringCodec Maybe Text
forall a. Maybe a
Nothing
stringCodec :: JSONCodec String
stringCodec :: JSONCodec String
stringCodec = (Text -> String)
-> (String -> Text) -> JSONCodec Text -> JSONCodec String
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Text -> String
T.unpack String -> Text
T.pack JSONCodec Text
textCodec
scientificCodec :: JSONCodec Scientific
scientificCodec :: JSONCodec Scientific
scientificCodec = Maybe Text -> Bounds Scientific -> JSONCodec Scientific
forall a b.
(Coercible a Scientific, Coercible b Scientific) =>
Maybe Text -> Bounds Scientific -> ValueCodec a b
NumberCodec Maybe Text
forall a. Maybe a
Nothing Bounds Scientific
forall a. Bounds a
emptyBounds
integerCodec :: JSONCodec Integer
integerCodec :: JSONCodec Integer
integerCodec = Maybe Text -> Bounds Integer -> JSONCodec Integer
forall a b.
(Coercible a Integer, Coercible b Integer) =>
Maybe Text -> Bounds Integer -> ValueCodec a b
IntegerCodec Maybe Text
forall a. Maybe a
Nothing Bounds Integer
forall a. Bounds a
emptyBounds
naturalCodec :: JSONCodec Natural
naturalCodec :: JSONCodec Natural
naturalCodec =
(Integer -> Natural)
-> (Natural -> Integer) -> JSONCodec Integer -> JSONCodec Natural
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (JSONCodec Integer -> JSONCodec Natural)
-> JSONCodec Integer -> JSONCodec Natural
forall a b. (a -> b) -> a -> b
$
Bounds Integer -> JSONCodec Integer
integerWithBoundsCodec
( Bounds
{ boundsLower :: Maybe Integer
boundsLower = Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
0,
boundsUpper :: Maybe Integer
boundsUpper = Maybe Integer
forall a. Maybe a
Nothing
}
)
scientificWithBoundsCodec :: Bounds Scientific -> JSONCodec Scientific
scientificWithBoundsCodec :: Bounds Scientific -> JSONCodec Scientific
scientificWithBoundsCodec Bounds Scientific
bounds = Maybe Text -> Bounds Scientific -> JSONCodec Scientific
forall a b.
(Coercible a Scientific, Coercible b Scientific) =>
Maybe Text -> Bounds Scientific -> ValueCodec a b
NumberCodec Maybe Text
forall a. Maybe a
Nothing Bounds Scientific
bounds
integerWithBoundsCodec :: Bounds Integer -> JSONCodec Integer
integerWithBoundsCodec :: Bounds Integer -> JSONCodec Integer
integerWithBoundsCodec Bounds Integer
bounds = Maybe Text -> Bounds Integer -> JSONCodec Integer
forall a b.
(Coercible a Integer, Coercible b Integer) =>
Maybe Text -> Bounds Integer -> ValueCodec a b
IntegerCodec Maybe Text
forall a. Maybe a
Nothing Bounds Integer
bounds
object :: Text -> ObjectCodec input output -> ValueCodec input output
object :: forall input output.
Text -> ObjectCodec input output -> ValueCodec input output
object Text
name = Maybe Text -> ObjectCodec input output -> ValueCodec input output
forall input output.
Maybe Text -> ObjectCodec input output -> ValueCodec input output
ObjectOfCodec (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
name)
boundedIntegralCodec :: forall i. (Integral i, Bounded i) => JSONCodec i
boundedIntegralCodec :: forall i. (Integral i, Bounded i) => JSONCodec i
boundedIntegralCodec =
(Integer -> i)
-> (i -> Integer) -> JSONCodec Integer -> Codec Value i i
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Integer -> i
forall a b. (Integral a, Num b) => a -> b
fromIntegral i -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (JSONCodec Integer -> Codec Value i i)
-> JSONCodec Integer -> Codec Value i i
forall a b. (a -> b) -> a -> b
$ Bounds Integer -> JSONCodec Integer
integerWithBoundsCodec (forall i. (Integral i, Bounded i) => Bounds Integer
boundedIntegralBounds @i)
boundedIntegralBounds :: forall i. (Integral i, Bounded i) => Bounds Integer
boundedIntegralBounds :: forall i. (Integral i, Bounded i) => Bounds Integer
boundedIntegralBounds = i -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (i -> Integer) -> Bounds i -> Bounds Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Bounded a => Bounds a
boundedBounds @i
unsafeUnboundedIntegerCodec :: JSONCodec Integer
unsafeUnboundedIntegerCodec :: JSONCodec Integer
unsafeUnboundedIntegerCodec =
(Scientific -> Either String Integer)
-> (Integer -> Scientific)
-> JSONCodec Scientific
-> JSONCodec Integer
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec Scientific -> Either String Integer
go Integer -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral JSONCodec Scientific
scientificCodec
where
go :: Scientific -> Either String Integer
go Scientific
s = case Scientific -> Either Float Integer
forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
Scientific.floatingOrInteger Scientific
s :: Either Float Integer of
Right Integer
i -> Integer -> Either String Integer
forall a b. b -> Either a b
Right Integer
i
Left Float
_ -> String -> Either String Integer
forall a b. a -> Either a b
Left (String
"Number is not an integer: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
s)
unsafeUnboundedNaturalCodec :: JSONCodec Natural
unsafeUnboundedNaturalCodec :: JSONCodec Natural
unsafeUnboundedNaturalCodec =
(Scientific -> Either String Natural)
-> (Natural -> Scientific)
-> JSONCodec Scientific
-> JSONCodec Natural
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec Scientific -> Either String Natural
go Natural -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral JSONCodec Scientific
scientificCodec
where
go :: Scientific -> Either String Natural
go Scientific
s = case Scientific -> Either Float Natural
forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
Scientific.floatingOrInteger Scientific
s :: Either Float Natural of
Right Natural
i -> Natural -> Either String Natural
forall a b. b -> Either a b
Right Natural
i
Left Float
_ -> String -> Either String Natural
forall a b. a -> Either a b
Left (String
"Number is not an integer: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
s)
literalTextCodec :: Text -> JSONCodec Text
literalTextCodec :: Text -> JSONCodec Text
literalTextCodec Text
text = Text -> JSONCodec Text -> JSONCodec Text
forall value a b.
(Show value, Eq value, Coercible a value, Coercible b value) =>
value -> ValueCodec value value -> ValueCodec a b
EqCodec Text
text JSONCodec Text
textCodec
literalTextValueCodec :: value -> Text -> JSONCodec value
literalTextValueCodec :: forall value. value -> Text -> JSONCodec value
literalTextValueCodec value
value Text
text = (Text -> value)
-> (value -> Text) -> JSONCodec Text -> Codec Value value value
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec (value -> Text -> value
forall a b. a -> b -> a
const value
value) (Text -> value -> Text
forall a b. a -> b -> a
const Text
text) (Text -> JSONCodec Text
literalTextCodec Text
text)
matchChoiceCodec ::
Codec context input output ->
Codec context input' output ->
(newInput -> Either input input') ->
Codec context newInput output
matchChoiceCodec :: forall context input output input' newInput.
Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
matchChoiceCodec = Union
-> Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
forall context input output input' newInput.
Union
-> Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
matchChoiceCodecAs Union
PossiblyJointUnion
disjointMatchChoiceCodec ::
Codec context input output ->
Codec context input' output ->
(newInput -> Either input input') ->
Codec context newInput output
disjointMatchChoiceCodec :: forall context input output input' newInput.
Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
disjointMatchChoiceCodec = Union
-> Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
forall context input output input' newInput.
Union
-> Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
matchChoiceCodecAs Union
DisjointUnion
matchChoiceCodecAs ::
Union ->
Codec context input output ->
Codec context input' output ->
(newInput -> Either input input') ->
Codec context newInput output
matchChoiceCodecAs :: forall context input output input' newInput.
Union
-> Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
matchChoiceCodecAs Union
union Codec context input output
c1 Codec context input' output
c2 newInput -> Either input input'
renderingChooser =
(Either output output -> output)
-> (newInput -> Either input input')
-> Codec context (Either input input') (Either output output)
-> Codec context newInput output
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec ((output -> output)
-> (output -> output) -> Either output output -> output
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either output -> output
forall a. a -> a
id output -> output
forall a. a -> a
id) newInput -> Either input input'
renderingChooser (Codec context (Either input input') (Either output output)
-> Codec context newInput output)
-> Codec context (Either input input') (Either output output)
-> Codec context newInput output
forall a b. (a -> b) -> a -> b
$
Union
-> Codec context input output
-> Codec context input' output
-> Codec context (Either input input') (Either output output)
forall a value v b output1 output2 context.
(Coercible a (Either value v),
Coercible b (Either output1 output2)) =>
Union
-> Codec context value output1
-> Codec context v output2
-> Codec context a b
EitherCodec Union
union Codec context input output
c1 Codec context input' output
c2
matchChoicesCodec ::
[(input -> Maybe input, Codec context input output)] ->
Codec context input output ->
Codec context input output
matchChoicesCodec :: forall input context output.
[(input -> Maybe input, Codec context input output)]
-> Codec context input output -> Codec context input output
matchChoicesCodec = Union
-> [(input -> Maybe input, Codec context input output)]
-> Codec context input output
-> Codec context input output
forall input context output.
Union
-> [(input -> Maybe input, Codec context input output)]
-> Codec context input output
-> Codec context input output
matchChoicesCodecAs Union
PossiblyJointUnion
disjointMatchChoicesCodec ::
[(input -> Maybe input, Codec context input output)] ->
Codec context input output ->
Codec context input output
disjointMatchChoicesCodec :: forall input context output.
[(input -> Maybe input, Codec context input output)]
-> Codec context input output -> Codec context input output
disjointMatchChoicesCodec = Union
-> [(input -> Maybe input, Codec context input output)]
-> Codec context input output
-> Codec context input output
forall input context output.
Union
-> [(input -> Maybe input, Codec context input output)]
-> Codec context input output
-> Codec context input output
matchChoicesCodecAs Union
DisjointUnion
matchChoicesCodecAs ::
Union ->
[(input -> Maybe input, Codec context input output)] ->
Codec context input output ->
Codec context input output
matchChoicesCodecAs :: forall input context output.
Union
-> [(input -> Maybe input, Codec context input output)]
-> Codec context input output
-> Codec context input output
matchChoicesCodecAs Union
union [(input -> Maybe input, Codec context input output)]
l Codec context input output
fallback = [(input -> Maybe input, Codec context input output)]
-> Codec context input output
go [(input -> Maybe input, Codec context input output)]
l
where
go :: [(input -> Maybe input, Codec context input output)]
-> Codec context input output
go = \case
[] -> Codec context input output
fallback
((input -> Maybe input
m, Codec context input output
c) : [(input -> Maybe input, Codec context input output)]
rest) -> Union
-> Codec context input output
-> Codec context input output
-> (input -> Either input input)
-> Codec context input output
forall context input output input' newInput.
Union
-> Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
matchChoiceCodecAs Union
union Codec context input output
c ([(input -> Maybe input, Codec context input output)]
-> Codec context input output
go [(input -> Maybe input, Codec context input output)]
rest) ((input -> Either input input) -> Codec context input output)
-> (input -> Either input input) -> Codec context input output
forall a b. (a -> b) -> a -> b
$ \input
i -> case input -> Maybe input
m input
i of
Just input
j -> input -> Either input input
forall a b. a -> Either a b
Left input
j
Maybe input
Nothing -> input -> Either input input
forall a b. b -> Either a b
Right input
i
parseAlternatives ::
Codec context input output ->
[Codec context input output] ->
Codec context input output
parseAlternatives :: forall context input output.
Codec context input output
-> [Codec context input output] -> Codec context input output
parseAlternatives Codec context input output
c [Codec context input output]
rest = NonEmpty (Codec context input output) -> Codec context input output
forall context input output.
NonEmpty (Codec context input output) -> Codec context input output
go (Codec context input output
c Codec context input output
-> [Codec context input output]
-> NonEmpty (Codec context input output)
forall a. a -> [a] -> NonEmpty a
:| [Codec context input output]
rest)
where
go :: NonEmpty (Codec context input output) -> Codec context input output
go :: forall context input output.
NonEmpty (Codec context input output) -> Codec context input output
go = \case
(Codec context input output
c' :| [Codec context input output]
cRest) -> case [Codec context input output]
-> Maybe (NonEmpty (Codec context input output))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [Codec context input output]
cRest of
Maybe (NonEmpty (Codec context input output))
Nothing -> Codec context input output
c'
Just NonEmpty (Codec context input output)
ne' -> Codec context input output
-> Codec context input output
-> (input -> Either input input)
-> Codec context input output
forall context input output input' newInput.
Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
matchChoiceCodec Codec context input output
c' (NonEmpty (Codec context input output) -> Codec context input output
forall context input output.
NonEmpty (Codec context input output) -> Codec context input output
go NonEmpty (Codec context input output)
ne') input -> Either input input
forall a b. a -> Either a b
Left
parseAlternative ::
Codec context input output ->
Codec context input' output ->
Codec context input output
parseAlternative :: forall context input output input'.
Codec context input output
-> Codec context input' output -> Codec context input output
parseAlternative Codec context input output
c Codec context input' output
cAlt = Codec context input output
-> Codec context input' output
-> (input -> Either input input')
-> Codec context input output
forall context input output input' newInput.
Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
matchChoiceCodec Codec context input output
c Codec context input' output
cAlt input -> Either input input'
forall a b. a -> Either a b
Left
enumCodec ::
forall enum context.
(Eq enum) =>
NonEmpty (enum, Codec context enum enum) ->
Codec context enum enum
enumCodec :: forall enum context.
Eq enum =>
NonEmpty (enum, Codec context enum enum) -> Codec context enum enum
enumCodec = NonEmpty (enum, Codec context enum enum) -> Codec context enum enum
go
where
go :: NonEmpty (enum, Codec context enum enum) -> Codec context enum enum
go :: NonEmpty (enum, Codec context enum enum) -> Codec context enum enum
go ((enum
e, Codec context enum enum
c) :| [(enum, Codec context enum enum)]
rest) = case [(enum, Codec context enum enum)]
-> Maybe (NonEmpty (enum, Codec context enum enum))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [(enum, Codec context enum enum)]
rest of
Maybe (NonEmpty (enum, Codec context enum enum))
Nothing -> Codec context enum enum
c
Just NonEmpty (enum, Codec context enum enum)
ne -> Codec context enum enum
-> Codec context enum enum
-> (enum -> Either enum enum)
-> Codec context enum enum
forall context input output input' newInput.
Codec context input output
-> Codec context input' output
-> (newInput -> Either input input')
-> Codec context newInput output
disjointMatchChoiceCodec Codec context enum enum
c (NonEmpty (enum, Codec context enum enum) -> Codec context enum enum
go NonEmpty (enum, Codec context enum enum)
ne) ((enum -> Either enum enum) -> Codec context enum enum)
-> (enum -> Either enum enum) -> Codec context enum enum
forall a b. (a -> b) -> a -> b
$ \enum
i ->
if enum
e enum -> enum -> Bool
forall a. Eq a => a -> a -> Bool
== enum
i
then enum -> Either enum enum
forall a b. a -> Either a b
Left enum
e
else enum -> Either enum enum
forall a b. b -> Either a b
Right enum
i
stringConstCodec ::
forall constant.
(Eq constant) =>
NonEmpty (constant, Text) ->
JSONCodec constant
stringConstCodec :: forall constant.
Eq constant =>
NonEmpty (constant, Text) -> JSONCodec constant
stringConstCodec =
NonEmpty (constant, Codec Value constant constant)
-> Codec Value constant constant
forall enum context.
Eq enum =>
NonEmpty (enum, Codec context enum enum) -> Codec context enum enum
enumCodec
(NonEmpty (constant, Codec Value constant constant)
-> Codec Value constant constant)
-> (NonEmpty (constant, Text)
-> NonEmpty (constant, Codec Value constant constant))
-> NonEmpty (constant, Text)
-> Codec Value constant constant
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((constant, Text) -> (constant, Codec Value constant constant))
-> NonEmpty (constant, Text)
-> NonEmpty (constant, Codec Value constant constant)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NE.map
( \(constant
constant, Text
text) ->
( constant
constant,
constant -> Text -> Codec Value constant constant
forall value. value -> Text -> JSONCodec value
literalTextValueCodec constant
constant Text
text
)
)
boundedEnumCodec ::
forall enum.
(Eq enum, Enum enum, Bounded enum) =>
(enum -> T.Text) ->
JSONCodec enum
boundedEnumCodec :: forall enum.
(Eq enum, Enum enum, Bounded enum) =>
(enum -> Text) -> JSONCodec enum
boundedEnumCodec enum -> Text
showFunc =
let ls :: [enum]
ls = [enum
forall a. Bounded a => a
minBound .. enum
forall a. Bounded a => a
maxBound]
in case [enum] -> Maybe (NonEmpty enum)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [enum]
ls of
Maybe (NonEmpty enum)
Nothing -> String -> JSONCodec enum
forall a. HasCallStack => String -> a
error String
"0 enum values ?!"
Just NonEmpty enum
ne -> NonEmpty (enum, Text) -> JSONCodec enum
forall constant.
Eq constant =>
NonEmpty (constant, Text) -> JSONCodec constant
stringConstCodec ((enum -> (enum, Text)) -> NonEmpty enum -> NonEmpty (enum, Text)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NE.map (\enum
v -> (enum
v, enum -> Text
showFunc enum
v)) NonEmpty enum
ne)
shownBoundedEnumCodec ::
forall enum.
(Show enum, Eq enum, Enum enum, Bounded enum) =>
JSONCodec enum
shownBoundedEnumCodec :: forall enum.
(Show enum, Eq enum, Enum enum, Bounded enum) =>
JSONCodec enum
shownBoundedEnumCodec = (enum -> Text) -> JSONCodec enum
forall enum.
(Eq enum, Enum enum, Bounded enum) =>
(enum -> Text) -> JSONCodec enum
boundedEnumCodec (String -> Text
T.pack (String -> Text) -> (enum -> String) -> enum -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. enum -> String
forall a. Show a => a -> String
show)
orNullHelper ::
ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output)) ->
ObjectCodec (Maybe input) (Maybe output)
orNullHelper :: forall input output.
ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output)
orNullHelper = (Maybe (Maybe output) -> Maybe output)
-> (Maybe input -> Maybe (Maybe input))
-> Codec
(KeyMap Value) (Maybe (Maybe input)) (Maybe (Maybe output))
-> Codec (KeyMap Value) (Maybe input) (Maybe output)
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Maybe (Maybe output) -> Maybe output
forall input. Maybe (Maybe input) -> Maybe input
f Maybe input -> Maybe (Maybe input)
forall output. Maybe output -> Maybe (Maybe output)
g
where
f :: Maybe (Maybe input) -> Maybe input
f :: forall input. Maybe (Maybe input) -> Maybe input
f = \case
Maybe (Maybe input)
Nothing -> Maybe input
forall a. Maybe a
Nothing
Just Maybe input
Nothing -> Maybe input
forall a. Maybe a
Nothing
Just (Just input
a) -> input -> Maybe input
forall a. a -> Maybe a
Just input
a
g :: Maybe output -> Maybe (Maybe output)
g :: forall output. Maybe output -> Maybe (Maybe output)
g = \case
Maybe output
Nothing -> Maybe (Maybe output)
forall a. Maybe a
Nothing
Just output
a -> Maybe output -> Maybe (Maybe output)
forall a. a -> Maybe a
Just (output -> Maybe output
forall a. a -> Maybe a
Just output
a)
named :: Text -> ValueCodec input output -> ValueCodec input output
named :: forall input output.
Text -> ValueCodec input output -> ValueCodec input output
named = Text -> ValueCodec input output -> ValueCodec input output
forall input output.
Text -> ValueCodec input output -> ValueCodec input output
ReferenceCodec
codecViaAeson ::
(FromJSON a, ToJSON a) =>
Text ->
JSONCodec a
codecViaAeson :: forall a. (FromJSON a, ToJSON a) => Text -> JSONCodec a
codecViaAeson Text
doc = (Value -> Either String a)
-> (a -> Value) -> JSONCodec Value -> Codec Value a a
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec ((Value -> Parser a) -> Value -> Either String a
forall a b. (a -> Parser b) -> a -> Either String b
JSON.parseEither Value -> Parser a
forall a. FromJSON a => Value -> Parser a
JSON.parseJSON) a -> Value
forall a. ToJSON a => a -> Value
JSON.toJSON JSONCodec Value
valueCodec Codec Value a a -> Text -> Codec Value a a
forall input output.
ValueCodec input output -> Text -> ValueCodec input output
<?> Text
doc
newtype Result a = Result {forall a. Result a -> Either String a
runResult :: Either String a}
deriving newtype ((forall a b. (a -> b) -> Result a -> Result b)
-> (forall a b. a -> Result b -> Result a) -> Functor Result
forall a b. a -> Result b -> Result a
forall a b. (a -> b) -> Result a -> Result b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Result a -> Result b
fmap :: forall a b. (a -> b) -> Result a -> Result b
$c<$ :: forall a b. a -> Result b -> Result a
<$ :: forall a b. a -> Result b -> Result a
Functor, Functor Result
Functor Result =>
(forall a. a -> Result a)
-> (forall a b. Result (a -> b) -> Result a -> Result b)
-> (forall a b c.
(a -> b -> c) -> Result a -> Result b -> Result c)
-> (forall a b. Result a -> Result b -> Result b)
-> (forall a b. Result a -> Result b -> Result a)
-> Applicative Result
forall a. a -> Result a
forall a b. Result a -> Result b -> Result a
forall a b. Result a -> Result b -> Result b
forall a b. Result (a -> b) -> Result a -> Result b
forall a b c. (a -> b -> c) -> Result a -> Result b -> Result c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> Result a
pure :: forall a. a -> Result a
$c<*> :: forall a b. Result (a -> b) -> Result a -> Result b
<*> :: forall a b. Result (a -> b) -> Result a -> Result b
$cliftA2 :: forall a b c. (a -> b -> c) -> Result a -> Result b -> Result c
liftA2 :: forall a b c. (a -> b -> c) -> Result a -> Result b -> Result c
$c*> :: forall a b. Result a -> Result b -> Result b
*> :: forall a b. Result a -> Result b -> Result b
$c<* :: forall a b. Result a -> Result b -> Result a
<* :: forall a b. Result a -> Result b -> Result a
Applicative, Applicative Result
Applicative Result =>
(forall a b. Result a -> (a -> Result b) -> Result b)
-> (forall a b. Result a -> Result b -> Result b)
-> (forall a. a -> Result a)
-> Monad Result
forall a. a -> Result a
forall a b. Result a -> Result b -> Result b
forall a b. Result a -> (a -> Result b) -> Result b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b. Result a -> (a -> Result b) -> Result b
>>= :: forall a b. Result a -> (a -> Result b) -> Result b
$c>> :: forall a b. Result a -> Result b -> Result b
>> :: forall a b. Result a -> Result b -> Result b
$creturn :: forall a. a -> Result a
return :: forall a. a -> Result a
Monad)
instance MonadFail Result where
fail :: forall a. String -> Result a
fail = Either String a -> Result a
forall a. Either String a -> Result a
Result (Either String a -> Result a)
-> (String -> Either String a) -> String -> Result a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Either String a
forall a b. a -> Either a b
Left
unsafeCodecViaAesonString ::
(FromJSON a, ToJSON a) =>
Text ->
JSONCodec a
unsafeCodecViaAesonString :: forall a. (FromJSON a, ToJSON a) => Text -> JSONCodec a
unsafeCodecViaAesonString Text
doc = (Text -> Either String a)
-> (a -> Text) -> JSONCodec Text -> Codec Value a a
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec ((Value -> Parser a) -> Value -> Either String a
forall a b. (a -> Parser b) -> a -> Either String b
JSON.parseEither Value -> Parser a
forall a. FromJSON a => Value -> Parser a
JSON.parseJSON (Value -> Either String a)
-> (Text -> Value) -> Text -> Either String a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Value
JSON.String) (Value -> Text
unsafeAesonValueToString (Value -> Text) -> (a -> Value) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Value
forall a. ToJSON a => a -> Value
JSON.toJSON) JSONCodec Text
textCodec Codec Value a a -> Text -> Codec Value a a
forall input output.
ValueCodec input output -> Text -> ValueCodec input output
<?> Text
doc
where
unsafeAesonValueToString :: Value -> Text
unsafeAesonValueToString Value
v = case Value
v of
JSON.String Text
s -> Text
s
Value
_ -> String -> Text
forall a. HasCallStack => String -> a
error (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ String
"unsafeAesonValueToString failed.\n " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Value -> String
forall a. Show a => a -> String
show Value
v String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"\n is not a JSON string."