diff options
author | James Crayne <jim.crayne@gmail.com> | 2019-09-28 13:43:29 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 19:27:53 -0500 |
commit | 11987749fc6e6d3e53ea737d46d5ab13a16faeb8 (patch) | |
tree | 5716463275c2d3e902889db619908ded2a73971c /dht/Presence/ByteStringOperators.hs | |
parent | add2c76bced51fde5e9917e7449ef52be70faf87 (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.hs | 59 |
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 #-} | ||
2 | module ByteStringOperators where | ||
3 | |||
4 | import qualified Data.ByteString as S (ByteString) | ||
5 | import Data.ByteString.Lazy.Char8 as L | ||
6 | import Control.Applicative | ||
7 | |||
8 | #if MIN_VERSION_bytestring(0,10,0) | ||
9 | #else | ||
10 | -- These two were imported to provide an NFData instance. | ||
11 | import qualified Data.ByteString.Lazy.Internal as L (ByteString(..)) | ||
12 | import 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 | ||
20 | a <++> b = L.append a b | ||
21 | a <++.> b = L.append a (fromChunks [b]) | ||
22 | a <.++> b = L.append (fromChunks [a]) b | ||
23 | a <.++.> b = fromChunks [a,b] | ||
24 | infixr 5 <.++.> | ||
25 | infixr 5 <.++> | ||
26 | infixr 5 <++> | ||
27 | infixr 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 | ||
33 | a <++$> b = fmap (a<++>) b | ||
34 | a <$++> b = fmap (<++>b) a | ||
35 | a <$++$> b = liftA2 (<++>) a b | ||
36 | infixr 6 <++$> | ||
37 | infixr 6 <$++> | ||
38 | infixr 6 <$++$> | ||
39 | |||
40 | (<?++>) :: Maybe ByteString -> ByteString -> ByteString | ||
41 | Nothing <?++> b = b | ||
42 | Just a <?++> b = a <++> b | ||
43 | infixr 5 <?++> | ||
44 | |||
45 | (<++?>) :: ByteString -> Maybe ByteString -> ByteString | ||
46 | a <++?> Nothing = a | ||
47 | a <++?> Just b = a <++> b | ||
48 | infixr 5 <++?> | ||
49 | |||
50 | bshow :: Show a => a -> ByteString | ||
51 | bshow = L.pack . show | ||
52 | |||
53 | |||
54 | #if MIN_VERSION_bytestring(0,10,0) | ||
55 | #else | ||
56 | instance NFData L.ByteString where | ||
57 | rnf L.Empty = () | ||
58 | rnf (L.Chunk _ b) = rnf b | ||
59 | #endif | ||