{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Data.String.Interpolate.Conversion.Classes
( B(..)
, IsCustomSink, InterpSink(..), Interpolatable(..), SpaceChompable(..)
)
where
import Data.Kind ( Type )
import Data.Proxy
import qualified Data.ByteString as B
import qualified Data.ByteString.Builder as LB
import qualified Data.ByteString.Lazy as LB
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.Builder as LT
newtype B dst a = B { unB :: a }
deriving (Eq, Show)
type family IsCustomSink dst where
IsCustomSink T.Text = 'True
IsCustomSink LT.Text = 'True
IsCustomSink LT.Builder = 'True
IsCustomSink B.ByteString = 'True
IsCustomSink LB.ByteString = 'True
IsCustomSink LB.Builder = 'True
IsCustomSink _ = 'False
class IsCustomSink dst ~ flag => InterpSink (flag :: Bool) dst where
type Builder flag dst :: Type
ofString :: Proxy flag -> String -> B dst (Builder flag dst)
build :: Proxy flag -> B dst (Builder flag dst) -> B dst (Builder flag dst) -> B dst (Builder flag dst)
finalize :: Proxy flag -> B dst (Builder flag dst) -> dst
class InterpSink flag dst => Interpolatable (flag :: Bool) src dst where
interpolate :: Proxy flag -> src -> B dst (Builder flag dst)
class SpaceChompable a where
chompSpaces :: a -> a