4.4.1
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
fcppt.monad

Description

Monad typeclass and related functions.

Classes

struct  fcppt::monad::instance< Type >
 Used to implement a monad instance. More...
 

Typedefs

template<typename Type , typename Value >
using fcppt::monad::constructor = typename fcppt::monad::instance< Type >::template constructor< Value >::type
 Applies the constructor of a monad.
 
template<typename Type >
using fcppt::monad::inner_type = typename fcppt::monad::instance< Type >::template inner_type< Type >::type
 Extracts the type a monadic constructor was used with.
 

Functions

template<typename Arg , typename Function >
std::invoke_result_t< Function, fcppt::move_if_rvalue_type< Arg, fcppt::monad::inner_type< std::remove_cvref_t< Arg > > > > fcppt::monad::bind (Arg &&_arg, Function const &_function)
 Monadic bind.
 
template<typename Value , typename... Lambdas>
auto fcppt::monad::chain (Value &&_value, Lambdas const &..._lambdas)
 Chains multiple bind calls.
 
template<typename Value , typename... Lambdas>
auto fcppt::monad::do_ (Value &&_value, Lambdas const &..._lambdas)
 Do-notation for monads.
 
template<typename Type , typename Value >
fcppt::monad::constructor< Type, std::remove_cvref_t< Value > > fcppt::monad::return_ (Value &&_value)
 Monadic return.
 

Typedef Documentation

◆ constructor

template<typename Type , typename Value >
using fcppt::monad::constructor = typedef typename fcppt::monad::instance<Type>::template constructor<Value>::type

Applies the constructor of a monad.

Applies the constructor Type to Value.

For example, if Type=optional and Value=int then the result is optional<int>.

◆ inner_type

template<typename Type >
using fcppt::monad::inner_type = typedef typename fcppt::monad::instance<Type>::template inner_type<Type>::type

Extracts the type a monadic constructor was used with.

Becaused C++ lacks type inference, we need a special function to get a from m a.

Function Documentation

◆ bind()

template<typename Arg , typename Function >
std::invoke_result_t< Function, fcppt::move_if_rvalue_type< Arg, fcppt::monad::inner_type< std::remove_cvref_t< Arg > > > > fcppt::monad::bind ( Arg &&  _arg,
Function const &  _function 
)
inline

Monadic bind.

◆ chain()

template<typename Value , typename... Lambdas>
auto fcppt::monad::chain ( Value &&  _value,
Lambdas const &...  _lambdas 
)

Chains multiple bind calls.

Let Lambdas = l_1, ..., l_n. Calls bind(... bind(bind(_value,_l1),l_2) ... ,l_n).

◆ do_()

template<typename Value , typename... Lambdas>
auto fcppt::monad::do_ ( Value &&  _value,
Lambdas const &...  _lambdas 
)

Do-notation for monads.

◆ return_()

template<typename Type , typename Value >
fcppt::monad::constructor< Type, std::remove_cvref_t< Value > > fcppt::monad::return_ ( Value &&  _value)

Monadic return.