haskoin-core-0.4.2: Implementation of the core Bitcoin protocol features.

Safe HaskellNone
LanguageHaskell98

Network.Haskoin.Util

Contents

Description

This module defines various utility functions used across the Network.Haskoin modules.

Synopsis

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

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

Maybe and Either monad helpers

isLeft :: Either a b -> Bool Source #

Returns True if the Either value is Left

isRight :: Either a b -> Bool Source #

Returns True if the Either value is Right

fromRight :: Either a b -> b Source #

Extract the Right value from an Either value. Fails if the value is Left

fromLeft :: Either a b -> a Source #

Extract the Left value from an Either value. Fails if the value is Right

eitherToMaybe :: Either a b -> Maybe b Source #

Transforms an Either value into a Maybe value. Right is mapped to Just and Left is mapped to Nothing. The value inside Left is lost.

maybeToEither :: b -> Maybe a -> Either b a Source #

Transforms a Maybe value into an Either value. Just is mapped to Right and Nothing is mapped to Left. You also pass in an error value in case Left is returned.

liftEither :: Monad m => Either b a -> EitherT b m a Source #

Lift a Either computation into the EitherT monad

liftMaybe :: Monad m => b -> Maybe a -> EitherT b m a Source #

Lift a Maybe computation into the EitherT monad

Various helpers

updateIndex Source #

Arguments

:: 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.

matchTemplate Source #

Arguments

:: [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

fst3 :: (a, b, c) -> a Source #

Returns the first value of a triple.

snd3 :: (a, b, c) -> b Source #

Returns the second value of a triple.

lst3 :: (a, b, c) -> c Source #

Returns the last value of a triple.

MonadState

modify' :: MonadState s m => (s -> s) -> m () Source #

Strict evaluation of the new state

JSON Utilities