cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2020-2021 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Wallet.Util

Description

General utility functions.

Synopsis

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.

tina :: HasCallStack => Builder -> [ Maybe a] -> a Source #

Take the first Just from a list of Maybe , or die trying. There is no alternative.

invariant Source #

Arguments

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

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

newtype ShowFmt a Source #

A polymorphic wrapper type with a custom show instance to display data through Buildable instances.

Constructors

ShowFmt

Fields

Instances

Instances details
Eq a => Eq ( ShowFmt a) Source #
Instance details

Defined in Cardano.Wallet.Util

Ord a => Ord ( ShowFmt a) Source #
Instance details

Defined in Cardano.Wallet.Util

Buildable a => Show ( ShowFmt a) Source #
Instance details

Defined in Cardano.Wallet.Util

Generic ( ShowFmt a) Source #
Instance details

Defined in Cardano.Wallet.Util

Associated Types

type Rep ( ShowFmt a) :: Type -> Type Source #

NFData a => NFData ( ShowFmt a) Source #
Instance details

Defined in Cardano.Wallet.Util

type Rep ( ShowFmt a) Source #
Instance details

Defined in Cardano.Wallet.Util

type Rep ( ShowFmt a) = D1 (' MetaData "ShowFmt" "Cardano.Wallet.Util" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "ShowFmt" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "unShowFmt") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 a)))

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.

HTTP(S) URIs