{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# 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
#if MIN_VERSION_aeson(2,0,0)
import Data.Aeson.KeyMap (KeyMap)
import qualified Data.Aeson.KeyMap as KM
#endif
import qualified Data.Aeson.Types as JSON
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 GHC.Generics (Generic)
import Numeric.Natural
data Codec context input output where
NullCodec ::
ValueCodec () ()
BoolCodec ::
Maybe Text ->
JSONCodec Bool
StringCodec ::
Maybe Text ->
JSONCodec Text
NumberCodec ::
Maybe Text ->
Maybe NumberBounds ->
JSONCodec Scientific
HashMapCodec ::
(Eq k, Hashable k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v ->
JSONCodec (HashMap k v)
MapCodec ::
(Ord k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v ->
JSONCodec (Map k v)
ValueCodec ::
JSONCodec JSON.Value
ArrayOfCodec ::
Maybe Text ->
ValueCodec input output ->
ValueCodec (Vector input) (Vector output)
ObjectOfCodec ::
Maybe Text ->
ObjectCodec input output ->
ValueCodec input output
EqCodec ::
(Show value, Eq value) =>
value ->
JSONCodec value ->
JSONCodec value
BimapCodec ::
(oldOutput -> Either String newOutput) ->
(newInput -> oldInput) ->
Codec context oldInput oldOutput ->
Codec context newInput newOutput
EitherCodec ::
!Union ->
Codec context input1 output1 ->
Codec context input2 output2 ->
Codec context (Either input1 input2) (Either output1 output2)
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 ::
Text ->
ValueCodec input output ->
Maybe Text ->
ObjectCodec (Maybe input) (Maybe output)
OptionalKeyWithDefaultCodec ::
Text ->
ValueCodec value value ->
value ->
Maybe Text ->
ObjectCodec value value
OptionalKeyWithOmittedDefaultCodec ::
Eq value =>
Text ->
ValueCodec value value ->
value ->
Maybe Text ->
ObjectCodec value value
PureCodec ::
output ->
ObjectCodec void output
ApCodec ::
ObjectCodec input (output -> newOutput) ->
ObjectCodec input output ->
ObjectCodec input newOutput
data NumberBounds = NumberBounds
{ NumberBounds -> Scientific
numberBoundsLower :: !Scientific,
NumberBounds -> Scientific
numberBoundsUpper :: !Scientific
}
deriving (Int -> NumberBounds -> ShowS
[NumberBounds] -> ShowS
NumberBounds -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NumberBounds] -> ShowS
$cshowList :: [NumberBounds] -> ShowS
show :: NumberBounds -> String
$cshow :: NumberBounds -> String
showsPrec :: Int -> NumberBounds -> ShowS
$cshowsPrec :: Int -> NumberBounds -> ShowS
Show, NumberBounds -> NumberBounds -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NumberBounds -> NumberBounds -> Bool
$c/= :: NumberBounds -> NumberBounds -> Bool
== :: NumberBounds -> NumberBounds -> Bool
$c== :: NumberBounds -> NumberBounds -> Bool
Eq, forall x. Rep NumberBounds x -> NumberBounds
forall x. NumberBounds -> Rep NumberBounds x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NumberBounds x -> NumberBounds
$cfrom :: forall x. NumberBounds -> Rep NumberBounds x
Generic)
instance Validity NumberBounds
checkNumberBounds :: NumberBounds -> Scientific -> Either String Scientific
checkNumberBounds :: NumberBounds -> Scientific -> Either String Scientific
checkNumberBounds NumberBounds {Scientific
numberBoundsUpper :: Scientific
numberBoundsLower :: Scientific
numberBoundsUpper :: NumberBounds -> Scientific
numberBoundsLower :: NumberBounds -> Scientific
..} Scientific
s =
if Scientific
numberBoundsLower forall a. Ord a => a -> a -> Bool
<= Scientific
s
then
if Scientific
s forall a. Ord a => a -> a -> Bool
<= Scientific
numberBoundsUpper
then forall a b. b -> Either a b
Right Scientific
s
else forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ [String] -> String
unwords [String
"Number", forall a. Show a => a -> String
show Scientific
s, String
"is bigger than the upper bound", forall a. Show a => a -> String
show Scientific
numberBoundsUpper]
else forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ [String] -> String
unwords [String
"Number", forall a. Show a => a -> String
show Scientific
s, String
"is smaller than the lower bound", forall a. Show a => a -> String
show Scientific
numberBoundsUpper]
data Union
=
PossiblyJointUnion
|
DisjointUnion
deriving (Int -> Union -> ShowS
[Union] -> ShowS
Union -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Union] -> ShowS
$cshowList :: [Union] -> ShowS
show :: Union -> String
$cshow :: Union -> String
showsPrec :: Int -> Union -> ShowS
$cshowsPrec :: Int -> Union -> ShowS
Show, Union -> Union -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Union -> Union -> Bool
$c/= :: Union -> Union -> Bool
== :: Union -> Union -> Bool
$c== :: Union -> Union -> Bool
Eq, 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
$cto :: forall x. Rep Union x -> Union
$cfrom :: forall x. Union -> Rep Union x
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 = (forall a b. (a -> b) -> a -> b
$ String
"") forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s a. State s a -> s -> a
`evalState` forall a. Set a
S.empty) forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"NullCodec"
BoolCodec Maybe Text
mName -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"BoolCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName
StringCodec Maybe Text
mName -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"StringCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName
NumberCodec Maybe Text
mName Maybe NumberBounds
mbs -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"NumberCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe NumberBounds
mbs
ArrayOfCodec Maybe Text
mName ValueCodec input output
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ArrayOfCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ObjectOfCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mName forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ValueCodec"
MapCodec JSONCodec v
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"MapCodec" forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"HashMapCodec" forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 JSONCodec v
c
EqCodec input
value JSONCodec input
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"EqCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 input
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 JSONCodec input
c
BimapCodec oldOutput -> Either String output
_ input -> oldInput
_ Codec context oldInput oldOutput
c -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"BimapCodec _ _ " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"EitherCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Union
u forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s2) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 Codec context input1 output1
c1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 <- forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (\(Text
n, (Text
_, ObjectCodec Void output
c)) -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen Bool
True forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> ShowS
shows Text
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
", " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ObjectCodec Void output
c) forall a b. (a -> b) -> a -> b
$ 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
"[" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) forall a. a -> a
id (forall a. a -> [a] -> [a]
intersperse (String -> ShowS
showString String
", ") [ShowS]
cs) forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"]"
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"DiscriminatedUnionCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
propertyName forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" _ " 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 forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"CommentCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
comment forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall a. Ord a => a -> Set a -> Bool
S.member Text
name)
if Bool
alreadySeen
then forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ReferenceCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
name
else do
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (forall a. Ord a => a -> Set a -> Set a
S.insert Text
name)
ShowS
s <- forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ValueCodec input output
c
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ReferenceCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " 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 forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"RequiredKeyCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mdoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"OptionalKeyCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mdoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ValueCodec input output
c
OptionalKeyWithDefaultCodec Text
k JSONCodec input
c input
_ Maybe Text
mdoc -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"OptionalKeyWithDefaultCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" _ " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mdoc) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 JSONCodec input
c
OptionalKeyWithOmittedDefaultCodec Text
k JSONCodec input
c input
_ Maybe Text
mdoc -> (\ShowS
s -> Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"OptionalKeyWithOmittedDefaultCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Text
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" _ " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe Text
mdoc) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 JSONCodec input
c
PureCodec output
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure 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 forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ApCodec " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
s2) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall context input output.
Int -> Codec context input output -> State (Set Text) ShowS
go Int
11 ObjectCodec input (output -> output)
oc1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec oldOutput -> newOutput
f 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 = 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 = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec 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
(.=) = forall a b c. (a -> b -> c) -> b -> a -> c
flip 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 = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec (forall a b. b -> Either a b
Right 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 = 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 = 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 = forall output input. output -> ObjectCodec input output
pureCodec
<*> :: forall a 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 =
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec forall {a}. Either () a -> Maybe a
f forall {b}. Maybe b -> Either () b
g
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall context input1 output1 input2 output2.
Codec context input1 output1
-> Codec context input2 output2
-> Codec context (Either input1 input2) (Either output1 output2)
possiblyJointEitherCodec JSONCodec ()
nullCodec
where
f :: Either () a -> Maybe a
f = \case
Left () -> forall a. Maybe a
Nothing
Right a
r -> forall a. a -> Maybe a
Just a
r
g :: Maybe b -> Either () b
g = \case
Maybe b
Nothing -> forall a b. a -> Either a b
Left ()
Just b
r -> 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 = 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 = forall context input output input2 output2.
Union
-> Codec context input output
-> Codec context input2 output2
-> Codec context (Either input input2) (Either output output2)
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 = forall context input output input2 output2.
Union
-> Codec context input output
-> Codec context input2 output2
-> Codec context (Either input input2) (Either output output2)
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 = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec (forall a b. a -> b -> a
const ()) (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 = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec b -> a
f 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 = 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 -> 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' forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> oldOutput -> Either String newOutput
f) (oldInput -> oldInput
g' forall b c a. (b -> c) -> (a -> b) -> a -> c
. newInput -> oldInput
g) Codec context oldInput oldOutput
c
Codec context oldInput oldOutput
c -> 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 = forall input output.
Maybe Text
-> ValueCodec input output
-> ValueCodec (Vector input) (Vector output)
ArrayOfCodec forall a. Maybe a
Nothing
listCodec :: ValueCodec input output -> ValueCodec [input] [output]
listCodec :: forall input output.
ValueCodec input output -> ValueCodec [input] [output]
listCodec = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec forall a. Vector a -> [a]
V.toList forall a. [a] -> Vector a
V.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall input output.
ValueCodec input output
-> ValueCodec (Vector input) (Vector output)
vectorCodec
nonEmptyCodec :: ValueCodec input output -> ValueCodec (NonEmpty input) (NonEmpty output)
nonEmptyCodec :: forall input output.
ValueCodec input output
-> ValueCodec (NonEmpty input) (NonEmpty output)
nonEmptyCodec = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec forall {a}. [a] -> Either String (NonEmpty a)
parseNonEmptyList forall a. NonEmpty a -> [a]
NE.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall input output.
ValueCodec input output -> ValueCodec [input] [output]
listCodec
where
parseNonEmptyList :: [a] -> Either String (NonEmpty a)
parseNonEmptyList [a]
l = case forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [a]
l of
Maybe (NonEmpty a)
Nothing -> forall a b. a -> Either a b
Left String
"Expected a nonempty list, but got an empty list."
Just NonEmpty a
ne -> 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 = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec forall {a}. Either a [a] -> [a]
f forall {a}. [a] -> Either a [a]
g forall a b. (a -> b) -> a -> b
$ 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 forall a b. (a -> b) -> a -> b
$ 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] -> forall a b. a -> Either a b
Left a
v
[a]
vs -> 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 = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec forall {a}. Either a (NonEmpty a) -> NonEmpty a
f forall {a}. NonEmpty a -> Either a (NonEmpty a)
g forall a b. (a -> b) -> a -> b
$ 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 forall a b. (a -> b) -> a -> b
$ 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 forall a. a -> [a] -> NonEmpty a
:| []
Right NonEmpty a
vs -> NonEmpty a
vs
g :: NonEmpty a -> Either a (NonEmpty a)
g = \case
a
v :| [] -> forall a b. a -> Either a b
Left a
v
NonEmpty a
vs -> 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 = forall input output.
Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec input output
RequiredKeyCodec Text
key ValueCodec input output
c (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 = forall input output.
Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec input output
RequiredKeyCodec Text
key ValueCodec input output
c 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 = forall input output.
Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec (Maybe input) (Maybe output)
OptionalKeyCodec Text
key ValueCodec input output
c (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 = forall input output.
Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec (Maybe input) (Maybe output)
OptionalKeyCodec Text
key ValueCodec input output
c 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 = forall value.
Text
-> ValueCodec value value
-> value
-> Maybe Text
-> ObjectCodec value value
OptionalKeyWithDefaultCodec Text
key JSONCodec output
c output
defaultValue (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 = forall value.
Text
-> ValueCodec value value
-> value
-> Maybe Text
-> ObjectCodec value value
OptionalKeyWithDefaultCodec Text
key JSONCodec output
c output
defaultValue forall a. Maybe a
Nothing
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 = forall value.
Eq value =>
Text
-> ValueCodec value value
-> value
-> Maybe Text
-> ObjectCodec value value
OptionalKeyWithOmittedDefaultCodec Text
key JSONCodec output
c output
defaultValue (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 = forall value.
Eq value =>
Text
-> ValueCodec value value
-> value
-> Maybe Text
-> ObjectCodec value value
OptionalKeyWithOmittedDefaultCodec Text
key JSONCodec output
c output
defaultValue 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 = 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 forall a b. (a -> b) -> a -> b
$ forall output.
Eq output =>
Text
-> JSONCodec output -> output -> Text -> ObjectCodec output output
optionalFieldWithOmittedDefaultWith Text
key (forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec JSONCodec output
c) (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 forall a. Eq a => a -> a -> Bool
== output
defaultValue then forall a. Maybe a
Nothing else 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 = 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 forall a b. (a -> b) -> a -> b
$ forall output.
Eq output =>
Text -> JSONCodec output -> output -> ObjectCodec output output
optionalFieldWithOmittedDefaultWith' Text
key (forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec JSONCodec output
c) (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 forall a. Eq a => a -> a -> Bool
== output
defaultValue then forall a. Maybe a
Nothing else 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 = forall input output.
ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output)
orNullHelper forall a b. (a -> b) -> a -> b
$ forall input output.
Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec (Maybe input) (Maybe output)
OptionalKeyCodec Text
key (forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec ValueCodec input output
c) (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 = forall input output.
ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output))
-> ObjectCodec (Maybe input) (Maybe output)
orNullHelper forall a b. (a -> b) -> a -> b
$ forall input output.
Text
-> ValueCodec input output
-> Maybe Text
-> ObjectCodec (Maybe input) (Maybe output)
OptionalKeyCodec Text
key (forall input output.
ValueCodec input output -> ValueCodec (Maybe input) (Maybe output)
maybeCodec ValueCodec input output
c) forall a. Maybe a
Nothing
(<?>) ::
ValueCodec input output ->
Text ->
ValueCodec input output
<?> :: forall input output.
ValueCodec input output -> Text -> ValueCodec input output
(<?>) = forall a b c. (a -> b -> c) -> b -> a -> c
flip 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 = 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 = forall k v.
(Eq k, Hashable k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v -> JSONCodec (HashMap k v)
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 = forall k v.
(Ord k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v -> JSONCodec (Map k v)
MapCodec
#if MIN_VERSION_aeson(2,0,0)
keyMapCodec ::
JSONCodec v ->
JSONCodec (KeyMap v)
keyMapCodec :: forall v. JSONCodec v -> JSONCodec (KeyMap v)
keyMapCodec = case forall v. Maybe (Coercion (Map Key v) (KeyMap v))
KM.coercionToMap of
Just Coercion (Map Key Any) (KeyMap Any)
_ -> forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec forall v. Map Key v -> KeyMap v
KM.fromMap forall v. KeyMap v -> Map Key v
KM.toMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v.
(Ord k, FromJSONKey k, ToJSONKey k) =>
JSONCodec v -> JSONCodec (Map k v)
mapCodec
Maybe (Coercion (Map Key Any) (KeyMap Any))
Nothing -> forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec forall v. HashMap Key v -> KeyMap v
KM.fromHashMap forall v. KeyMap v -> HashMap Key v
KM.toHashMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
ValueCodec
nullCodec :: JSONCodec ()
nullCodec :: JSONCodec ()
nullCodec = JSONCodec ()
NullCodec
boolCodec :: JSONCodec Bool
boolCodec :: JSONCodec Bool
boolCodec = Maybe Text -> JSONCodec Bool
BoolCodec forall a. Maybe a
Nothing
textCodec :: JSONCodec Text
textCodec :: JSONCodec Text
textCodec = Maybe Text -> JSONCodec Text
StringCodec forall a. Maybe a
Nothing
stringCodec :: JSONCodec String
stringCodec :: JSONCodec String
stringCodec = 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 -> Maybe NumberBounds -> JSONCodec Scientific
NumberCodec forall a. Maybe a
Nothing forall a. Maybe a
Nothing
scientificWithBoundsCodec :: NumberBounds -> JSONCodec Scientific
scientificWithBoundsCodec :: NumberBounds -> JSONCodec Scientific
scientificWithBoundsCodec NumberBounds
bounds = Maybe Text -> Maybe NumberBounds -> JSONCodec Scientific
NumberCodec forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just NumberBounds
bounds)
object :: Text -> ObjectCodec input output -> ValueCodec input output
object :: forall input output.
Text -> ObjectCodec input output -> ValueCodec input output
object Text
name = forall input output.
Maybe Text -> ObjectCodec input output -> ValueCodec input output
ObjectOfCodec (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 =
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec forall {b}.
(Integral b, Bounded b) =>
Scientific -> Either String b
go forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ NumberBounds -> JSONCodec Scientific
scientificWithBoundsCodec (forall i. (Integral i, Bounded i) => NumberBounds
boundedIntegralNumberBounds @i)
where
go :: Scientific -> Either String b
go Scientific
s = case forall i. (Integral i, Bounded i) => Scientific -> Maybe i
Scientific.toBoundedInteger Scientific
s of
Maybe b
Nothing -> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ String
"Number did not fit into bounded integer: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Scientific
s
Just b
i -> forall a b. b -> Either a b
Right b
i
boundedIntegralNumberBounds :: forall i. (Integral i, Bounded i) => NumberBounds
boundedIntegralNumberBounds :: forall i. (Integral i, Bounded i) => NumberBounds
boundedIntegralNumberBounds =
NumberBounds
{ numberBoundsLower :: Scientific
numberBoundsLower = forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Bounded a => a
minBound :: i),
numberBoundsUpper :: Scientific
numberBoundsUpper = forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Bounded a => a
maxBound :: i)
}
integerCodec :: JSONCodec Integer
integerCodec :: JSONCodec Integer
integerCodec =
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 forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$
NumberBounds -> JSONCodec Scientific
scientificWithBoundsCodec
( NumberBounds
{ numberBoundsLower :: Scientific
numberBoundsLower = Integer -> Int -> Scientific
scientific (-Integer
1) Int
1024,
numberBoundsUpper :: Scientific
numberBoundsUpper = Integer -> Int -> Scientific
scientific Integer
1 Int
1024
}
)
where
go :: Scientific -> Either String Integer
go Scientific
s = case forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
Scientific.floatingOrInteger Scientific
s :: Either Float Integer of
Right Integer
i -> forall a b. b -> Either a b
Right Integer
i
Left Float
_ -> forall a b. a -> Either a b
Left (String
"Number is not an integer: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Scientific
s)
unsafeUnboundedIntegerCodec :: JSONCodec Integer
unsafeUnboundedIntegerCodec :: JSONCodec Integer
unsafeUnboundedIntegerCodec =
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 forall a b. (Integral a, Num b) => a -> b
fromIntegral JSONCodec Scientific
scientificCodec
where
go :: Scientific -> Either String Integer
go Scientific
s = case forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
Scientific.floatingOrInteger Scientific
s :: Either Float Integer of
Right Integer
i -> forall a b. b -> Either a b
Right Integer
i
Left Float
_ -> forall a b. a -> Either a b
Left (String
"Number is not an integer: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Scientific
s)
naturalCodec :: JSONCodec Natural
naturalCodec :: JSONCodec Natural
naturalCodec =
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 forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$
NumberBounds -> JSONCodec Scientific
scientificWithBoundsCodec
( NumberBounds
{ numberBoundsLower :: Scientific
numberBoundsLower = Integer -> Int -> Scientific
scientific Integer
0 Int
0,
numberBoundsUpper :: Scientific
numberBoundsUpper = Integer -> Int -> Scientific
scientific Integer
1 Int
1024
}
)
where
go :: Scientific -> Either String Natural
go Scientific
s = case forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
Scientific.floatingOrInteger Scientific
s :: Either Float Natural of
Right Natural
i -> forall a b. b -> Either a b
Right Natural
i
Left Float
_ -> forall a b. a -> Either a b
Left (String
"Number is not an integer: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Scientific
s)
unsafeUnboundedNaturalCodec :: JSONCodec Natural
unsafeUnboundedNaturalCodec :: JSONCodec Natural
unsafeUnboundedNaturalCodec =
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 forall a b. (Integral a, Num b) => a -> b
fromIntegral JSONCodec Scientific
scientificCodec
where
go :: Scientific -> Either String Natural
go Scientific
s = case forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
Scientific.floatingOrInteger Scientific
s :: Either Float Natural of
Right Natural
i -> forall a b. b -> Either a b
Right Natural
i
Left Float
_ -> forall a b. a -> Either a b
Left (String
"Number is not an integer: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Scientific
s)
literalTextCodec :: Text -> JSONCodec Text
literalTextCodec :: Text -> JSONCodec Text
literalTextCodec Text
text = forall value.
(Show value, Eq value) =>
value -> JSONCodec value -> JSONCodec value
EqCodec Text
text JSONCodec Text
textCodec
literalTextValueCodec :: value -> Text -> JSONCodec value
literalTextValueCodec :: forall value. value -> Text -> JSONCodec value
literalTextValueCodec value
value Text
text = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec (forall a b. a -> b -> a
const value
value) (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 = 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 = 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 =
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. a -> a
id forall a. a -> a
id) newInput -> Either input input'
renderingChooser forall a b. (a -> b) -> a -> b
$
forall context input output input2 output2.
Union
-> Codec context input output
-> Codec context input2 output2
-> Codec context (Either input input2) (Either output output2)
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 = 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 = 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) -> 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) forall a b. (a -> b) -> a -> b
$ \input
i -> case input -> Maybe input
m input
i of
Just input
j -> forall a b. a -> Either a b
Left input
j
Maybe input
Nothing -> 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 = forall context input output.
NonEmpty (Codec context input output) -> Codec context input output
go (Codec context input output
c 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 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' -> 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' (forall context input output.
NonEmpty (Codec context input output) -> Codec context input output
go NonEmpty (Codec context input output)
ne') 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 = 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 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 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 -> 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) forall a b. (a -> b) -> a -> b
$ \enum
i ->
if enum
e forall a. Eq a => a -> a -> Bool
== enum
i
then forall a b. a -> Either a b
Left enum
e
else 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 =
forall enum context.
Eq enum =>
NonEmpty (enum, Codec context enum enum) -> Codec context enum enum
enumCodec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NE.map
( \(constant
constant, Text
text) ->
( constant
constant,
forall value. value -> Text -> JSONCodec value
literalTextValueCodec constant
constant Text
text
)
)
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 =
let ls :: [enum]
ls = [forall a. Bounded a => a
minBound .. forall a. Bounded a => a
maxBound]
in case forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [enum]
ls of
Maybe (NonEmpty enum)
Nothing -> forall a. HasCallStack => String -> a
error String
"0 enum values ?!"
Just NonEmpty enum
ne -> forall constant.
Eq constant =>
NonEmpty (constant, Text) -> JSONCodec constant
stringConstCodec (forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NE.map (\enum
v -> (enum
v, String -> Text
T.pack (forall a. Show a => a -> String
show enum
v))) NonEmpty enum
ne)
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 = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec forall input. Maybe (Maybe input) -> Maybe input
f 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 -> forall a. Maybe a
Nothing
Just Maybe input
Nothing -> forall a. Maybe a
Nothing
Just (Just input
a) -> 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 -> forall a. Maybe a
Nothing
Just output
a -> forall a. a -> Maybe a
Just (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 = 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 = forall oldOutput newOutput newInput oldInput context.
(oldOutput -> Either String newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
bimapCodec (forall a b. (a -> Parser b) -> a -> Either String b
JSON.parseEither forall a. FromJSON a => Value -> Parser a
JSON.parseJSON) forall a. ToJSON a => a -> Value
JSON.toJSON JSONCodec Value
valueCodec forall input output.
ValueCodec input output -> Text -> ValueCodec input output
<?> Text
doc