3 Forward declares `boost::hana::monadic_compose`.
5 @copyright Louis Dionne 2013-2016
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_FWD_MONADIC_COMPOSE_HPP
11 #define BOOST_HANA_FWD_MONADIC_COMPOSE_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
17 BOOST_HANA_NAMESPACE_BEGIN
18 //! Composition of monadic functions.
19 //! @ingroup group-Monad
21 //! Given two monadic functions `f` and `g`, `monadic_compose` returns
22 //! a new function equivalent to the composition of `f` with `g`, except
23 //! the result of `g` is `chain`ed into `f` instead of simply passed to
24 //! it, as with normal composition. `monadic_compose` satisfies
26 //! monadic_compose(f, g)(x) == chain(g(x), f)
31 //! Unlike `compose`, `monadic_compose` does not generalize nicely to
32 //! arities higher than one. Hence, only unary functions may be used
33 //! with `monadic_compose`.
38 //! Given a `Monad` `M` and two functions @f$ f : B \to M(C) @f$ and
39 //! @f$ g : A \to M(B) @f$, the signature is
41 //! \mathtt{monadic\_compose}
42 //! : (B \to M(C)) \times (A \to M(B)) \to (A \to M(C))
46 //! A monadic function with signature @f$ B \to M(C) @f$.
49 //! A monadic function with signature @f$ A \to M(B) @f$.
53 //! This method is not tag-dispatched, so it can't be customized directly.
58 //! @include example/monadic_compose.cpp
59 #ifdef BOOST_HANA_DOXYGEN_INVOKED
60 constexpr auto monadic_compose = [](auto&& f, auto&& g) {
61 return [perfect-capture](auto&& x) -> decltype(auto) {
62 return hana::chain(forwarded(g)(forwarded(x)), forwarded(f));
66 struct monadic_compose_t {
67 template <typename F, typename G>
68 constexpr auto operator()(F&& f, G&& g) const;
71 constexpr monadic_compose_t monadic_compose{};
73 BOOST_HANA_NAMESPACE_END
75 #endif // !BOOST_HANA_FWD_MONADIC_COMPOSE_HPP