disco-0.2: Functional programming language for teaching discrete math.
Copyrightdisco team and contributors
LicenseBSD-3-Clause
Maintainer[email protected]
Safe HaskellSafe-Inferred
LanguageHaskell2010

Disco.Util

Description

Miscellaneous utilities.

Synopsis

Documentation

(==>) :: a -> b -> (a, b) infixr 1 Source #

A synonym for pairing which makes convenient syntax for constructing literal maps via M.fromList.

for :: [a] -> (a -> b) -> [b] Source #

Flipped variant of map.

(!) :: (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.