6#ifndef GIMO_PIPELINE_HPP
7#define GIMO_PIPELINE_HPP
28 template <
typename... Steps>
31 template <
typename... Others>
40 explicit constexpr Pipeline(std::tuple<Steps...> steps)
41 : m_Steps{std::move(steps)}
51 template <nullable Nullable>
52 constexpr auto apply(Nullable&& opt) &
54 return apply(*
this, std::forward<Nullable>(opt));
60 template <nullable Nullable>
61 constexpr auto apply(Nullable&& opt)
const&
63 return apply(*
this, std::forward<Nullable>(opt));
69 template <nullable Nullable>
70 constexpr auto apply(Nullable&& opt) &&
72 return apply(std::move(*
this), std::forward<Nullable>(opt));
78 template <nullable Nullable>
79 constexpr auto apply(Nullable&& opt)
const&&
81 return apply(std::move(*
this), std::forward<Nullable>(opt));
89 template <
typename... SuffixSteps>
92 return append(*
this, std::move(suffix.m_Steps));
98 template <
typename... SuffixSteps>
101 return append(std::move(*
this), std::move(suffix.m_Steps));
109 template <
typename... SuffixSteps>
113 return prefix.
append(std::move(suffix));
119 template <
typename... SuffixSteps>
123 return std::move(prefix).append(std::move(suffix));
127 std::tuple<Steps...> m_Steps{};
129 template <
typename Self,
typename Nullable>
131 static constexpr auto apply(Self&& self, Nullable&& opt)
134 [&]<
typename First,
typename... Others>(First&& first, Others&&... steps) {
136 std::forward<First>(first),
137 std::forward<Nullable>(opt),
138 std::forward<Others>(steps)...);
140 std::forward<Self>(self).m_Steps);
143 template <
typename Self,
typename... SuffixSteps>
145 static constexpr auto append(Self&& self, std::tuple<SuffixSteps...>&& suffixSteps)
147 using Appended =
Pipeline<Steps..., SuffixSteps...>;
150 std::tuple_cat(std::forward<Self>(self).m_Steps, std::move(suffixSteps))};
156 template <
typename T>
158 :
public std::false_type
162 template <
typename... Steps>
163 struct is_pipeline<Pipeline<Steps...>>
164 :
public std::true_type
173 template <
typename T>
174 concept pipeline = detail::is_pipeline<std::remove_cvref_t<T>>::value;
185 template <nullable Nullable, pipeline Pipeline>
189 return std::forward<Pipeline>(steps).apply(std::forward<Nullable>(opt));
194 template <
typename Nullable,
typename ConstRefSource,
typename... Steps>
195 struct is_processable_by_impl
196 :
public std::bool_constant<0u == sizeof...(Steps)>
200 template <
typename Nullable,
typename ConstRefSource,
typename First,
typename... Rest>
201 requires applicable_to<Nullable, const_ref_like_t<ConstRefSource, First>>
202 struct is_processable_by_impl<Nullable, ConstRefSource, First, Rest...>
203 :
public is_processable_by_impl<
204 std::invoke_result_t<const_ref_like_t<ConstRefSource, First>, Nullable>,
210 template <
typename Nullable,
typename Pipeline,
typename StepList = std::remove_cvref_t<Pipeline>>
211 struct is_processable_by;
213 template <
typename Nullable,
typename ConstRefSource,
typename... Steps>
214 struct is_processable_by<Nullable, ConstRefSource, Pipeline<Steps...>>
215 :
public is_processable_by_impl<Nullable, ConstRefSource, Steps...>
225 template <
typename Nullable,
typename Pipeline>
228 && detail::is_processable_by<Nullable, Pipeline>::value;
constexpr Pipeline(std::tuple< Steps... > steps)
Constructs a pipeline from a tuple of steps.
Definition Pipeline.hpp:40
friend constexpr auto operator|(Pipeline &&prefix, Pipeline< SuffixSteps... > suffix)
Appends the right-hand-side pipeline to the end of the left-hand-side pipeline.
Definition Pipeline.hpp:121
constexpr auto apply(Nullable &&opt) const &
Applies nullable input on the pipeline.
Definition Pipeline.hpp:61
constexpr auto append(Pipeline< SuffixSteps... > suffix) const &
Appends another pipeline to the end of this one.
Definition Pipeline.hpp:90
friend constexpr auto operator|(Pipeline const &prefix, Pipeline< SuffixSteps... > suffix)
Appends the right-hand-side pipeline to the end of the left-hand-side pipeline.
Definition Pipeline.hpp:111
constexpr auto apply(Nullable &&opt, Pipeline &&steps)
Applies nullable input on the pipeline.
Definition Pipeline.hpp:187
constexpr auto apply(Nullable &&opt) &&
Applies nullable input on the pipeline.
Definition Pipeline.hpp:70
constexpr auto apply(Nullable &&opt) const &&
Applies nullable input on the pipeline.
Definition Pipeline.hpp:79
constexpr auto append(Pipeline< SuffixSteps... > suffix) &&
Appends another pipeline to the end of this one.
Definition Pipeline.hpp:99
constexpr auto apply(Nullable &&opt) &
Applies nullable input on the pipeline.
Definition Pipeline.hpp:52
friend class Pipeline
Definition Pipeline.hpp:32
Concept describing a type that can be used as a monad in the pipeline.
Definition Common.hpp:200
Checks whether the given type is a specialization of gimo::Pipeline.
Definition Pipeline.hpp:174
Evaluates whether a Nullable type can be processed by the entire pipeline.
Definition Pipeline.hpp:226
Definition AndThen.hpp:21