Copyright | No rights reserved |
---|---|
License | UNLICENSE |
Maintainer | xenog@protonmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This module defines various utility functions used across the library.
Synopsis
- bsToInteger :: ByteString -> Integer
- integerToBS :: Integer -> ByteString
- encodeHex :: ByteString -> Text
- decodeHex :: Text -> Maybe ByteString
- getBits :: Int -> ByteString -> ByteString
- eitherToMaybe :: Either a b -> Maybe b
- maybeToEither :: b -> Maybe a -> Either b a
- liftEither :: Monad m => Either b a -> ExceptT b m a
- liftMaybe :: Monad m => b -> Maybe a -> ExceptT b m a
- updateIndex :: Int -> [a] -> (a -> a) -> [a]
- matchTemplate :: [a] -> [b] -> (a -> b -> Bool) -> [Maybe a]
- convertBits :: Bool -> Int -> Int -> [Word] -> ([Word], Bool)
- fst3 :: (a, b, c) -> a
- snd3 :: (a, b, c) -> b
- lst3 :: (a, b, c) -> c
- 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 -> Text Source #
Encode as string of human-readable hex characters.
getBits :: Int -> ByteString -> ByteString Source #
Obtain Int
bits from beginning of ByteString
. Resulting ByteString
will be smallest required to hold that many bits, padded with zeroes to the
right.
Maybe & Either Helpers
eitherToMaybe :: Either a b -> Maybe b Source #
maybeToEither :: b -> Maybe a -> Either b a Source #
Other Helpers
:: Int | index of the element to change |
-> [a] | list of elements |
-> (a -> a) | function to apply |
-> [a] | 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.
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.
convertBits :: Bool -> Int -> Int -> [Word] -> ([Word], Bool) Source #
Convert from one power-of-two base to another, as long as it fits in a
Word
.
Triples
JSON Utilities
dropFieldLabel :: Int -> Options Source #
Field label goes lowercase and first n
characters get removed.
dropSumLabels :: Int -> Int -> String -> Options Source #
Transformation from dropFieldLabel
is applied with argument f
, plus
constructor tags are lowercased and first c
characters removed. tag
is
used as the name of the object field name that will hold the transformed
constructor tag as its value.