feat: strict inDatatypeOf

This commit is contained in:
vegowotenks 2025-08-23 18:39:46 +02:00
parent b90e2f115b
commit a28f6abe5d

View file

@ -14,6 +14,7 @@
{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DerivingVia #-} {-# LANGUAGE DerivingVia #-}
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE BangPatterns #-}
module Pretty.Serialize (Serializer, PrettySerialize(..), ShowPrettySerialize(..), run, emit, KeyValueSerialize(..), customField) where module Pretty.Serialize (Serializer, PrettySerialize(..), ShowPrettySerialize(..), run, emit, KeyValueSerialize(..), customField) where
import Data.Text.Lazy.Builder (Builder) 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. -- | Append a text to the serializer buffer. Does not check whether the emitted text contains a newline.
emit :: Text -> Serializer () emit :: Text -> Serializer ()
emit t = Serializer $ \ state -> (state { builder = state.builder <> Builder.fromLazyText t }, ()) emit t = Serializer $ \ state -> (state { builder = state.builder <> Builder.fromLazyText t }, ())
@ -158,7 +158,9 @@ inDatatype name body = do
body body
inDatatypeOf :: Typeable a => a -> Serializer b -> Serializer b 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 () -> Text
run (Serializer computeUnit) = Builder.toLazyText . builder . fst . computeUnit $ SerializerState {builder=mempty, indentation=0, increaseIndentation=(+4), currentFieldIndex=Nothing} run (Serializer computeUnit) = Builder.toLazyText . builder . fst . computeUnit $ SerializerState {builder=mempty, indentation=0, increaseIndentation=(+4), currentFieldIndex=Nothing}