cardano-sl-0.4.3: Cardano SL main implementation

Safe HaskellNone
LanguageHaskell2010

Pos.Util

Contents

Description

Miscellaneous unclassified utility functions.

Synopsis

Documentation

Stuff for testing and benchmarking

class Nonrepeating a where Source #

Type for generating list of unique (nonrepeating) elemets.

Minimal complete definition

nonrepeating

Methods

nonrepeating :: Int -> Gen [a] Source #

class ArbitraryUnsafe a where Source #

ArbitraryUnsafe class ~~~~~~~~~~~~~~~~~~~~~~~~

This class is the same as Arbitrary, except instances of this class for stuff like public/secret keys, VSS shares, commitments etc. are designed not to mimic real data as presisely as possible (using OpenSSL random), but rather to be simple and efficient.

This is especially useful for benchmarking.

Note: we don't need Generic to derive instances of ArbitraryUnsafe. We can either use one-line instance declaration, or -XStandaloneDeriving or -XDeriveAnyClass to write something like deriving (Arbitrary, ArbitraryUnsafe).

sublistN :: Int -> [a] -> Gen [a] Source #

Choose a random (shuffled) subset of length n. Throws an error if there's not enough elements.

unsafeMakeList :: Text -> IO [a] -> [a] Source #

Unsafely create list of n random values to be picked (see note in Arbitrary for explanation) Used because genSharedSecret already returns a list of EncShares, making the replicateM unneeded.

unsafeMakePool :: Text -> Int -> IO a -> [a] Source #

Unsafely create pool of n random values to be picked (see note in Arbitrary for explanation)

arbitrarySizedS :: Int -> Gen ByteString Source #

Make arbitrary ByteString of given length.

arbitrarySizedSL :: Int -> Gen ByteString Source #

Make arbitrary Lazy of given length.

runGen :: Gen a -> a Source #

Get something out of a quickcheck Gen without having to do IO

Various

mappendPair :: (Monoid a, Monoid b) => (a, b) -> (a, b) -> (a, b) Source #

Specialized version of mappend for restricted to pair type.

mconcatPair :: (Monoid a, Monoid b) => [(a, b)] -> (a, b) Source #

Specialized version of mconcat (or fold) for restricting type to list of pairs.

(<//>) :: String -> String -> String Source #

Concatenates two url part using regular slash /. E.g. ".dir" // "file" = ".dir/file".

readerToState :: MonadState s m => Reader s a -> m a Source #

Convert (Reader s) to any (MonadState s)

eitherPanic :: Show a => Text -> Either a b -> b Source #

A helper for simple error handling in executables

inAssertMode :: Applicative m => m a -> m () Source #

This function performs checks at compile-time for different actions. May slowdown implementation. To disable such checks (especially in benchmarks) one should compile with: stack build --flag cardano-sl:-asserts

diffDoubleMap :: forall k1 k2 v. (Eq k1, Eq k2, Hashable k1, Hashable k2) => HashMap k1 (HashMap k2 v) -> HashMap k1 (HashMap k2 v) -> HashMap k1 (HashMap k2 v) Source #

Remove elements which are in b from a

maybeThrow' :: (Mockable Throw m, Exception e) => e -> Maybe a -> m a Source #

NonEmpty

neZipWith3 :: (x -> y -> z -> q) -> NonEmpty x -> NonEmpty y -> NonEmpty z -> NonEmpty q Source #

spanSafe :: (a -> a -> Bool) -> NonEmpty a -> (NonEmpty a, [a]) Source #

Makes a span on the list, considering tail only. Predicate has list head as first argument. Used to take non-null prefix that depends on the first element.

Lenses

makeLensesData :: Name -> Name -> DecsQ Source #

Make lenses for a data family instance.

_neHead :: Lens' (NonEmpty a) a Source #

Lens for the head of NonEmpty.

We can't use _head because it doesn't work for NonEmpty: https://github.com/ekmett/lens/issues/636#issuecomment-213981096. Even if we could though, it wouldn't be a lens, only a traversal.

_neTail :: Lens' (NonEmpty a) [a] Source #

Lens for the tail of NonEmpty.

_neLast :: Lens' (NonEmpty a) a Source #

Lens for the last element of NonEmpty.

LRU

clearLRU :: Ord k => LRU k v -> LRU k v Source #

Remove all items from LRU, retaining maxSize property.

Concurrency

clearMVar :: MonadIO m => MVar a -> m () Source #

forcePutMVar :: MonadIO m => MVar a -> a -> m () Source #

readMVarConditional :: MonadIO m => (x -> Bool) -> MVar x -> m x Source #

Block until value in MVar satisfies given predicate. When value satisfies, it is returned.

readUntilEqualMVar :: (Eq a, MonadIO m) => (x -> a) -> MVar x -> a -> m x Source #

Read until value is equal to stored value comparing by some function.

readTVarConditional :: MonadIO m => (x -> Bool) -> TVar x -> m x Source #

Block until value in TVar satisfies given predicate. When value satisfies, it is returned.

readUntilEqualTVar :: (Eq a, MonadIO m) => (x -> a) -> TVar x -> a -> m x Source #

Read until value is equal to stored value comparing by some function.

withReadLifted :: (MonadIO m, MonadMask m) => RWLock -> m a -> m a Source #

withWriteLifted :: (MonadIO m, MonadMask m) => RWLock -> m a -> m a Source #

Instances

MonadFail ParsecT

MonadFail Dialog

MonadFail Transfer

MonadFail TimedIO

MonadFail ResponseT

MonadFail LoggerNameBox

Orphan instances

MonadFail m => MonadFail (LoggerNameBox m) Source # 

Methods

fail :: String -> LoggerNameBox m a #

MonadFail m => MonadFail (ResourceT m) Source # 

Methods

fail :: String -> ResourceT m a #

MonadFail (ParsecT s u m) Source # 

Methods

fail :: String -> ParsecT s u m a #