Safe Haskell | None |
---|---|

Language | Haskell2010 |

Miscellaneous unclassified utility functions.

- module Pos.Util.Util
- class Nonrepeating a where
- class ArbitraryUnsafe a where
- makeSmall :: Gen a -> Gen a
- sublistN :: Int -> [a] -> Gen [a]
- unsafeMakeList :: Text -> IO [a] -> [a]
- unsafeMakePool :: Text -> Int -> IO a -> [a]
- arbitrarySizedS :: Int -> Gen ByteString
- arbitrarySizedSL :: Int -> Gen ByteString
- runGen :: Gen a -> a
- module Pos.Util.TimeLimit
- mappendPair :: (Monoid a, Monoid b) => (a, b) -> (a, b) -> (a, b)
- mconcatPair :: (Monoid a, Monoid b) => [(a, b)] -> (a, b)
- (<//>) :: String -> String -> String
- readerToState :: MonadState s m => Reader s a -> m a
- eitherPanic :: Show a => Text -> Either a b -> b
- inAssertMode :: Applicative m => m a -> m ()
- 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)
- maybeThrow' :: (Mockable Throw m, Exception e) => e -> Maybe a -> m a
- neZipWith3 :: (x -> y -> z -> q) -> NonEmpty x -> NonEmpty y -> NonEmpty z -> NonEmpty q
- spanSafe :: (a -> a -> Bool) -> NonEmpty a -> (NonEmpty a, [a])
- makeLensesData :: Name -> Name -> DecsQ
- _neHead :: Lens' (NonEmpty a) a
- _neTail :: Lens' (NonEmpty a) [a]
- _neLast :: Lens' (NonEmpty a) a
- clearLRU :: Ord k => LRU k v -> LRU k v
- eitherToVerRes :: Either Text a -> VerificationRes
- clearMVar :: MonadIO m => MVar a -> m ()
- forcePutMVar :: MonadIO m => MVar a -> a -> m ()
- readMVarConditional :: MonadIO m => (x -> Bool) -> MVar x -> m x
- readUntilEqualMVar :: (Eq a, MonadIO m) => (x -> a) -> MVar x -> a -> m x
- readTVarConditional :: MonadIO m => (x -> Bool) -> TVar x -> m x
- readUntilEqualTVar :: (Eq a, MonadIO m) => (x -> a) -> TVar x -> a -> m x
- withReadLifted :: (MonadIO m, MonadMask m) => RWLock -> m a -> m a
- withWriteLifted :: (MonadIO m, MonadMask m) => RWLock -> m a -> m a

# Documentation

module Pos.Util.Util

# Stuff for testing and benchmarking

class Nonrepeating a where Source #

Type for generating list of unique (nonrepeating) elemets.

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)`

.

arbitraryUnsafe :: Gen a Source #

arbitraryUnsafe :: Arbitrary a => Gen a Source #

ArbitraryUnsafe Word16 Source # | |

ArbitraryUnsafe Word32 Source # | |

ArbitraryUnsafe Word64 Source # | |

Arbitrary ByteString => ArbitraryUnsafe ByteString Source # | |

ArbitraryUnsafe a => ArbitraryUnsafe [a] Source # | |

ArbitraryUnsafe a => ArbitraryUnsafe (NonEmpty a) Source # | |

(ArbitraryUnsafe a, ArbitraryUnsafe b) => ArbitraryUnsafe (a, b) Source # | |

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.

module Pos.Util.TimeLimit

# 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 #

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`

# NonEmpty

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

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

# LRU

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

Remove all items from LRU, retaining maxSize property.

eitherToVerRes :: Either Text a -> VerificationRes Source #

# Concurrency

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.