Copyright | disco team and contributors |
---|---|
License | BSD-3-Clause |
Maintainer | [email protected] |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Disco.Util
Description
Miscellaneous utilities.
Synopsis
- (==>) :: a -> b -> (a, b)
- for :: [a] -> (a -> b) -> [b]
- (!) :: (Show k, Ord k) => Map k v -> k -> v
- maximum0 :: (Num a, Ord a) => [a] -> a
- filterNE :: (a -> Bool) -> NonEmpty a -> Maybe (NonEmpty a)
- partitionNE :: (a -> Bool) -> NonEmpty a -> (Maybe (NonEmpty a), Maybe (NonEmpty a))
- partitionEithersNE :: NonEmpty (Either a b) -> Either (NonEmpty a) ([a], NonEmpty b)
- iterUntil :: (a -> a) -> (a -> Maybe b) -> a -> b
- gate :: Alternative f => (a -> Bool) -> a -> f a
Documentation
(==>) :: a -> b -> (a, b) infixr 1 Source #
A synonym for pairing which makes convenient syntax for constructing literal maps via M.fromList.
(!) :: (Show k, Ord k) => Map k v -> k -> v Source #
A variant of Map
indexing that throws a custom error message
in case the key is not found, to help with debugging.
maximum0 :: (Num a, Ord a) => [a] -> a Source #
Find the maximum of a list of positive numbers, yielding 0 in the case of an empty list.
filterNE :: (a -> Bool) -> NonEmpty a -> Maybe (NonEmpty a) Source #
A variant of filter
that returns a Maybe (NonEmpty a)
instead
of a regular list.
partitionNE :: (a -> Bool) -> NonEmpty a -> (Maybe (NonEmpty a), Maybe (NonEmpty a)) Source #
A variant of partition
that returns Maybe (NonEmpty a)
s instead
of regular lists.
partitionEithersNE :: NonEmpty (Either a b) -> Either (NonEmpty a) ([a], NonEmpty b) Source #
A variant of partitionEithers
for nonempty lists. If the
result is Left, it means all the inputs were Left. If the result
is Right, we definitely have some Rights, and possibly some Lefts
as well. This properly encodes the fact that at least one result
list must be nonempty.
iterUntil :: (a -> a) -> (a -> Maybe b) -> a -> b Source #
Iterate a function until finding the first value that satisfies
the given predicate. iterUntil f p
is equivalent to head
. filter p . iterate f
but does not trigger a partiality
warning.
gate :: Alternative f => (a -> Bool) -> a -> f a Source #
Allow a value through only if it satisfies the given predicate.