3 Forward declares `boost::hana::unfold_right`.
5 @copyright Louis Dionne 2013-2017
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_UNFOLD_RIGHT_HPP
11 #define BOOST_HANA_FWD_UNFOLD_RIGHT_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
17 BOOST_HANA_NAMESPACE_BEGIN
18 //! Dual operation to `fold_right` for sequences.
19 //! @ingroup group-Sequence
21 //! While `fold_right` reduces a structure to a summary value from the
22 //! right, `unfold_right` builds a sequence from a seed value and a
23 //! function, starting from the right.
28 //! Given a `Sequence` `S`, an initial value `state` of tag `I`, an
29 //! arbitrary Product `P` and a function \f$ f : I \to P(T, I) \f$,
30 //! `unfold_right<S>` has the following signature:
32 //! \mathtt{unfold\_right}_S : I \times (I \to P(T, I)) \to S(T)
36 //! The tag of the sequence to build up.
39 //! An initial value to build the sequence from.
42 //! A function called as `f(state)`, where `state` is an initial value,
44 //! 1. `nothing` if it is done producing the sequence.
45 //! 2. otherwise, `just(make<P>(x, state))`, where `state` is the new
46 //! initial value used in the next call to `f`, `x` is an element to
47 //! be prepended to the resulting sequence, and `P` is an arbitrary
53 //! In some cases, `unfold_right` can undo a `fold_right` operation:
55 //! unfold_right<S>(fold_right(xs, state, f), g) == xs
58 //! if the following holds
60 //! g(f(x, y)) == just(make_pair(x, y))
61 //! g(state) == nothing
67 //! @include example/unfold_right.cpp
68 #ifdef BOOST_HANA_DOXYGEN_INVOKED
70 constexpr auto unfold_right = [](auto&& state, auto&& f) {
71 return tag-dispatched;
74 template <typename S, typename = void>
75 struct unfold_right_impl : unfold_right_impl<S, when<true>> { };
78 struct unfold_right_t;
81 constexpr unfold_right_t<S> unfold_right{};
83 BOOST_HANA_NAMESPACE_END
85 #endif // !BOOST_HANA_FWD_UNFOLD_RIGHT_HPP