Skip to content

Commit

Permalink
instance IsList Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
BebeSparkelSparkel committed Apr 12, 2024
1 parent 46a3aeb commit 5855a0e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Data/ByteString/Builder/Internal.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoMonoLocalBinds #-}

{-# OPTIONS_HADDOCK not-home #-}

Expand Down Expand Up @@ -128,6 +130,7 @@ module Data.ByteString.Builder.Internal (
) where

import Control.Arrow (second)
import GHC.Exts (IsList(..))

import Data.Semigroup (Semigroup(..))
import Data.List.NonEmpty (NonEmpty(..))
Expand Down Expand Up @@ -414,6 +417,12 @@ instance Monoid Builder where
{-# INLINE mconcat #-}
mconcat = foldr mappend mempty

instance IsList Builder where
type Item Builder = Word8
fromList = byteStringInsert . fromList
fromListN n = byteStringThreshold n . fromList
toList = toList . toLazyByteStringWith (safeStrategy L.smallChunkSize L.smallChunkSize) mempty

-- | Flush the current buffer. This introduces a chunk boundary.
{-# INLINE flush #-}
flush :: Builder
Expand Down

0 comments on commit 5855a0e

Please sign in to comment.