Copyright | © 2020-2021 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
General utility functions.
Synopsis
- type HasCallStack = ?callStack :: CallStack
- internalError :: HasCallStack => Builder -> a
- tina :: HasCallStack => Builder -> [ Maybe a] -> a
- invariant :: HasCallStack => String -> a -> (a -> Bool ) -> a
- isInternalError :: ErrorCall -> Maybe String
- tryInternalError :: MonadUnliftIO m => a -> m ( Either String a)
-
newtype
ShowFmt
a =
ShowFmt
{
- unShowFmt :: a
- mapFirst :: (a -> a) -> [a] -> [a]
- modifyM :: forall m s. Monad m => (s -> m s) -> StateT s m ()
- uriToText :: URI -> Text
- parseURI :: Text -> Either TextDecodingError URI
Partial functions for "impossible" situations
type HasCallStack = ?callStack :: CallStack Source #
Request a CallStack.
NOTE: The implicit parameter
?callStack :: CallStack
is an
implementation detail and
should not
be considered part of the
CallStack
API, we may decide to change the implementation in the
future.
Since: base-4.9.0.0
internalError :: HasCallStack => Builder -> a Source #
Calls the
error
function, which will usually crash the program.
:: HasCallStack | |
=> String |
The message |
-> a |
The value to test |
-> (a -> Bool ) |
The predicate |
-> a |
Checks whether or not an invariant holds, by applying the given predicate to the given value.
If the invariant does not hold (indicated by the predicate function
returning
False
), throws an error with the specified message.
>>>
invariant "not empty" [1,2,3] (not . null)
[1, 2, 3]
>>>
invariant "not empty" [] (not . null)
*** Exception: not empty
Handling errors for "impossible" situations.
isInternalError :: ErrorCall -> Maybe String Source #
Tests whether an
Exception
was caused by
internalError
.
tryInternalError :: MonadUnliftIO m => a -> m ( Either String a) Source #
Evaluates a pure expression to WHNF and handles any occurrence of
internalError
.
This is intended for use in testing. Don't use this in application code -- that's what normal IO exceptions are for.
String formatting
A polymorphic wrapper type with a custom show instance to display data
through
Buildable
instances.
Instances
Eq a => Eq ( ShowFmt a) Source # | |
Ord a => Ord ( ShowFmt a) Source # | |
Defined in Cardano.Wallet.Util |
|
Buildable a => Show ( ShowFmt a) Source # | |
Generic ( ShowFmt a) Source # | |
NFData a => NFData ( ShowFmt a) Source # | |
Defined in Cardano.Wallet.Util |
|
type Rep ( ShowFmt a) Source # | |
Defined in Cardano.Wallet.Util |
mapFirst :: (a -> a) -> [a] -> [a] Source #
Map a function to the first element of a list. Does nothing if the list is empty.
StateT
modifyM :: forall m s. Monad m => (s -> m s) -> StateT s m () Source #
Effectfully modify the state of a state-monad transformer stack.