Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Miscellaneous utilities
Synopsis
- class Empty a
- class ShowProxy (p ∷ k) where
- data Some (f ∷ k → Type) where
- data SomePair (f ∷ k → Type) (g ∷ k → Type) where
- data SomeSecond f a where
- SomeSecond ∷ !(f a b) → SomeSecond f a
- mustBeRight ∷ Either Void a → a
- foldlM' ∷ ∀ m a b. Monad m ⇒ (b → a → m b) → b → [a] → m b
- nTimes ∷ ∀ a. (a → a) → Word64 → a → a
- nTimesM ∷ ∀ m a. Monad m ⇒ (a → m a) → Word64 → a → m a
- repeatedly ∷ (a → b → b) → [a] → b → b
- repeatedlyM ∷ Monad m ⇒ (a → b → m b) → [a] → b → m b
- allEqual ∷ Eq a ⇒ [a] → Bool
- chunks ∷ Int → [a] → [[a]]
- dropLast ∷ Word64 → [a] → [a]
- firstJust ∷ ∀ a b f. Foldable f ⇒ (a → Maybe b) → f a → Maybe b
- markLast ∷ [a] → [Either a a]
- pickOne ∷ [a] → [([a], a, [a])]
- split ∷ (a → Bool) → [a] → NonEmpty [a]
- splits ∷ [a] → [([a], a, [a])]
- takeLast ∷ Word64 → [a] → [a]
- takeUntil ∷ (a → Bool) → [a] → [a]
- lastMaybe ∷ [a] → Maybe a
- safeMaximum ∷ Ord a ⇒ [a] → Maybe a
- safeMaximumBy ∷ (a → a → Ordering) → [a] → Maybe a
- safeMaximumOn ∷ Ord b ⇒ (a → b) → [a] → Maybe a
- hashFromBytesE ∷ ∀ h a. (HashAlgorithm h, HasCallStack) ⇒ ByteString → Hash h a
- hashFromBytesShortE ∷ ∀ h a. (HashAlgorithm h, HasCallStack) ⇒ ShortByteString → Hash h a
- byteStringChunks ∷ Int → ByteString → [ByteString]
- lazyByteStringChunks ∷ Int → ByteString → [ByteString]
- whenJust ∷ Applicative f ⇒ Maybe a → (a → f ()) → f ()
- checkThat ∷ (Show a, Monad m) ⇒ String → (a → Bool) → a → m ()
- allDisjoint ∷ ∀ a. Ord a ⇒ [Set a] → Bool
- (......:) ∷ (y → z) → (x0 → x1 → x2 → x3 → x4 → x5 → x6 → y) → x0 → x1 → x2 → x3 → x4 → x5 → x6 → z
- (.....:) ∷ (y → z) → (x0 → x1 → x2 → x3 → x4 → x5 → y) → x0 → x1 → x2 → x3 → x4 → x5 → z
- (....:) ∷ (y → z) → (x0 → x1 → x2 → x3 → x4 → y) → x0 → x1 → x2 → x3 → x4 → z
- (...:) ∷ (y → z) → (x0 → x1 → x2 → x3 → y) → x0 → x1 → x2 → x3 → z
- (..:) ∷ (y → z) → (x0 → x1 → x2 → y) → x0 → x1 → x2 → z
- (.:) ∷ (y → z) → (x0 → x1 → y) → x0 → x1 → z
- pairFst ∷ Product f g a → f a
- pairSnd ∷ Product f g a → g a
- eitherToMaybe ∷ Either a b → Maybe b
- fib ∷ Word64 → Word64
- data Electric m a
- data Fuse m
- newtype FuseBlownException = FuseBlownException Text
- electric ∷ m a → Electric m a
- newFuse ∷ MonadMVar m ⇒ Text → m (Fuse m)
- withFuse ∷ (MonadThrow m, MonadMVar m) ⇒ Fuse m → Electric m a → m a
Type-level utility
class ShowProxy (p ∷ k) where Source #
Nothing
Instances
data Some (f ∷ k → Type) where Source #
Instances
Serialise (Some QueryAnytime) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Ledger.Query encode ∷ Some QueryAnytime → Encoding Source # decode ∷ Decoder s (Some QueryAnytime) Source # encodeList ∷ [Some QueryAnytime] → Encoding Source # decodeList ∷ Decoder s [Some QueryAnytime] Source # |
data SomePair (f ∷ k → Type) (g ∷ k → Type) where Source #
Pair of functors instantiated to the same existential
data SomeSecond f a where Source #
Hide the second type argument of some functor
SomeSecond f a
is isomorphic to Some (f a)
, but is more convenient in
partial applications.
SomeSecond ∷ !(f a b) → SomeSecond f a |
Instances
mustBeRight ∷ Either Void a → a Source #
Folding variations
nTimes ∷ ∀ a. (a → a) → Word64 → a → a Source #
Apply a function n times. The value of each application is forced.
nTimesM ∷ ∀ m a. Monad m ⇒ (a → m a) → Word64 → a → m a Source #
Apply a function n times through a monadic bind. The value of each application is forced.
repeatedly ∷ (a → b → b) → [a] → b → b Source #
repeatedlyM ∷ Monad m ⇒ (a → b → m b) → [a] → b → m b Source #
Lists
pickOne ∷ [a] → [([a], a, [a])] Source #
All possible ways to pick on element from a list, preserving order
pickOne [1,2,3] = [ ([], 1, [2, 3]) , ([1], 2, [3]) , ([1,2], 3, []) ]
split ∷ (a → Bool) → [a] → NonEmpty [a] Source #
Split a list given a delimiter predicate.
>>>
split (`elem` "xy") "axbyxc"
"a" :| ["b","","c"]
We have the laws
concat (split p as) === filter (not . p) as length (split p as) === length (filter p as) + 1
splits ∷ [a] → [([a], a, [a])] Source #
Focus on one element in the list
E.g.
splits [1..3] == [ ([] , 1 , [2,3]) , ([1] , 2 , [3] ) , ([1,2] , 3 , [] ) ]
takeUntil ∷ (a → Bool) → [a] → [a] Source #
Take items until the condition is true. If the condition is true for an item, include that item as the last item in the returned list. If the condition was never true, the original list is returned.
takeUntil (== 3) [1,2,3,4]
- 1,2,3
- > takeUntil (== 2) [0,1,0]
- 0,1,0
- > takeUntil (== 2) [2,2,3]
- 2
Safe variants of existing base functions
safeMaximum ∷ Ord a ⇒ [a] → Maybe a Source #
safeMaximumBy ∷ (a → a → Ordering) → [a] → Maybe a Source #
safeMaximumOn ∷ Ord b ⇒ (a → b) → [a] → Maybe a Source #
Hashes
hashFromBytesE ∷ ∀ h a. (HashAlgorithm h, HasCallStack) ⇒ ByteString → Hash h a Source #
Calls hashFromBytes
and throws an error if the input is of the wrong
length.
hashFromBytesShortE ∷ ∀ h a. (HashAlgorithm h, HasCallStack) ⇒ ShortByteString → Hash h a Source #
Calls hashFromBytesShort
and throws an error if the input is of the
wrong length.
Bytestrings
byteStringChunks ∷ Int → ByteString → [ByteString] Source #
lazyByteStringChunks ∷ Int → ByteString → [ByteString] Source #
Monadic utilities
whenJust ∷ Applicative f ⇒ Maybe a → (a → f ()) → f () Source #
Test code
checkThat ∷ (Show a, Monad m) ⇒ String → (a → Bool) → a → m () Source #
Assertion
Variation on assert
for use in testing code.
Sets
allDisjoint ∷ ∀ a. Ord a ⇒ [Set a] → Bool Source #
Check that a bunch of sets are all mutually disjoint
Composition
(......:) ∷ (y → z) → (x0 → x1 → x2 → x3 → x4 → x5 → x6 → y) → x0 → x1 → x2 → x3 → x4 → x5 → x6 → z Source #
Product
Miscellaneous
eitherToMaybe ∷ Either a b → Maybe b Source #
Electric code
An action that cannot be ran without drawing current through a Fuse
.
NOTE: using Fuse m -> ...
would suffice but the newtype wrapper is useful
for ensuring we don't make mistakes.
Instances
A simple semaphore, though instead of blocking a fatal exception is thrown.
Instances
Generic (Fuse m) Source # | |
NoThunks (StrictMVar m ()) ⇒ NoThunks (Fuse m) Source # | |
type Rep (Fuse m) Source # | |
Defined in Ouroboros.Consensus.Util type Rep (Fuse m) = D1 ('MetaData "Fuse" "Ouroboros.Consensus.Util" "ouroboros-consensus-0.21.0.0-inplace" 'False) (C1 ('MetaCons "Fuse" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (StrictMVar m ())))) |
newtype FuseBlownException Source #
Instances
Exception FuseBlownException Source # | |
Show FuseBlownException Source # | |
Defined in Ouroboros.Consensus.Util showsPrec ∷ Int → FuseBlownException → ShowS # show ∷ FuseBlownException → String # showList ∷ [FuseBlownException] → ShowS # |
withFuse ∷ (MonadThrow m, MonadMVar m) ⇒ Fuse m → Electric m a → m a Source #
Put full load on the Fuse
while the Electric
is running.
Thus any two withFuse
calls with the same Fuse
will throw one fatal
exception.
NOTE The metaphor is: when I run at most one waffle iron concurrently, my kitchen's fuse doesn't blow. But it blows if I run more than one waffle iron concurrently.
WARNING If the given action throws its own exception, then it will never stop
putting load on the Fuse
.