{-# LANGUAGE Safe #-}{- |Module : Relude.MonadCopyright : (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikSPDX-License-Identifier : MITMaintainer : Kowainik <xrom.xkov@gmail.com>Stability : StablePortability : PortableReexporting useful monadic stuff.-}module Relude.Monad ( module Relude.Monad.Reexport -- $reexport , module Relude.Monad.Maybe -- $maybe , module Relude.Monad.Either -- $either , module Relude.Monad.Trans -- $trans , chainedTo , infinitely ) whereimport Relude.Monad.Eitherimport Relude.Monad.Maybeimport Relude.Monad.Reexportimport Relude.Monad.Transimport Control.Applicative (Applicative)import Relude.Base (Void)-- $setup-- >>> import Relude{- | 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-}chainedTo :: Monad m => (a -> m b) -> m a -> m bchainedTo = (=<<){-# INLINE chainedTo #-}{- | Repeat a monadic action indefinitely.This is a more type safe version of 'forever', which has a convenientbut unsafe type.Consider the following two examples. In the @getIntForever@ functions, itfalsely expects 'Int' as the result of the 'forever' function. But it would needto wait *forever* to get that, and this mistake won't be caught by the typesystem and compiler:@getIntForever :: IO IntgetIntForever = do i <- forever $ do ... pure i@In contrast, using 'infinitely' instead of 'forever' in 'foo' is a type error.@since 1.0.0.0-}infinitely :: Applicative f => f a -> f Voidinfinitely = forever{-# INLINE infinitely #-}{- $reexportReexports functions to work with different monads.-}{- $maybeProvided new combinators to work with 'Relude.Maybe' data type.-}{- $eitherProvided new combinators to work with 'Relude.Either' data type.-}{- $transMonad transformers functions and combinators.-}