Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:53:04

0001 /*!
0002 @file
0003 Forward declares `boost::hana::monadic_compose`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_FWD_MONADIC_COMPOSE_HPP
0011 #define BOOST_HANA_FWD_MONADIC_COMPOSE_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/core/when.hpp>
0015 
0016 
0017 namespace boost { namespace hana {
0018     //! Composition of monadic functions.
0019     //! @ingroup group-Monad
0020     //!
0021     //! Given two monadic functions `f` and `g`, `monadic_compose` returns
0022     //! a new function equivalent to the composition of `f` with `g`, except
0023     //! the result of `g` is `chain`ed into `f` instead of simply passed to
0024     //! it, as with normal composition. `monadic_compose` satisfies
0025     //! @code
0026     //!     monadic_compose(f, g)(x) == chain(g(x), f)
0027     //! @endcode
0028     //!
0029     //!
0030     //! @note
0031     //! Unlike `compose`, `monadic_compose` does not generalize nicely to
0032     //! arities higher than one. Hence, only unary functions may be used
0033     //! with `monadic_compose`.
0034     //!
0035     //!
0036     //! Signature
0037     //! ---------
0038     //! Given a `Monad` `M` and two functions @f$ f : B \to M(C) @f$ and
0039     //! @f$ g : A \to M(B) @f$, the signature is
0040     //! @f$
0041     //!     \mathtt{monadic\_compose}
0042     //!         : (B \to M(C)) \times (A \to M(B)) \to (A \to M(C))
0043     //! @f$.
0044     //!
0045     //! @param f
0046     //! A monadic function with signature @f$ B \to M(C) @f$.
0047     //!
0048     //! @param g
0049     //! A monadic function with signature @f$ A \to M(B) @f$.
0050     //!
0051     //!
0052     //! @note
0053     //! This method is not tag-dispatched, so it can't be customized directly.
0054     //!
0055     //!
0056     //! Example
0057     //! -------
0058     //! @include example/monadic_compose.cpp
0059 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0060     constexpr auto monadic_compose = [](auto&& f, auto&& g) {
0061         return [perfect-capture](auto&& x) -> decltype(auto) {
0062             return hana::chain(forwarded(g)(forwarded(x)), forwarded(f));
0063         };
0064     };
0065 #else
0066     struct monadic_compose_t {
0067         template <typename F, typename G>
0068         constexpr auto operator()(F&& f, G&& g) const;
0069     };
0070 
0071     BOOST_HANA_INLINE_VARIABLE constexpr monadic_compose_t monadic_compose{};
0072 #endif
0073 }} // end namespace boost::hana
0074 
0075 #endif // !BOOST_HANA_FWD_MONADIC_COMPOSE_HPP