maybe package:streamly-core

Consume a single input and transform it using the supplied Maybe returning function. Pre-release
Map a Maybe returning function on the next element in the stream. The parser fails if the function returns Nothing otherwise returns the Just value.
>>> toEither = Maybe.maybe (Left "maybe: predicate failed") Right

>>> maybe f = Parser.either (toEither . f)
>>> maybe f = Parser.fromFoldMaybe "maybe: predicate failed" (Fold.maybe f)
Pre-release
A strict Maybe
Modify a fold to receive a Maybe input, the Just values are unwrapped and sent to the original fold, Nothing values are discarded.
>>> catMaybes = Fold.mapMaybe id

>>> catMaybes = Fold.filter isJust . Fold.lmap fromJust
mapMaybe f fold maps a Maybe returning function f on the input of the fold, filters out Nothing elements, and return the values extracted from Just.
>>> mapMaybe f = Fold.lmap f . Fold.catMaybes

>>> mapMaybe f = Fold.mapMaybeM (return . f)
>>> f x = if even x then Just x else Nothing

>>> fld = Fold.mapMaybe f Fold.toList

>>> Stream.fold fld (Stream.enumerateFromTo 1 10)
[2,4,6,8,10]
Use a Maybe returning fold as a filtering scan.
>>> scanMaybe p f = Fold.postscan p (Fold.catMaybes f)
Pre-release
In a stream of Maybes, discard Nothings and unwrap Justs.
>>> catMaybes = Stream.mapMaybe id

>>> catMaybes = fmap fromJust . Stream.filter isJust
Pre-release
Map a Maybe returning function to a stream, filter out the Nothing elements, and return a stream of values extracted from Just. Equivalent to:
>>> mapMaybe f = Stream.catMaybes . fmap f
Like mapMaybe but maps a monadic function. Equivalent to:
>>> mapMaybeM f = Stream.catMaybes . Stream.mapM f
>>> mapM f = Stream.mapMaybeM (\x -> Just <$> f x)
Use a filtering fold on a stream.
>>> scanMaybe f = Stream.catMaybes . Stream.postscan f
>>> mapMaybeM f = Fold.lmapM f . Fold.catMaybes
Convert strict Maybe' to lazy Maybe
Convert a Maybe returning fold to an error returning parser. The first argument is the error message that the parser would return when the fold returns Nothing. Pre-release
Write a stream of Maybe values. Keep buffering the just values in an array until a Nothing is encountered or the buffer size exceeds the specified limit, at that point flush the buffer to the handle. Pre-release