{-# LANGUAGE CPP, FlexibleInstances, MultiParamTypeClasses #-}
{-# OPTIONS_GHC -Wall -fno-warn-orphans -Werror #-}

{-|
Module      : Data.Tuple.Append.Instances.ByteString
Description : A module that contains typeclasses instances for the bytestring package.
Maintainer  : hapytexeu+gh@gmail.com
Stability   : experimental
Portability : POSIX

A module that contains typeclasses instances for the 'Data.ByteString.ByteString', lazy 'Data.ByteString.Lazy.ByteString', and 'ShortByteString' data types.
-}

module Data.Tuple.Append.Instances.ByteString () where

import Data.ByteString.Short(ShortByteString)
#if MIN_VERSION_bytestring(0,11,3)
import qualified Data.ByteString.Short as BS(append, cons, snoc)
#else
import Data.ByteString.Short.Internal(fromShort, toShort)
#endif
import Data.Function(on)
import Data.Tuple.Append.Class(TupleAddL((<++)), TupleAddR((++>)), TupleAppend((+++)))
import Data.Tuple.Append.Instances.ByteString.Safe()
import Data.Word(Word8)

instance TupleAddL Word8 ShortByteString ShortByteString where
#if MIN_VERSION_bytestring(0,11,3)
  (<++) = BS.cons
#else
  <++ :: Word8 -> ShortByteString -> ShortByteString
(<++) Word8
c = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word8
c Word8 -> ByteString -> ByteString
forall x 𝐯 x𝐯. TupleAddL x 𝐯 x𝐯 => x -> 𝐯 -> x𝐯
<++) (ByteString -> ByteString)
-> (ShortByteString -> ByteString) -> ShortByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
#endif

instance TupleAddR ShortByteString Word8 ShortByteString where
#if MIN_VERSION_bytestring(0,11,3)
  (++>) = BS.snoc
#else
  ++> :: ShortByteString -> Word8 -> ShortByteString
(++>) ShortByteString
vs Word8
x = ByteString -> ShortByteString
toShort (ShortByteString -> ByteString
fromShort ShortByteString
vs ByteString -> Word8 -> ByteString
forall 𝐯 x 𝐯x. TupleAddR 𝐯 x 𝐯x => 𝐯 -> x -> 𝐯x
++> Word8
x)
#endif

instance TupleAppend ShortByteString ShortByteString ShortByteString where
#if MIN_VERSION_bytestring(0,11,3)
  (+++) = BS.append
#else
  +++ :: ShortByteString -> ShortByteString -> ShortByteString
(+++) ShortByteString
us = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> ByteString -> ByteString
forall 𝐮 𝐯 𝐮𝐯. TupleAppend 𝐮 𝐯 𝐮𝐯 => 𝐮 -> 𝐯 -> 𝐮𝐯
(+++) (ByteString -> ByteString -> ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
-> ByteString
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` ShortByteString -> ByteString
fromShort) ShortByteString
us
#endif