Maybe package:hedgehog

The Maybe type encapsulates an optional value. A value of type Maybe a either contains a value of type a (represented as Just a), or it is empty (represented as Nothing). Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error. The Maybe type is also a monad. It is a simple kind of error monad, where all errors are represented by Nothing. A richer error monad can be built using the Either type.
Generates a Nothing some of the time.
The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.

Examples

Basic usage:
>>> maybe False odd (Just 3)
True
>>> maybe False odd Nothing
False
Read an integer from a string using readMaybe. If we succeed, return twice the integer; that is, apply (*2) to it. If instead we fail to parse an integer, return 0 by default:
>>> import Text.Read ( readMaybe )

>>> maybe 0 (*2) (readMaybe "5")
10

>>> maybe 0 (*2) (readMaybe "")
0
Apply show to a Maybe Int. If we have Just n, we want to show the underlying Int n. But if we have Nothing, we return the empty string instead of (for example) "Nothing":
>>> maybe "" show (Just 5)
"5"

>>> maybe "" show Nothing
""
Fails the test if the Maybe is Nothing, otherwise returns the value in the Just.
Fails the test if the action throws an exception, or if the Maybe is Nothing, otherwise returns the value in the Just.
Generates a value which is the result of the given function returning a Just. The original generator's shrink tree will be retained, with values returning Nothing removed. Subsequent shrinks of those values will be retained. Compared to mapMaybeT, shrinking may be slower but will be optimal. It's possible that the function will never return Just, or will only do so a larger size than we're currently running at. To avoid looping forever, we limit the number of retries, and grow the size with each retry. If we retry too many times then the whole generator is discarded.
Generates a value which is the result of the given function returning a Just. The original generator's shrink tree will be retained, with values returning Nothing removed. Subsequent shrinks of those values will be retained. Compared to mapMaybeT, shrinking may be slower but will be optimal. The type is also more general, because the shrink behavior from mapMaybe would force the entire shrink tree to be evaluated when applied to an impure tree. It's possible that the function will never return Just, or will only do so a larger size than we're currently running at. To avoid looping forever, we limit the number of retries, and grow the size with each retry. If we retry too many times then the whole generator is discarded.
Lift a predefined shrink tree in to a generator, ignoring the seed and the size.
Lift a predefined shrink tree in to a generator, ignoring the seed and the size.
Takes a tree of Maybes and returns a tree of all the Just values. If the root of the tree is Nothing then Nothing is returned.
Returns a tree containing only elements that match the predicate. If the root of the tree does not match the predicate then Nothing is returned.