relude-1.2.0.0: Safe, performant, user-friendly and lightweight Haskell Standard Library
Copyright(c) 2016 Stephen Diehl
(c) 2016-2018 Serokell
(c) 2018-2023 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
StabilityStable
PortabilityPortable
Safe HaskellSafe
LanguageHaskell2010

Relude.Monad

Description

Reexporting useful monadic stuff.

Synopsis

Documentation

Reexports functions to work with different monads.

Provided new combinators to work with Maybe data type.

Provided new combinators to work with Either data type.

Monad transformers functions and combinators.

chainedTo :: Monad m => (a -> m b) -> m a -> m b Source #

For chaining monadic operations in forward applications using (&) Named version of =<<.

>>> Just [ 1 :: Int ] & chainedTo (viaNonEmpty head)
Just 1
>>> Nothing & chainedTo (viaNonEmpty head)
Nothing

Since: 0.5.0

infinitely :: Applicative f => f a -> f Void Source #

Repeat a monadic action indefinitely.

This is a more type safe version of forever, which has a convenient but unsafe type.

Consider the following two examples. In the getIntForever functions, it falsely expects Int as the result of the forever function. But it would need to wait *forever* to get that, and this mistake won't be caught by the type system and compiler:

getIntForever :: IO Int
getIntForever = do
    i <- forever $ do ...
    pure i

In contrast, using infinitely instead of forever in foo is a type error.

Since: 1.0.0.0