3.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. More... | |
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. More... | |
Functions | |
template<typename Arg , typename Function > | |
std::invoke_result_t< Function, fcppt::move_if_rvalue_type< Arg, fcppt::monad::inner_type< fcppt::type_traits::remove_cv_ref_t< Arg > > >> | fcppt::monad::bind (Arg &&_arg, Function const &_function) |
Monadic bind. More... | |
template<typename Value , typename... Lambdas> | |
auto | fcppt::monad::chain (Value &&_value, Lambdas const &... _lambdas) |
Chains multiple bind calls. More... | |
template<typename Type , typename Value > | |
fcppt::monad::constructor< Type, fcppt::type_traits::remove_cv_ref_t< Value >> | fcppt::monad::return_ (Value &&_value) |
Monadic return. More... | |
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>
.
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
.
|
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)
.
fcppt::monad::constructor< Type, fcppt::type_traits::remove_cv_ref_t< Value >> fcppt::monad::return_ | ( | Value && | _value | ) |
Monadic return.