{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
module Waargonaut.Encode
(
Encoder
, Encoder'
, ObjEncoder
, ObjEncoder'
, encodeA
, encodePureA
, jsonEncoder
, objEncoder
, runPureEncoder
, runEncoder
, simpleEncodeWith
, simplePureEncodeWith
, simpleEncodeText
, simpleEncodeTextNoSpaces
, simpleEncodeByteString
, simpleEncodeByteStringNoSpaces
, simplePureEncodeText
, simplePureEncodeTextNoSpaces
, simplePureEncodeByteString
, simplePureEncodeByteStringNoSpaces
, int
, integral
, scientific
, bool
, string
, text
, null
, either
, maybe
, maybeOrNull
, traversable
, list
, nonempty
, mapToObj
, json
, prismE
, asJson
, mapLikeObj
, atKey
, atOptKey
, intAt
, textAt
, boolAt
, traversableAt
, listAt
, nonemptyAt
, encAt
, keyValuesAsObj
, onObj
, keyValueTupleFoldable
, extendObject
, extendMapLikeObject
, combineObjects
, int'
, integral'
, scientific'
, bool'
, string'
, text'
, null'
, either'
, maybe'
, maybeOrNull'
, traversable'
, nonempty'
, list'
, atKey'
, atOptKey'
, mapLikeObj'
, mapToObj'
, keyValuesAsObj'
, json'
, asJson'
, onObj'
, generaliseEncoder
) where
import Control.Applicative (Applicative (..), (<$>))
import Control.Category (id, (.))
import Control.Lens (AReview, At, Index,
IxValue, Prism', at,
cons, review, ( # ),
(?~), _Empty, _Wrapped)
import qualified Control.Lens as L
import Data.Foldable (Foldable, foldr, foldrM)
import Data.Function (const, flip, ($), (&))
import Data.Functor (Functor, fmap)
import Data.Functor.Contravariant ((>$<))
import Data.Functor.Contravariant.Divisible (divide)
import Data.Functor.Identity (Identity (..))
import Data.Traversable (Traversable, traverse)
import Prelude (Bool, Int, Integral,
Monad, String,
fromIntegral, fst)
import Data.Either (Either)
import qualified Data.Either as Either
import Data.List.NonEmpty (NonEmpty)
import Data.Maybe (Maybe)
import qualified Data.Maybe as Maybe
import Data.Scientific (Scientific)
import Data.Monoid (Monoid, mempty)
import Data.Semigroup (Semigroup)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.String (IsString)
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Builder as BB
import Data.Text (Text)
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.Builder as TB
import Waargonaut.Encode.Types (Encoder, Encoder',
ObjEncoder, ObjEncoder',
finaliseEncoding,
generaliseEncoder,
initialEncoding,
jsonEncoder, objEncoder,
runEncoder,
runPureEncoder)
import Waargonaut.Types (AsJType (..),
JAssoc (..), JObject,
Json, MapLikeObj (..),
WS, stringToJString,
toMapLikeObj,
_JNumberInt,
_JNumberScientific,
_JStringText)
import Waargonaut.Encode.Builder (textBuilder, bsBuilder,
waargonautBuilder)
import Waargonaut.Encode.Builder.Types (Builder)
import Waargonaut.Encode.Builder.Whitespace (wsBuilder, wsRemover)
encodeA :: (a -> f Json) -> Encoder f a
encodeA :: (a -> f Json) -> Encoder f a
encodeA = (a -> f Json) -> Encoder f a
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
jsonEncoder
encodePureA :: (a -> Json) -> Encoder' a
encodePureA :: (a -> Json) -> Encoder' a
encodePureA a -> Json
f = (a -> Identity Json) -> Encoder' a
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
encodeA (Json -> Identity Json
forall a. a -> Identity a
Identity (Json -> Identity Json) -> (a -> Json) -> a -> Identity Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> Json
f)
simpleEncodeWith
:: ( Applicative f
, Monoid b
, IsString t
)
=> Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder f a
-> a
-> f out
simpleEncodeWith :: Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder f a
-> a
-> f out
simpleEncodeWith Builder t b
builder b -> out
buildRunner Builder t b -> WS -> b
wsB Encoder f a
enc =
(Json -> out) -> f Json -> f out
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (b -> out
buildRunner (b -> out) -> (Json -> b) -> Json -> out
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Builder t b -> WS -> b) -> Builder t b -> Json -> b
forall t b.
(IsString t, Monoid b) =>
(Builder t b -> WS -> b) -> Builder t b -> Json -> b
waargonautBuilder Builder t b -> WS -> b
wsB Builder t b
builder) (f Json -> f out) -> (a -> f Json) -> a -> f out
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Encoder f a -> a -> f Json
forall (f :: * -> *) i a.
Functor f =>
EncoderFns i f a -> a -> f Json
runEncoder Encoder f a
enc
simpleEncodeText
:: Applicative f
=> Encoder f a
-> a
-> f LT.Text
simpleEncodeText :: Encoder f a -> a -> f Text
simpleEncodeText =
Builder Text Builder
-> (Builder -> Text)
-> (Builder Text Builder -> WS -> Builder)
-> Encoder f a
-> a
-> f Text
forall (f :: * -> *) b t out a.
(Applicative f, Monoid b, IsString t) =>
Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder f a
-> a
-> f out
simpleEncodeWith Builder Text Builder
textBuilder Builder -> Text
TB.toLazyText Builder Text Builder -> WS -> Builder
forall b t. Monoid b => Builder t b -> WS -> b
wsBuilder
simpleEncodeTextNoSpaces
:: Applicative f
=> Encoder f a
-> a
-> f LT.Text
simpleEncodeTextNoSpaces :: Encoder f a -> a -> f Text
simpleEncodeTextNoSpaces =
Builder Text Builder
-> (Builder -> Text)
-> (Builder Text Builder -> WS -> Builder)
-> Encoder f a
-> a
-> f Text
forall (f :: * -> *) b t out a.
(Applicative f, Monoid b, IsString t) =>
Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder f a
-> a
-> f out
simpleEncodeWith Builder Text Builder
textBuilder Builder -> Text
TB.toLazyText Builder Text Builder -> WS -> Builder
forall b t. Monoid b => Builder t b -> WS -> b
wsRemover
simpleEncodeByteString
:: Applicative f
=> Encoder f a
-> a
-> f BL.ByteString
simpleEncodeByteString :: Encoder f a -> a -> f ByteString
simpleEncodeByteString =
Builder ByteString Builder
-> (Builder -> ByteString)
-> (Builder ByteString Builder -> WS -> Builder)
-> Encoder f a
-> a
-> f ByteString
forall (f :: * -> *) b t out a.
(Applicative f, Monoid b, IsString t) =>
Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder f a
-> a
-> f out
simpleEncodeWith Builder ByteString Builder
bsBuilder Builder -> ByteString
BB.toLazyByteString Builder ByteString Builder -> WS -> Builder
forall b t. Monoid b => Builder t b -> WS -> b
wsBuilder
simpleEncodeByteStringNoSpaces
:: Applicative f
=> Encoder f a
-> a
-> f BL.ByteString
simpleEncodeByteStringNoSpaces :: Encoder f a -> a -> f ByteString
simpleEncodeByteStringNoSpaces =
Builder ByteString Builder
-> (Builder -> ByteString)
-> (Builder ByteString Builder -> WS -> Builder)
-> Encoder f a
-> a
-> f ByteString
forall (f :: * -> *) b t out a.
(Applicative f, Monoid b, IsString t) =>
Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder f a
-> a
-> f out
simpleEncodeWith Builder ByteString Builder
bsBuilder Builder -> ByteString
BB.toLazyByteString Builder ByteString Builder -> WS -> Builder
forall b t. Monoid b => Builder t b -> WS -> b
wsRemover
simplePureEncodeWith
:: ( Monoid b
, IsString t
)
=> Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder Identity a
-> a
-> out
simplePureEncodeWith :: Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder Identity a
-> a
-> out
simplePureEncodeWith Builder t b
builder b -> out
buildRunner Builder t b -> WS -> b
wsB Encoder Identity a
enc =
Identity out -> out
forall a. Identity a -> a
runIdentity (Identity out -> out) -> (a -> Identity out) -> a -> out
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder Identity a
-> a
-> Identity out
forall (f :: * -> *) b t out a.
(Applicative f, Monoid b, IsString t) =>
Builder t b
-> (b -> out)
-> (Builder t b -> WS -> b)
-> Encoder f a
-> a
-> f out
simpleEncodeWith Builder t b
builder b -> out
buildRunner Builder t b -> WS -> b
wsB Encoder Identity a
enc
simplePureEncodeText
:: Encoder Identity a
-> a
-> LT.Text
simplePureEncodeText :: Encoder Identity a -> a -> Text
simplePureEncodeText Encoder Identity a
enc =
Identity Text -> Text
forall a. Identity a -> a
runIdentity (Identity Text -> Text) -> (a -> Identity Text) -> a -> Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Encoder Identity a -> a -> Identity Text
forall (f :: * -> *) a. Applicative f => Encoder f a -> a -> f Text
simpleEncodeText Encoder Identity a
enc
simplePureEncodeTextNoSpaces
:: Encoder Identity a
-> a
-> LT.Text
simplePureEncodeTextNoSpaces :: Encoder Identity a -> a -> Text
simplePureEncodeTextNoSpaces Encoder Identity a
enc =
Identity Text -> Text
forall a. Identity a -> a
runIdentity (Identity Text -> Text) -> (a -> Identity Text) -> a -> Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Encoder Identity a -> a -> Identity Text
forall (f :: * -> *) a. Applicative f => Encoder f a -> a -> f Text
simpleEncodeTextNoSpaces Encoder Identity a
enc
simplePureEncodeByteString
:: Encoder Identity a
-> a
-> BL.ByteString
simplePureEncodeByteString :: Encoder Identity a -> a -> ByteString
simplePureEncodeByteString Encoder Identity a
enc =
Identity ByteString -> ByteString
forall a. Identity a -> a
runIdentity (Identity ByteString -> ByteString)
-> (a -> Identity ByteString) -> a -> ByteString
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Encoder Identity a -> a -> Identity ByteString
forall (f :: * -> *) a.
Applicative f =>
Encoder f a -> a -> f ByteString
simpleEncodeByteString Encoder Identity a
enc
simplePureEncodeByteStringNoSpaces
:: Encoder Identity a
-> a
-> BL.ByteString
simplePureEncodeByteStringNoSpaces :: Encoder Identity a -> a -> ByteString
simplePureEncodeByteStringNoSpaces Encoder Identity a
enc =
Identity ByteString -> ByteString
forall a. Identity a -> a
runIdentity (Identity ByteString -> ByteString)
-> (a -> Identity ByteString) -> a -> ByteString
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Encoder Identity a -> a -> Identity ByteString
forall (f :: * -> *) a.
Applicative f =>
Encoder f a -> a -> f ByteString
simpleEncodeByteStringNoSpaces Encoder Identity a
enc
asJson :: Applicative f => Encoder f a -> a -> f Json
asJson :: Encoder f a -> a -> f Json
asJson = Encoder f a -> a -> f Json
forall (f :: * -> *) i a.
Functor f =>
EncoderFns i f a -> a -> f Json
runEncoder
{-# INLINE asJson #-}
asJson' :: Encoder Identity a -> a -> Json
asJson' :: Encoder Identity a -> a -> Json
asJson' Encoder Identity a
e = Identity Json -> Json
forall a. Identity a -> a
runIdentity (Identity Json -> Json) -> (a -> Identity Json) -> a -> Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Encoder Identity a -> a -> Identity Json
forall (f :: * -> *) i a.
Functor f =>
EncoderFns i f a -> a -> f Json
runEncoder Encoder Identity a
e
{-# INLINE asJson' #-}
json :: Applicative f => Encoder f Json
json :: Encoder f Json
json = (Json -> f Json) -> Encoder f Json
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
encodeA Json -> f Json
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE json #-}
encToJsonNoSpaces
:: ( Monoid t
, Applicative f
)
=> AReview Json (b, t)
-> (a -> b)
-> Encoder f a
encToJsonNoSpaces :: AReview Json (b, t) -> (a -> b) -> Encoder f a
encToJsonNoSpaces AReview Json (b, t)
c a -> b
f =
(a -> f Json) -> Encoder f a
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
encodeA (Json -> f Json
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Json -> f Json) -> (a -> Json) -> a -> f Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. AReview Json (b, t) -> (b, t) -> Json
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview Json (b, t)
c ((b, t) -> Json) -> (a -> (b, t)) -> a -> Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (,t
forall a. Monoid a => a
mempty) (b -> (b, t)) -> (a -> b) -> a -> (b, t)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> b
f)
prismE
:: Prism' a b
-> Encoder f a
-> Encoder f b
prismE :: Prism' a b -> Encoder f a -> Encoder f b
prismE Prism' a b
p Encoder f a
e =
AReview a b -> b -> a
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
L.review AReview a b
Prism' a b
p (b -> a) -> Encoder f a -> Encoder f b
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
>$< Encoder f a
e
{-# INLINE prismE #-}
int :: Applicative f => Encoder f Int
int :: Encoder f Int
int = AReview Json (JNumber, WS) -> (Int -> JNumber) -> Encoder f Int
forall t (f :: * -> *) b a.
(Monoid t, Applicative f) =>
AReview Json (b, t) -> (a -> b) -> Encoder f a
encToJsonNoSpaces AReview Json (JNumber, WS)
forall r ws a. AsJType r ws a => Prism' r (JNumber, ws)
_JNum (Tagged Int (Identity Int) -> Tagged JNumber (Identity JNumber)
Prism' JNumber Int
_JNumberInt (Tagged Int (Identity Int) -> Tagged JNumber (Identity JNumber))
-> Int -> JNumber
forall t b. AReview t b -> b -> t
#)
scientific :: Applicative f => Encoder f Scientific
scientific :: Encoder f Scientific
scientific = AReview Json (JNumber, WS)
-> (Scientific -> JNumber) -> Encoder f Scientific
forall t (f :: * -> *) b a.
(Monoid t, Applicative f) =>
AReview Json (b, t) -> (a -> b) -> Encoder f a
encToJsonNoSpaces AReview Json (JNumber, WS)
forall r ws a. AsJType r ws a => Prism' r (JNumber, ws)
_JNum (Tagged Scientific (Identity Scientific)
-> Tagged JNumber (Identity JNumber)
Prism' JNumber Scientific
_JNumberScientific (Tagged Scientific (Identity Scientific)
-> Tagged JNumber (Identity JNumber))
-> Scientific -> JNumber
forall t b. AReview t b -> b -> t
#)
integral :: (Applicative f, Integral n) => Encoder f n
integral :: Encoder f n
integral = AReview Json (JNumber, WS) -> (n -> JNumber) -> Encoder f n
forall t (f :: * -> *) b a.
(Monoid t, Applicative f) =>
AReview Json (b, t) -> (a -> b) -> Encoder f a
encToJsonNoSpaces AReview Json (JNumber, WS)
forall r ws a. AsJType r ws a => Prism' r (JNumber, ws)
_JNum ((Tagged Scientific (Identity Scientific)
-> Tagged JNumber (Identity JNumber))
-> Scientific -> JNumber
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Tagged Scientific (Identity Scientific)
-> Tagged JNumber (Identity JNumber)
Prism' JNumber Scientific
_JNumberScientific (Scientific -> JNumber) -> (n -> Scientific) -> n -> JNumber
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. n -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral)
bool :: Applicative f => Encoder f Bool
bool :: Encoder f Bool
bool = AReview Json (Bool, WS) -> (Bool -> Bool) -> Encoder f Bool
forall t (f :: * -> *) b a.
(Monoid t, Applicative f) =>
AReview Json (b, t) -> (a -> b) -> Encoder f a
encToJsonNoSpaces AReview Json (Bool, WS)
forall r ws a. AsJType r ws a => Prism' r (Bool, ws)
_JBool Bool -> Bool
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
string :: Applicative f => Encoder f String
string :: Encoder f String
string = AReview Json (JString, WS)
-> (String -> JString) -> Encoder f String
forall t (f :: * -> *) b a.
(Monoid t, Applicative f) =>
AReview Json (b, t) -> (a -> b) -> Encoder f a
encToJsonNoSpaces AReview Json (JString, WS)
forall r ws a. AsJType r ws a => Prism' r (JString, ws)
_JStr String -> JString
stringToJString
text :: Applicative f => Encoder f Text
text :: Encoder f Text
text = AReview Json (JString, WS) -> (Text -> JString) -> Encoder f Text
forall t (f :: * -> *) b a.
(Monoid t, Applicative f) =>
AReview Json (b, t) -> (a -> b) -> Encoder f a
encToJsonNoSpaces AReview Json (JString, WS)
forall r ws a. AsJType r ws a => Prism' r (JString, ws)
_JStr (Tagged Text (Identity Text) -> Tagged JString (Identity JString)
forall (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Applicative f) =>
p Text (f Text) -> p JString (f JString)
_JStringText (Tagged Text (Identity Text) -> Tagged JString (Identity JString))
-> Text -> JString
forall t b. AReview t b -> b -> t
#)
null :: Applicative f => Encoder f ()
null :: Encoder f ()
null = (() -> f Json) -> Encoder f ()
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
encodeA ((() -> f Json) -> Encoder f ()) -> (() -> f Json) -> Encoder f ()
forall a b. (a -> b) -> a -> b
$ f Json -> () -> f Json
forall a b. a -> b -> a
const (Json -> f Json
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Json -> f Json) -> Json -> f Json
forall a b. (a -> b) -> a -> b
$ Tagged WS (Identity WS) -> Tagged Json (Identity Json)
forall r ws a. AsJType r ws a => Prism' r ws
_JNull (Tagged WS (Identity WS) -> Tagged Json (Identity Json))
-> WS -> Json
forall t b. AReview t b -> b -> t
# WS
forall a. Monoid a => a
mempty)
maybe
:: Functor f
=> Encoder f ()
-> Encoder f a
-> Encoder f (Maybe a)
maybe :: Encoder f () -> Encoder f a -> Encoder f (Maybe a)
maybe Encoder f ()
encN = (Maybe a -> f Json) -> Encoder f (Maybe a)
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
encodeA
((Maybe a -> f Json) -> Encoder f (Maybe a))
-> (Encoder f a -> Maybe a -> f Json)
-> Encoder f a
-> Encoder f (Maybe a)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. f Json -> (a -> f Json) -> Maybe a -> f Json
forall b a. b -> (a -> b) -> Maybe a -> b
Maybe.maybe (Encoder f () -> () -> f Json
forall (f :: * -> *) i a.
Functor f =>
EncoderFns i f a -> a -> f Json
runEncoder Encoder f ()
encN ())
((a -> f Json) -> Maybe a -> f Json)
-> (Encoder f a -> a -> f Json) -> Encoder f a -> Maybe a -> f Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Encoder f a -> a -> f Json
forall (f :: * -> *) i a.
Functor f =>
EncoderFns i f a -> a -> f Json
runEncoder
maybeOrNull
:: Applicative f
=> Encoder f a
-> Encoder f (Maybe a)
maybeOrNull :: Encoder f a -> Encoder f (Maybe a)
maybeOrNull =
Encoder f () -> Encoder f a -> Encoder f (Maybe a)
forall (f :: * -> *) a.
Functor f =>
Encoder f () -> Encoder f a -> Encoder f (Maybe a)
maybe Encoder f ()
forall (f :: * -> *). Applicative f => Encoder f ()
null
either
:: Functor f
=> Encoder f a
-> Encoder f b
-> Encoder f (Either a b)
either :: Encoder f a -> Encoder f b -> Encoder f (Either a b)
either Encoder f a
eA = (Either a b -> f Json) -> Encoder f (Either a b)
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
encodeA
((Either a b -> f Json) -> Encoder f (Either a b))
-> (Encoder f b -> Either a b -> f Json)
-> Encoder f b
-> Encoder f (Either a b)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (a -> f Json) -> (b -> f Json) -> Either a b -> f Json
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
Either.either (Encoder f a -> a -> f Json
forall (f :: * -> *) i a.
Functor f =>
EncoderFns i f a -> a -> f Json
runEncoder Encoder f a
eA)
((b -> f Json) -> Either a b -> f Json)
-> (Encoder f b -> b -> f Json)
-> Encoder f b
-> Either a b
-> f Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Encoder f b -> b -> f Json
forall (f :: * -> *) i a.
Functor f =>
EncoderFns i f a -> a -> f Json
runEncoder
traversable
:: ( Applicative f
, Traversable t
)
=> Encoder f a
-> Encoder f (t a)
traversable :: Encoder f a -> Encoder f (t a)
traversable = (t Json -> Json) -> Encoder f a -> Encoder f (t a)
forall (f :: * -> *) (t :: * -> *) a.
(Applicative f, Traversable t) =>
(t Json -> Json) -> Encoder f a -> Encoder f (t a)
encodeWithInner
(\t Json
xs -> Tagged (JArray WS Json, WS) (Identity (JArray WS Json, WS))
-> Tagged Json (Identity Json)
forall r ws a. AsJType r ws a => Prism' r (JArray ws a, ws)
_JArr (Tagged (JArray WS Json, WS) (Identity (JArray WS Json, WS))
-> Tagged Json (Identity Json))
-> (JArray WS Json, WS) -> Json
forall t b. AReview t b -> b -> t
# (Tagged (CommaSeparated WS Json) (Identity (CommaSeparated WS Json))
-> Tagged (JArray WS Json) (Identity (JArray WS Json))
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (Tagged
(CommaSeparated WS Json) (Identity (CommaSeparated WS Json))
-> Tagged (JArray WS Json) (Identity (JArray WS Json)))
-> CommaSeparated WS Json -> JArray WS Json
forall t b. AReview t b -> b -> t
# (Json -> CommaSeparated WS Json -> CommaSeparated WS Json)
-> CommaSeparated WS Json -> t Json -> CommaSeparated WS Json
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Json -> CommaSeparated WS Json -> CommaSeparated WS Json
forall s a. Cons s s a a => a -> s -> s
cons CommaSeparated WS Json
forall a. Monoid a => a
mempty t Json
xs, WS
forall a. Monoid a => a
mempty))
mapToObj
:: Applicative f
=> Encoder f a
-> (k -> Text)
-> Encoder f (Map k a)
mapToObj :: Encoder f a -> (k -> Text) -> Encoder f (Map k a)
mapToObj Encoder f a
encodeVal k -> Text
kToText =
let
mapToCS :: Map k Json -> MapLikeObj WS Json
mapToCS = (k -> Json -> MapLikeObj WS Json -> MapLikeObj WS Json)
-> MapLikeObj WS Json -> Map k Json -> MapLikeObj WS Json
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey (\k
k Json
v -> Index (MapLikeObj WS Json)
-> Lens'
(MapLikeObj WS Json) (Maybe (IxValue (MapLikeObj WS Json)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at (k -> Text
kToText k
k) ((Maybe Json -> Identity (Maybe Json))
-> MapLikeObj WS Json -> Identity (MapLikeObj WS Json))
-> Json -> MapLikeObj WS Json -> MapLikeObj WS Json
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Json
v) (Tagged () (Identity ())
-> Tagged (MapLikeObj WS Json) (Identity (MapLikeObj WS Json))
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ())
-> Tagged (MapLikeObj WS Json) (Identity (MapLikeObj WS Json)))
-> () -> MapLikeObj WS Json
forall t b. AReview t b -> b -> t
# ())
in
(Map k Json -> Json) -> Encoder f a -> Encoder f (Map k a)
forall (f :: * -> *) (t :: * -> *) a.
(Applicative f, Traversable t) =>
(t Json -> Json) -> Encoder f a -> Encoder f (t a)
encodeWithInner (\Map k Json
xs -> Tagged (JObject WS Json, WS) (Identity (JObject WS Json, WS))
-> Tagged Json (Identity Json)
forall r ws a. AsJType r ws a => Prism' r (JObject ws a, ws)
_JObj (Tagged (JObject WS Json, WS) (Identity (JObject WS Json, WS))
-> Tagged Json (Identity Json))
-> (JObject WS Json, WS) -> Json
forall t b. AReview t b -> b -> t
# (MapLikeObj WS Json -> JObject WS Json
forall ws a. MapLikeObj ws a -> JObject ws a
fromMapLikeObj (MapLikeObj WS Json -> JObject WS Json)
-> MapLikeObj WS Json -> JObject WS Json
forall a b. (a -> b) -> a -> b
$ Map k Json -> MapLikeObj WS Json
mapToCS Map k Json
xs, WS
forall a. Monoid a => a
mempty)) Encoder f a
encodeVal
nonempty
:: Applicative f
=> Encoder f a
-> Encoder f (NonEmpty a)
nonempty :: Encoder f a -> Encoder f (NonEmpty a)
nonempty =
Encoder f a -> Encoder f (NonEmpty a)
forall (f :: * -> *) (t :: * -> *) a.
(Applicative f, Traversable t) =>
Encoder f a -> Encoder f (t a)
traversable
list
:: Applicative f
=> Encoder f a
-> Encoder f [a]
list :: Encoder f a -> Encoder f [a]
list =
Encoder f a -> Encoder f [a]
forall (f :: * -> *) (t :: * -> *) a.
(Applicative f, Traversable t) =>
Encoder f a -> Encoder f (t a)
traversable
json' :: Encoder' Json
json' :: Encoder' Json
json' = Encoder' Json
forall (f :: * -> *). Applicative f => Encoder f Json
json
int' :: Encoder' Int
int' :: Encoder' Int
int' = Encoder' Int
forall (f :: * -> *). Applicative f => Encoder f Int
int
integral' :: Integral n => Encoder' n
integral' :: Encoder' n
integral' = Encoder' n
forall (f :: * -> *) n. (Applicative f, Integral n) => Encoder f n
integral
scientific' :: Encoder' Scientific
scientific' :: Encoder' Scientific
scientific' = Encoder' Scientific
forall (f :: * -> *). Applicative f => Encoder f Scientific
scientific
bool' :: Encoder' Bool
bool' :: Encoder' Bool
bool' = Encoder' Bool
forall (f :: * -> *). Applicative f => Encoder f Bool
bool
string' :: Encoder' String
string' :: Encoder' String
string' = Encoder' String
forall (f :: * -> *). Applicative f => Encoder f String
string
text' :: Encoder' Text
text' :: Encoder' Text
text' = Encoder' Text
forall (f :: * -> *). Applicative f => Encoder f Text
text
null' :: Encoder' ()
null' :: Encoder' ()
null' = Encoder' ()
forall (f :: * -> *). Applicative f => Encoder f ()
null
maybe'
:: Encoder' ()
-> Encoder' a
-> Encoder' (Maybe a)
maybe' :: Encoder' () -> Encoder' a -> Encoder' (Maybe a)
maybe' =
Encoder' () -> Encoder' a -> Encoder' (Maybe a)
forall (f :: * -> *) a.
Functor f =>
Encoder f () -> Encoder f a -> Encoder f (Maybe a)
maybe
maybeOrNull'
:: Encoder' a
-> Encoder' (Maybe a)
maybeOrNull' :: Encoder' a -> Encoder' (Maybe a)
maybeOrNull' =
Encoder' a -> Encoder' (Maybe a)
forall (f :: * -> *) a.
Applicative f =>
Encoder f a -> Encoder f (Maybe a)
maybeOrNull
either'
:: Encoder' a
-> Encoder' b
-> Encoder' (Either a b)
either' :: Encoder' a -> Encoder' b -> Encoder' (Either a b)
either' =
Encoder' a -> Encoder' b -> Encoder' (Either a b)
forall (f :: * -> *) a b.
Functor f =>
Encoder f a -> Encoder f b -> Encoder f (Either a b)
either
nonempty'
:: Encoder' a
-> Encoder' (NonEmpty a)
nonempty' :: Encoder' a -> Encoder' (NonEmpty a)
nonempty' =
Encoder' a -> Encoder' (NonEmpty a)
forall (f :: * -> *) (t :: * -> *) a.
(Applicative f, Traversable t) =>
Encoder f a -> Encoder f (t a)
traversable
list'
:: Encoder' a
-> Encoder' [a]
list' :: Encoder' a -> Encoder' [a]
list' =
Encoder' a -> Encoder' [a]
forall (f :: * -> *) (t :: * -> *) a.
(Applicative f, Traversable t) =>
Encoder f a -> Encoder f (t a)
traversable
encodeWithInner
:: ( Applicative f
, Traversable t
)
=> (t Json -> Json)
-> Encoder f a
-> Encoder f (t a)
encodeWithInner :: (t Json -> Json) -> Encoder f a -> Encoder f (t a)
encodeWithInner t Json -> Json
f Encoder f a
g =
(t a -> f Json) -> Encoder f (t a)
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
jsonEncoder ((t a -> f Json) -> Encoder f (t a))
-> (t a -> f Json) -> Encoder f (t a)
forall a b. (a -> b) -> a -> b
$ (t Json -> Json) -> f (t Json) -> f Json
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap t Json -> Json
f (f (t Json) -> f Json) -> (t a -> f (t Json)) -> t a -> f Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (a -> f Json) -> t a -> f (t Json)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Encoder f a -> a -> f Json
forall (f :: * -> *) i a.
Functor f =>
EncoderFns i f a -> a -> f Json
runEncoder Encoder f a
g)
traversable'
:: Traversable t
=> Encoder' a
-> Encoder' (t a)
traversable' :: Encoder' a -> Encoder' (t a)
traversable' =
Encoder' a -> Encoder' (t a)
forall (f :: * -> *) (t :: * -> *) a.
(Applicative f, Traversable t) =>
Encoder f a -> Encoder f (t a)
traversable
mapToObj'
:: Encoder' a
-> (k -> Text)
-> Encoder' (Map k a)
mapToObj' :: Encoder' a -> (k -> Text) -> Encoder' (Map k a)
mapToObj' =
Encoder' a -> (k -> Text) -> Encoder' (Map k a)
forall (f :: * -> *) a k.
Applicative f =>
Encoder f a -> (k -> Text) -> Encoder f (Map k a)
mapToObj
atKey
:: ( At t
, IxValue t ~ Json
, Applicative f
)
=> Index t
-> Encoder f a
-> a
-> t
-> f t
atKey :: Index t -> Encoder f a -> a -> t -> f t
atKey Index t
k Encoder f a
enc a
v t
t =
(\Json
v' -> t
t t -> (t -> t) -> t
forall a b. a -> (a -> b) -> b
& Index t -> Lens' t (Maybe (IxValue t))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Index t
k ((Maybe Json -> Identity (Maybe Json)) -> t -> Identity t)
-> Json -> t -> t
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Json
v') (Json -> t) -> f Json -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Encoder f a -> a -> f Json
forall (f :: * -> *) i a.
Functor f =>
EncoderFns i f a -> a -> f Json
runEncoder Encoder f a
enc a
v
atOptKey
:: ( At t
, IxValue t ~ Json
, Applicative f
)
=> Index t
-> Encoder f a
-> Maybe a
-> t
-> f t
atOptKey :: Index t -> Encoder f a -> Maybe a -> t -> f t
atOptKey Index t
k Encoder f a
enc =
(t -> f t) -> (a -> t -> f t) -> Maybe a -> t -> f t
forall b a. b -> (a -> b) -> Maybe a -> b
Maybe.maybe t -> f t
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Index t -> Encoder f a -> a -> t -> f t
forall t (f :: * -> *) a.
(At t, IxValue t ~ Json, Applicative f) =>
Index t -> Encoder f a -> a -> t -> f t
atKey Index t
k Encoder f a
enc)
atKey'
:: ( At t
, IxValue t ~ Json
)
=> Index t
-> Encoder' a
-> a
-> t
-> t
atKey' :: Index t -> Encoder' a -> a -> t -> t
atKey' Index t
k Encoder' a
enc a
v =
Index t -> Lens' t (Maybe (IxValue t))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Index t
k ((Maybe Json -> Identity (Maybe Json)) -> t -> Identity t)
-> Json -> t -> t
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Encoder' a -> a -> Json
forall a. Encoder Identity a -> a -> Json
asJson' Encoder' a
enc a
v
{-# INLINE atKey' #-}
atOptKey'
:: ( At t
, IxValue t ~ Json
)
=> Index t
-> Encoder' a
-> Maybe a
-> t
-> t
atOptKey' :: Index t -> Encoder' a -> Maybe a -> t -> t
atOptKey' Index t
k Encoder' a
enc =
(t -> t) -> (a -> t -> t) -> Maybe a -> t -> t
forall b a. b -> (a -> b) -> Maybe a -> b
Maybe.maybe t -> t
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id (Index t -> Encoder' a -> a -> t -> t
forall t a.
(At t, IxValue t ~ Json) =>
Index t -> Encoder' a -> a -> t -> t
atKey' Index t
k Encoder' a
enc)
{-# INLINE atOptKey' #-}
intAt
:: Text
-> Int
-> MapLikeObj WS Json
-> MapLikeObj WS Json
intAt :: Text -> Int -> MapLikeObj WS Json -> MapLikeObj WS Json
intAt =
(Text
-> Encoder' Int -> Int -> MapLikeObj WS Json -> MapLikeObj WS Json)
-> Encoder' Int
-> Text
-> Int
-> MapLikeObj WS Json
-> MapLikeObj WS Json
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text
-> Encoder' Int -> Int -> MapLikeObj WS Json -> MapLikeObj WS Json
forall t a.
(At t, IxValue t ~ Json) =>
Index t -> Encoder' a -> a -> t -> t
atKey' Encoder' Int
forall (f :: * -> *). Applicative f => Encoder f Int
int
textAt
:: Text
-> Text
-> MapLikeObj WS Json
-> MapLikeObj WS Json
textAt :: Text -> Text -> MapLikeObj WS Json -> MapLikeObj WS Json
textAt =
(Text
-> Encoder' Text
-> Text
-> MapLikeObj WS Json
-> MapLikeObj WS Json)
-> Encoder' Text
-> Text
-> Text
-> MapLikeObj WS Json
-> MapLikeObj WS Json
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text
-> Encoder' Text
-> Text
-> MapLikeObj WS Json
-> MapLikeObj WS Json
forall t a.
(At t, IxValue t ~ Json) =>
Index t -> Encoder' a -> a -> t -> t
atKey' Encoder' Text
forall (f :: * -> *). Applicative f => Encoder f Text
text
boolAt
:: Text
-> Bool
-> MapLikeObj WS Json
-> MapLikeObj WS Json
boolAt :: Text -> Bool -> MapLikeObj WS Json -> MapLikeObj WS Json
boolAt =
(Text
-> Encoder' Bool
-> Bool
-> MapLikeObj WS Json
-> MapLikeObj WS Json)
-> Encoder' Bool
-> Text
-> Bool
-> MapLikeObj WS Json
-> MapLikeObj WS Json
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text
-> Encoder' Bool
-> Bool
-> MapLikeObj WS Json
-> MapLikeObj WS Json
forall t a.
(At t, IxValue t ~ Json) =>
Index t -> Encoder' a -> a -> t -> t
atKey' Encoder' Bool
forall (f :: * -> *). Applicative f => Encoder f Bool
bool
traversableAt
:: ( At t
, Traversable f
, IxValue t ~ Json
)
=> Encoder' a
-> Index t
-> f a
-> t
-> t
traversableAt :: Encoder' a -> Index t -> f a -> t -> t
traversableAt Encoder' a
enc =
(Index t -> Encoder' (f a) -> f a -> t -> t)
-> Encoder' (f a) -> Index t -> f a -> t -> t
forall a b c. (a -> b -> c) -> b -> a -> c
flip Index t -> Encoder' (f a) -> f a -> t -> t
forall t a.
(At t, IxValue t ~ Json) =>
Index t -> Encoder' a -> a -> t -> t
atKey' (Encoder' a -> Encoder' (f a)
forall (f :: * -> *) (t :: * -> *) a.
(Applicative f, Traversable t) =>
Encoder f a -> Encoder f (t a)
traversable Encoder' a
enc)
listAt
:: ( At t
, IxValue t ~ Json
)
=> Encoder' a
-> Index t
-> [a]
-> t
-> t
listAt :: Encoder' a -> Index t -> [a] -> t -> t
listAt =
Encoder' a -> Index t -> [a] -> t -> t
forall t (f :: * -> *) a.
(At t, Traversable f, IxValue t ~ Json) =>
Encoder' a -> Index t -> f a -> t -> t
traversableAt
nonemptyAt
:: ( At t
, IxValue t ~ Json
)
=> Encoder' a
-> Index t
-> NonEmpty a
-> t
-> t
nonemptyAt :: Encoder' a -> Index t -> NonEmpty a -> t -> t
nonemptyAt =
Encoder' a -> Index t -> NonEmpty a -> t -> t
forall t (f :: * -> *) a.
(At t, Traversable f, IxValue t ~ Json) =>
Encoder' a -> Index t -> f a -> t -> t
traversableAt
mapLikeObj
:: ( AsJType Json ws a
, Monoid ws
, Semigroup ws
, Applicative f
)
=> (i -> MapLikeObj ws a -> MapLikeObj ws a)
-> Encoder f i
mapLikeObj :: (i -> MapLikeObj ws a -> MapLikeObj ws a) -> Encoder f i
mapLikeObj i -> MapLikeObj ws a -> MapLikeObj ws a
f = (i -> f Json) -> Encoder f i
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
encodeA ((i -> f Json) -> Encoder f i) -> (i -> f Json) -> Encoder f i
forall a b. (a -> b) -> a -> b
$ \i
a ->
Json -> f Json
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Json -> f Json) -> Json -> f Json
forall a b. (a -> b) -> a -> b
$ Tagged (JObject ws a, ws) (Identity (JObject ws a, ws))
-> Tagged Json (Identity Json)
forall r ws a. AsJType r ws a => Prism' r (JObject ws a, ws)
_JObj (Tagged (JObject ws a, ws) (Identity (JObject ws a, ws))
-> Tagged Json (Identity Json))
-> (JObject ws a, ws) -> Json
forall t b. AReview t b -> b -> t
# (MapLikeObj ws a -> JObject ws a
forall ws a. MapLikeObj ws a -> JObject ws a
fromMapLikeObj (MapLikeObj ws a -> JObject ws a)
-> MapLikeObj ws a -> JObject ws a
forall a b. (a -> b) -> a -> b
$ i -> MapLikeObj ws a -> MapLikeObj ws a
f i
a (Tagged () (Identity ())
-> Tagged (MapLikeObj ws a) (Identity (MapLikeObj ws a))
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ())
-> Tagged (MapLikeObj ws a) (Identity (MapLikeObj ws a)))
-> () -> MapLikeObj ws a
forall t b. AReview t b -> b -> t
# ()), ws
forall a. Monoid a => a
mempty)
mapLikeObj'
:: ( AsJType Json ws a
, Semigroup ws
, Monoid ws
)
=> (i -> MapLikeObj ws a -> MapLikeObj ws a)
-> Encoder' i
mapLikeObj' :: (i -> MapLikeObj ws a -> MapLikeObj ws a) -> Encoder' i
mapLikeObj' i -> MapLikeObj ws a -> MapLikeObj ws a
f = (i -> Json) -> Encoder' i
forall a. (a -> Json) -> Encoder' a
encodePureA ((i -> Json) -> Encoder' i) -> (i -> Json) -> Encoder' i
forall a b. (a -> b) -> a -> b
$ \i
a ->
Tagged (JObject ws a, ws) (Identity (JObject ws a, ws))
-> Tagged Json (Identity Json)
forall r ws a. AsJType r ws a => Prism' r (JObject ws a, ws)
_JObj (Tagged (JObject ws a, ws) (Identity (JObject ws a, ws))
-> Tagged Json (Identity Json))
-> (JObject ws a, ws) -> Json
forall t b. AReview t b -> b -> t
# (MapLikeObj ws a -> JObject ws a
forall ws a. MapLikeObj ws a -> JObject ws a
fromMapLikeObj (MapLikeObj ws a -> JObject ws a)
-> MapLikeObj ws a -> JObject ws a
forall a b. (a -> b) -> a -> b
$ i -> MapLikeObj ws a -> MapLikeObj ws a
f i
a (Tagged () (Identity ())
-> Tagged (MapLikeObj ws a) (Identity (MapLikeObj ws a))
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ())
-> Tagged (MapLikeObj ws a) (Identity (MapLikeObj ws a)))
-> () -> MapLikeObj ws a
forall t b. AReview t b -> b -> t
# ()), ws
forall a. Monoid a => a
mempty)
extendObject
:: Functor f
=> ObjEncoder f a
-> a
-> (JObject WS Json -> JObject WS Json)
-> f Json
extendObject :: ObjEncoder f a
-> a -> (JObject WS Json -> JObject WS Json) -> f Json
extendObject ObjEncoder f a
encA a
a JObject WS Json -> JObject WS Json
f =
ObjEncoder f a -> JObject WS Json -> Json
forall i (f :: * -> *) a. EncoderFns i f a -> i -> Json
finaliseEncoding ObjEncoder f a
encA (JObject WS Json -> Json)
-> (JObject WS Json -> JObject WS Json) -> JObject WS Json -> Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. JObject WS Json -> JObject WS Json
f (JObject WS Json -> Json) -> f (JObject WS Json) -> f Json
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ObjEncoder f a -> a -> f (JObject WS Json)
forall i (f :: * -> *) a. EncoderFns i f a -> a -> f i
initialEncoding ObjEncoder f a
encA a
a
extendMapLikeObject
:: Functor f
=> ObjEncoder f a
-> a
-> (MapLikeObj WS Json -> MapLikeObj WS Json)
-> f Json
extendMapLikeObject :: ObjEncoder f a
-> a -> (MapLikeObj WS Json -> MapLikeObj WS Json) -> f Json
extendMapLikeObject ObjEncoder f a
encA a
a MapLikeObj WS Json -> MapLikeObj WS Json
f =
ObjEncoder f a -> JObject WS Json -> Json
forall i (f :: * -> *) a. EncoderFns i f a -> i -> Json
finaliseEncoding ObjEncoder f a
encA (JObject WS Json -> Json)
-> (JObject WS Json -> JObject WS Json) -> JObject WS Json -> Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. JObject WS Json -> JObject WS Json
floopObj (JObject WS Json -> Json) -> f (JObject WS Json) -> f Json
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ObjEncoder f a -> a -> f (JObject WS Json)
forall i (f :: * -> *) a. EncoderFns i f a -> a -> f i
initialEncoding ObjEncoder f a
encA a
a
where
floopObj :: JObject WS Json -> JObject WS Json
floopObj = MapLikeObj WS Json -> JObject WS Json
forall ws a. MapLikeObj ws a -> JObject ws a
fromMapLikeObj (MapLikeObj WS Json -> JObject WS Json)
-> (JObject WS Json -> MapLikeObj WS Json)
-> JObject WS Json
-> JObject WS Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. MapLikeObj WS Json -> MapLikeObj WS Json
f (MapLikeObj WS Json -> MapLikeObj WS Json)
-> (JObject WS Json -> MapLikeObj WS Json)
-> JObject WS Json
-> MapLikeObj WS Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (MapLikeObj WS Json, [JAssoc WS Json]) -> MapLikeObj WS Json
forall a b. (a, b) -> a
fst ((MapLikeObj WS Json, [JAssoc WS Json]) -> MapLikeObj WS Json)
-> (JObject WS Json -> (MapLikeObj WS Json, [JAssoc WS Json]))
-> JObject WS Json
-> MapLikeObj WS Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. JObject WS Json -> (MapLikeObj WS Json, [JAssoc WS Json])
forall ws a.
(Semigroup ws, Monoid ws) =>
JObject ws a -> (MapLikeObj ws a, [JAssoc ws a])
toMapLikeObj
combineObjects
:: Applicative f
=> (a -> (b, c))
-> ObjEncoder f b
-> ObjEncoder f c
-> ObjEncoder f a
combineObjects :: (a -> (b, c)) -> ObjEncoder f b -> ObjEncoder f c -> ObjEncoder f a
combineObjects =
(a -> (b, c)) -> ObjEncoder f b -> ObjEncoder f c -> ObjEncoder f a
forall (f :: * -> *) a b c.
Divisible f =>
(a -> (b, c)) -> f b -> f c -> f a
divide
onObj
:: Applicative f
=> Text
-> b
-> Encoder f b
-> JObject WS Json
-> f (JObject WS Json)
onObj :: Text -> b -> Encoder f b -> JObject WS Json -> f (JObject WS Json)
onObj Text
k b
b Encoder f b
encB JObject WS Json
o = (\JAssoc WS Json
j -> JObject WS Json
o JObject WS Json
-> (JObject WS Json -> JObject WS Json) -> JObject WS Json
forall a b. a -> (a -> b) -> b
& (CommaSeparated WS (JAssoc WS Json)
-> Identity (CommaSeparated WS (JAssoc WS Json)))
-> JObject WS Json -> Identity (JObject WS Json)
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped ((CommaSeparated WS (JAssoc WS Json)
-> Identity (CommaSeparated WS (JAssoc WS Json)))
-> JObject WS Json -> Identity (JObject WS Json))
-> (CommaSeparated WS (JAssoc WS Json)
-> CommaSeparated WS (JAssoc WS Json))
-> JObject WS Json
-> JObject WS Json
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.%~ JAssoc WS Json
-> CommaSeparated WS (JAssoc WS Json)
-> CommaSeparated WS (JAssoc WS Json)
forall s a. Cons s s a a => a -> s -> s
L.cons JAssoc WS Json
j)
(JAssoc WS Json -> JObject WS Json)
-> (Json -> JAssoc WS Json) -> Json -> JObject WS Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. JString -> WS -> WS -> Json -> JAssoc WS Json
forall ws a. JString -> ws -> ws -> a -> JAssoc ws a
JAssoc (Tagged Text (Identity Text) -> Tagged JString (Identity JString)
forall (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Applicative f) =>
p Text (f Text) -> p JString (f JString)
_JStringText (Tagged Text (Identity Text) -> Tagged JString (Identity JString))
-> Text -> JString
forall t b. AReview t b -> b -> t
# Text
k) WS
forall a. Monoid a => a
mempty WS
forall a. Monoid a => a
mempty (Json -> JObject WS Json) -> f Json -> f (JObject WS Json)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Encoder f b -> b -> f Json
forall (f :: * -> *) a. Applicative f => Encoder f a -> a -> f Json
asJson Encoder f b
encB b
b
onObj'
:: Text
-> b
-> Encoder' b
-> JObject WS Json
-> JObject WS Json
onObj' :: Text -> b -> Encoder' b -> JObject WS Json -> JObject WS Json
onObj' Text
k b
b Encoder' b
encB JObject WS Json
o = (\JAssoc WS Json
j -> JObject WS Json
o JObject WS Json
-> (JObject WS Json -> JObject WS Json) -> JObject WS Json
forall a b. a -> (a -> b) -> b
& (CommaSeparated WS (JAssoc WS Json)
-> Identity (CommaSeparated WS (JAssoc WS Json)))
-> JObject WS Json -> Identity (JObject WS Json)
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped ((CommaSeparated WS (JAssoc WS Json)
-> Identity (CommaSeparated WS (JAssoc WS Json)))
-> JObject WS Json -> Identity (JObject WS Json))
-> (CommaSeparated WS (JAssoc WS Json)
-> CommaSeparated WS (JAssoc WS Json))
-> JObject WS Json
-> JObject WS Json
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.%~ JAssoc WS Json
-> CommaSeparated WS (JAssoc WS Json)
-> CommaSeparated WS (JAssoc WS Json)
forall s a. Cons s s a a => a -> s -> s
L.cons JAssoc WS Json
j)
(JAssoc WS Json -> JObject WS Json)
-> (Json -> JAssoc WS Json) -> Json -> JObject WS Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. JString -> WS -> WS -> Json -> JAssoc WS Json
forall ws a. JString -> ws -> ws -> a -> JAssoc ws a
JAssoc (Tagged Text (Identity Text) -> Tagged JString (Identity JString)
forall (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Applicative f) =>
p Text (f Text) -> p JString (f JString)
_JStringText (Tagged Text (Identity Text) -> Tagged JString (Identity JString))
-> Text -> JString
forall t b. AReview t b -> b -> t
# Text
k) WS
forall a. Monoid a => a
mempty WS
forall a. Monoid a => a
mempty (Json -> JObject WS Json) -> Json -> JObject WS Json
forall a b. (a -> b) -> a -> b
$ Encoder' b -> b -> Json
forall a. Encoder Identity a -> a -> Json
asJson' Encoder' b
encB b
b
keyValuesAsObj
:: ( Foldable g
, Monad f
)
=> g (a -> JObject WS Json -> f (JObject WS Json))
-> Encoder f a
keyValuesAsObj :: g (a -> JObject WS Json -> f (JObject WS Json)) -> Encoder f a
keyValuesAsObj g (a -> JObject WS Json -> f (JObject WS Json))
xs = (a -> f Json) -> Encoder f a
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
encodeA ((a -> f Json) -> Encoder f a) -> (a -> f Json) -> Encoder f a
forall a b. (a -> b) -> a -> b
$ \a
a ->
(\JObject WS Json
v -> Tagged (JObject WS Json, WS) (Identity (JObject WS Json, WS))
-> Tagged Json (Identity Json)
forall r ws a. AsJType r ws a => Prism' r (JObject ws a, ws)
_JObj (Tagged (JObject WS Json, WS) (Identity (JObject WS Json, WS))
-> Tagged Json (Identity Json))
-> (JObject WS Json, WS) -> Json
forall t b. AReview t b -> b -> t
# (JObject WS Json
v,WS
forall a. Monoid a => a
mempty)) (JObject WS Json -> Json) -> f (JObject WS Json) -> f Json
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((a -> JObject WS Json -> f (JObject WS Json))
-> JObject WS Json -> f (JObject WS Json))
-> JObject WS Json
-> g (a -> JObject WS Json -> f (JObject WS Json))
-> f (JObject WS Json)
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> b -> m b) -> b -> t a -> m b
foldrM (\a -> JObject WS Json -> f (JObject WS Json)
f -> a -> JObject WS Json -> f (JObject WS Json)
f a
a) (Tagged () (Identity ())
-> Tagged (JObject WS Json) (Identity (JObject WS Json))
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ())
-> Tagged (JObject WS Json) (Identity (JObject WS Json)))
-> () -> JObject WS Json
forall t b. AReview t b -> b -> t
# ()) g (a -> JObject WS Json -> f (JObject WS Json))
xs
keyValueTupleFoldable
:: ( Monad f
, Foldable g
)
=> Encoder f a
-> Encoder f (g (Text, a))
keyValueTupleFoldable :: Encoder f a -> Encoder f (g (Text, a))
keyValueTupleFoldable Encoder f a
eA = (g (Text, a) -> f Json) -> Encoder f (g (Text, a))
forall a (f :: * -> *). (a -> f Json) -> EncoderFns Json f a
encodeA ((g (Text, a) -> f Json) -> Encoder f (g (Text, a)))
-> (g (Text, a) -> f Json) -> Encoder f (g (Text, a))
forall a b. (a -> b) -> a -> b
$
(JObject WS Json -> Json) -> f (JObject WS Json) -> f Json
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\JObject WS Json
v -> Tagged (JObject WS Json, WS) (Identity (JObject WS Json, WS))
-> Tagged Json (Identity Json)
forall r ws a. AsJType r ws a => Prism' r (JObject ws a, ws)
_JObj (Tagged (JObject WS Json, WS) (Identity (JObject WS Json, WS))
-> Tagged Json (Identity Json))
-> (JObject WS Json, WS) -> Json
forall t b. AReview t b -> b -> t
# (JObject WS Json
v,WS
forall a. Monoid a => a
mempty)) (f (JObject WS Json) -> f Json)
-> (g (Text, a) -> f (JObject WS Json)) -> g (Text, a) -> f Json
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ((Text, a) -> JObject WS Json -> f (JObject WS Json))
-> JObject WS Json -> g (Text, a) -> f (JObject WS Json)
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> b -> m b) -> b -> t a -> m b
foldrM (\(Text
k,a
v) JObject WS Json
o -> Text -> a -> Encoder f a -> JObject WS Json -> f (JObject WS Json)
forall (f :: * -> *) b.
Applicative f =>
Text -> b -> Encoder f b -> JObject WS Json -> f (JObject WS Json)
onObj Text
k a
v Encoder f a
eA JObject WS Json
o) (Tagged () (Identity ())
-> Tagged (JObject WS Json) (Identity (JObject WS Json))
forall a. AsEmpty a => Prism' a ()
_Empty (Tagged () (Identity ())
-> Tagged (JObject WS Json) (Identity (JObject WS Json)))
-> () -> JObject WS Json
forall t b. AReview t b -> b -> t
# ())
keyValuesAsObj'
:: ( Foldable g
, Functor g
)
=> g (a -> JObject WS Json -> JObject WS Json)
-> Encoder' a
keyValuesAsObj' :: g (a -> JObject WS Json -> JObject WS Json) -> Encoder' a
keyValuesAsObj' =
g (a -> JObject WS Json -> Identity (JObject WS Json))
-> Encoder' a
forall (g :: * -> *) (f :: * -> *) a.
(Foldable g, Monad f) =>
g (a -> JObject WS Json -> f (JObject WS Json)) -> Encoder f a
keyValuesAsObj (g (a -> JObject WS Json -> Identity (JObject WS Json))
-> Encoder' a)
-> (g (a -> JObject WS Json -> JObject WS Json)
-> g (a -> JObject WS Json -> Identity (JObject WS Json)))
-> g (a -> JObject WS Json -> JObject WS Json)
-> Encoder' a
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ((a -> JObject WS Json -> JObject WS Json)
-> a -> JObject WS Json -> Identity (JObject WS Json))
-> g (a -> JObject WS Json -> JObject WS Json)
-> g (a -> JObject WS Json -> Identity (JObject WS Json))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a -> JObject WS Json -> JObject WS Json
f a
a -> JObject WS Json -> Identity (JObject WS Json)
forall a. a -> Identity a
Identity (JObject WS Json -> Identity (JObject WS Json))
-> (JObject WS Json -> JObject WS Json)
-> JObject WS Json
-> Identity (JObject WS Json)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> JObject WS Json -> JObject WS Json
f a
a)
encAt
:: Applicative f
=> Encoder f b
-> Text
-> (a -> b)
-> a
-> JObject WS Json
-> f (JObject WS Json)
encAt :: Encoder f b
-> Text -> (a -> b) -> a -> JObject WS Json -> f (JObject WS Json)
encAt Encoder f b
e Text
k a -> b
f a
a =
Text -> b -> Encoder f b -> JObject WS Json -> f (JObject WS Json)
forall (f :: * -> *) b.
Applicative f =>
Text -> b -> Encoder f b -> JObject WS Json -> f (JObject WS Json)
onObj Text
k (a -> b
f a
a) Encoder f b
e