summaryrefslogtreecommitdiff
path: root/dht/Presence/ByteStringOperators.hs
blob: e848513427c7b74d5af531e6c43e2509a12cebae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{-# LANGUAGE CPP #-}
module ByteStringOperators where

import qualified Data.ByteString as S (ByteString)
import Data.ByteString.Lazy.Char8 as L 
import Control.Applicative

#if MIN_VERSION_bytestring(0,10,0)
#else
-- These two were imported to provide an NFData instance.
import qualified Data.ByteString.Lazy.Internal as L (ByteString(..))
import Control.DeepSeq
#endif


(<++>) :: ByteString -> ByteString -> ByteString
(<++.>) :: ByteString -> S.ByteString -> ByteString
(<.++>) :: S.ByteString -> ByteString -> ByteString
(<.++.>) :: S.ByteString -> S.ByteString -> ByteString
a <++> b =  L.append a b
a <++.> b = L.append a (fromChunks [b])
a <.++> b = L.append (fromChunks [a]) b
a <.++.> b = fromChunks [a,b]
infixr 5 <.++.>
infixr 5 <.++>
infixr 5 <++>
infixr 5 <++.>


(<++$>) :: Functor f => ByteString -> f ByteString -> f ByteString
(<$++>) :: Functor f => f ByteString -> ByteString -> f ByteString
(<$++$>) :: Applicative f => f ByteString -> f ByteString -> f ByteString
a <++$> b = fmap (a<++>) b
a <$++> b = fmap (<++>b) a
a <$++$> b = liftA2 (<++>) a b
infixr 6 <++$>
infixr 6 <$++>
infixr 6 <$++$>

(<?++>) :: Maybe ByteString -> ByteString -> ByteString
Nothing <?++> b = b
Just a  <?++> b = a <++> b
infixr 5 <?++>

(<++?>) :: ByteString -> Maybe ByteString -> ByteString
a <++?> Nothing = a
a <++?> Just b  = a <++> b
infixr 5 <++?>

bshow :: Show a => a -> ByteString
bshow = L.pack . show


#if MIN_VERSION_bytestring(0,10,0)
#else
instance NFData L.ByteString where
    rnf L.Empty       = ()
    rnf (L.Chunk _ b) = rnf b
#endif