]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Forward declares `boost::hana::chain`. | |
4 | ||
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) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_FWD_CHAIN_HPP | |
11 | #define BOOST_HANA_FWD_CHAIN_HPP | |
12 | ||
13 | #include <boost/hana/config.hpp> | |
14 | #include <boost/hana/core/when.hpp> | |
15 | ||
16 | ||
17 | BOOST_HANA_NAMESPACE_BEGIN | |
18 | //! Feed a monadic value into a monadic computation. | |
19 | //! @ingroup group-Monad | |
20 | //! | |
21 | //! Given a monadic value and a monadic function, `chain` feeds the | |
22 | //! monadic value into the function, thus performing some Monad-specific | |
23 | //! effects, and returns the result. An implementation of `chain` must | |
24 | //! satisfy | |
25 | //! @code | |
26 | //! chain(xs, f) == flatten(transform(xs, f)) | |
27 | //! @endcode | |
28 | //! | |
29 | //! | |
30 | //! Signature | |
31 | //! --------- | |
32 | //! For a monad `M`, given a monadic value of type `M(A)` and a monadic | |
33 | //! function @f$ f : A \to M(B) @f$, `chain` has the signature | |
34 | //! @f$ | |
35 | //! \mathtt{chain} : M(A) \times (A \to M(B)) \to M(B) | |
36 | //! @f$. | |
37 | //! | |
38 | //! @param xs | |
39 | //! A monadic value to be fed to the function `f`. | |
40 | //! | |
41 | //! @param f | |
42 | //! A function taking a normal value in the `xs` structure, and returning | |
43 | //! a monadic value. This function is called as `f(x)`, where `x` is an | |
44 | //! element of the structure `xs`. | |
45 | //! | |
46 | //! | |
47 | //! Example | |
48 | //! ------- | |
49 | //! @include example/chain.cpp | |
50 | #ifdef BOOST_HANA_DOXYGEN_INVOKED | |
51 | constexpr auto chain = [](auto&& xs, auto&& f) -> decltype(auto) { | |
52 | return tag-dispatched; | |
53 | }; | |
54 | #else | |
55 | template <typename M, typename = void> | |
56 | struct chain_impl : chain_impl<M, when<true>> { }; | |
57 | ||
58 | struct chain_t { | |
59 | template <typename Xs, typename F> | |
60 | constexpr decltype(auto) operator()(Xs&& xs, F&& f) const; | |
61 | }; | |
62 | ||
63 | constexpr chain_t chain{}; | |
64 | #endif | |
65 | BOOST_HANA_NAMESPACE_END | |
66 | ||
67 | #endif // !BOOST_HANA_FWD_CHAIN_HPP |