feat: strict inDatatypeOf
This commit is contained in:
parent
b90e2f115b
commit
a28f6abe5d
1 changed files with 4 additions and 2 deletions
|
@ -14,6 +14,7 @@
|
|||
{-# LANGUAGE StandaloneDeriving #-}
|
||||
{-# LANGUAGE DerivingVia #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE BangPatterns #-}
|
||||
module Pretty.Serialize (Serializer, PrettySerialize(..), ShowPrettySerialize(..), run, emit, KeyValueSerialize(..), customField) where
|
||||
|
||||
import Data.Text.Lazy.Builder (Builder)
|
||||
|
@ -85,7 +86,6 @@ modifySerializerState f = getSerializerState >>= setSerializerState . f
|
|||
|
||||
-- | Append a text to the serializer buffer. Does not check whether the emitted text contains a newline.
|
||||
|
||||
|
||||
emit :: Text -> Serializer ()
|
||||
emit t = Serializer $ \ state -> (state { builder = state.builder <> Builder.fromLazyText t }, ())
|
||||
|
||||
|
@ -158,7 +158,9 @@ inDatatype name body = do
|
|||
body
|
||||
|
||||
inDatatypeOf :: Typeable a => a -> Serializer b -> Serializer b
|
||||
inDatatypeOf = inDatatype . Text.pack . show . typeOf
|
||||
inDatatypeOf x s = let
|
||||
!typeName = Text.pack . show . typeOf $ x
|
||||
in inDatatype typeName s
|
||||
|
||||
run :: Serializer () -> Text
|
||||
run (Serializer computeUnit) = Builder.toLazyText . builder . fst . computeUnit $ SerializerState {builder=mempty, indentation=0, increaseIndentation=(+4), currentFieldIndex=Nothing}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue