3 Forward declares `boost::hana::unfold_left`.
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_UNFOLD_LEFT_HPP
11 #define BOOST_HANA_FWD_UNFOLD_LEFT_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
17 BOOST_HANA_NAMESPACE_BEGIN
18 //! Dual operation to `fold_left` for sequences.
19 //! @ingroup group-Sequence
21 //! While `fold_left` reduces a structure to a summary value from the left,
22 //! `unfold_left` builds a sequence from a seed value and a function,
23 //! starting from the left.
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(I, T) \f$,
30 //! `unfold_left<S>` has the following signature:
32 //! \mathtt{unfold\_left}_S : I \times (I \to P(I, T)) \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>(state, x))`, where `state` is the new
46 //! initial value used in the next call to `f`, `x` is an element to
47 //! be appended to the resulting sequence, and `P` is an arbitrary
53 //! In some cases, `unfold_left` can undo a `fold_left` operation:
55 //! unfold_left<S>(fold_left(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_left.cpp
68 #ifdef BOOST_HANA_DOXYGEN_INVOKED
70 constexpr auto unfold_left = [](auto&& state, auto&& f) {
71 return tag-dispatched;
74 template <typename S, typename = void>
75 struct unfold_left_impl : unfold_left_impl<S, when<true>> { };
81 constexpr unfold_left_t<S> unfold_left{};
83 BOOST_HANA_NAMESPACE_END
85 #endif // !BOOST_HANA_FWD_UNFOLD_LEFT_HPP