Safe Haskell | None |
---|---|
Language | Haskell98 |
This module defines various utility functions used across the Network.Haskoin modules.
- bsToInteger :: ByteString -> Integer
- integerToBS :: Integer -> ByteString
- encodeHex :: ByteString -> ByteString
- decodeHex :: ByteString -> Maybe ByteString
- encode' :: Binary a => a -> ByteString
- decode' :: Binary a => ByteString -> a
- runPut' :: Put -> ByteString
- runGet' :: Binary a => Get a -> ByteString -> a
- decodeOrFail' :: Binary a => ByteString -> Either (ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
- runGetOrFail' :: Get a -> ByteString -> Either (ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
- fromDecode :: Binary a => ByteString -> b -> (a -> b) -> b
- fromRunGet :: Binary a => Get a -> ByteString -> b -> (a -> b) -> b
- decodeToEither :: Binary a => ByteString -> Either String a
- decodeToMaybe :: Binary a => ByteString -> Maybe a
- isolate :: Binary a => Int -> Get a -> Get a
- isLeft :: Either a b -> Bool
- isRight :: Either a b -> Bool
- fromRight :: Either a b -> b
- fromLeft :: Either a b -> a
- eitherToMaybe :: Either a b -> Maybe b
- maybeToEither :: b -> Maybe a -> Either b a
- liftEither :: Monad m => Either b a -> EitherT b m a
- liftMaybe :: Monad m => b -> Maybe a -> EitherT b m a
- updateIndex :: Int -> [a] -> (a -> a) -> [a]
- matchTemplate :: [a] -> [b] -> (a -> b -> Bool) -> [Maybe a]
- fst3 :: (a, b, c) -> a
- snd3 :: (a, b, c) -> b
- lst3 :: (a, b, c) -> c
- modify' :: MonadState s m => (s -> s) -> m ()
- dropFieldLabel :: Int -> Options
- dropSumLabels :: Int -> Int -> String -> Options
ByteString helpers
bsToInteger :: ByteString -> Integer Source
Decode a big endian Integer from a bytestring.
integerToBS :: Integer -> ByteString Source
Encode an Integer to a bytestring as big endian
encodeHex :: ByteString -> ByteString Source
decodeHex :: ByteString -> Maybe ByteString Source
Decode hexadecimal ByteString
. This function can fail if the string
contains invalid hexadecimal (0-9, a-f, A-F) characters
Data.Binary helpers
encode' :: Binary a => a -> ByteString Source
Strict version of encode
decode' :: Binary a => ByteString -> a Source
Strict version of decode
runPut' :: Put -> ByteString Source
Strict version of runPut
decodeOrFail' :: Binary a => ByteString -> Either (ByteString, ByteOffset, String) (ByteString, ByteOffset, a) Source
Strict version of decodeOrFail
runGetOrFail' :: Get a -> ByteString -> Either (ByteString, ByteOffset, String) (ByteString, ByteOffset, a) Source
Strict version of runGetOrFail
:: Binary a | |
=> ByteString | The bytestring to decode |
-> b | Default value to return when decoding fails |
-> (a -> b) | Function to apply when decoding succeeds |
-> b | Final result |
Try to decode a Binary
value. If decoding succeeds, apply the
function to the result. Otherwise, return the default value.
:: Binary a | |
=> Get a | The Get monad to run |
-> ByteString | The bytestring to decode |
-> b | Default value to return when decoding fails |
-> (a -> b) | Function to apply when decoding succeeds |
-> b | Final result |
Try to run a Get
monad. If decoding succeeds, apply a
function to the result. Otherwise, return the default value.
decodeToEither :: Binary a => ByteString -> Either String a Source
decodeToMaybe :: Binary a => ByteString -> Maybe a Source
isolate :: Binary a => Int -> Get a -> Get a Source
Isolate a Get
monad for the next Int
bytes. Only the next
Int
bytes of the input ByteString
will be available for the Get
monad
to consume. This function will fail if the Get monad fails or some of the
input is not consumed.
Maybe and Either monad helpers
eitherToMaybe :: Either a b -> Maybe b Source
maybeToEither :: b -> Maybe a -> Either b a Source
liftEither :: Monad m => Either b a -> EitherT b m a Source
Various helpers
:: Int | The index of the element to change |
-> [a] | The list of elements |
-> (a -> a) | The function to apply |
-> [a] | The result with one element changed |
Applies a function to only one element of a list defined by its index. If the index is out of the bounds of the list, the original list is returned.
:: [a] | The input list |
-> [b] | The list to serve as a template |
-> (a -> b -> Bool) | The comparison function |
-> [Maybe a] | Results of the template matching |
Use the list [b]
as a template and try to match the elements of [a]
against it. For each element of [b]
return the (first) matching element of
[a]
, or Nothing
. Output list has same size as [b]
and contains results
in same order. Elements of [a]
can only appear once.
Triples
MonadState
modify' :: MonadState s m => (s -> s) -> m () Source
Strict evaluation of the new state
JSON Utilities
dropFieldLabel :: Int -> Options Source