summaryrefslogtreecommitdiff
path: root/dht/Presence/ByteStringOperators.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2019-09-28 13:43:29 -0400
committerJoe Crayne <joe@jerkface.net>2020-01-01 19:27:53 -0500
commit11987749fc6e6d3e53ea737d46d5ab13a16faeb8 (patch)
tree5716463275c2d3e902889db619908ded2a73971c /dht/Presence/ByteStringOperators.hs
parentadd2c76bced51fde5e9917e7449ef52be70faf87 (diff)
Factor out some new libraries
word64-map: Data.Word64Map network-addr: Network.Address tox-crypto: Crypto.Tox lifted-concurrent: Control.Concurrent.Lifted.Instrument Control.Concurrent.Async.Lifted.Instrument psq-wrap: Data.Wrapper.PSQInt Data.Wrapper.PSQ minmax-psq: Data.MinMaxPSQ tasks: Control.Concurrent.Tasks kad: Network.Kademlia Network.Kademlia.Bootstrap Network.Kademlia.Routing Network.Kademlia.CommonAPI Network.Kademlia.Persistence Network.Kademlia.Search
Diffstat (limited to 'dht/Presence/ByteStringOperators.hs')
-rw-r--r--dht/Presence/ByteStringOperators.hs59
1 files changed, 59 insertions, 0 deletions
diff --git a/dht/Presence/ByteStringOperators.hs b/dht/Presence/ByteStringOperators.hs
new file mode 100644
index 00000000..e8485134
--- /dev/null
+++ b/dht/Presence/ByteStringOperators.hs
@@ -0,0 +1,59 @@
1{-# LANGUAGE CPP #-}
2module ByteStringOperators where
3
4import qualified Data.ByteString as S (ByteString)
5import Data.ByteString.Lazy.Char8 as L
6import Control.Applicative
7
8#if MIN_VERSION_bytestring(0,10,0)
9#else
10-- These two were imported to provide an NFData instance.
11import qualified Data.ByteString.Lazy.Internal as L (ByteString(..))
12import Control.DeepSeq
13#endif
14
15
16(<++>) :: ByteString -> ByteString -> ByteString
17(<++.>) :: ByteString -> S.ByteString -> ByteString
18(<.++>) :: S.ByteString -> ByteString -> ByteString
19(<.++.>) :: S.ByteString -> S.ByteString -> ByteString
20a <++> b = L.append a b
21a <++.> b = L.append a (fromChunks [b])
22a <.++> b = L.append (fromChunks [a]) b
23a <.++.> b = fromChunks [a,b]
24infixr 5 <.++.>
25infixr 5 <.++>
26infixr 5 <++>
27infixr 5 <++.>
28
29
30(<++$>) :: Functor f => ByteString -> f ByteString -> f ByteString
31(<$++>) :: Functor f => f ByteString -> ByteString -> f ByteString
32(<$++$>) :: Applicative f => f ByteString -> f ByteString -> f ByteString
33a <++$> b = fmap (a<++>) b
34a <$++> b = fmap (<++>b) a
35a <$++$> b = liftA2 (<++>) a b
36infixr 6 <++$>
37infixr 6 <$++>
38infixr 6 <$++$>
39
40(<?++>) :: Maybe ByteString -> ByteString -> ByteString
41Nothing <?++> b = b
42Just a <?++> b = a <++> b
43infixr 5 <?++>
44
45(<++?>) :: ByteString -> Maybe ByteString -> ByteString
46a <++?> Nothing = a
47a <++?> Just b = a <++> b
48infixr 5 <++?>
49
50bshow :: Show a => a -> ByteString
51bshow = L.pack . show
52
53
54#if MIN_VERSION_bytestring(0,10,0)
55#else
56instance NFData L.ByteString where
57 rnf L.Empty = ()
58 rnf (L.Chunk _ b) = rnf b
59#endif