4.6.0
Freundlich's C++ toolkit
|
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. | |
using fcppt::monad::constructor = 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>
.
using fcppt::monad::inner_type = 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
.
|
inline |
Monadic bind.
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)
.
auto fcppt::monad::do_ | ( | Value && | _value, |
Lambdas const &... | _lambdas ) |
Do-notation for monads.
fcppt::monad::constructor< Type, std::remove_cvref_t< Value > > fcppt::monad::return_ | ( | Value && | _value | ) |
Monadic return.