MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ apply()

template<typename Executor , ComputeData DataType>
template<typename Func >
requires std::invocable<Func, const DataType&>
auto MayaFlux::Yantra::FluentExecutor< Executor, DataType >::apply ( Func &&  func)
inline

Apply a custom transformation function within the chain.

func receives the raw DataType (not the Datum) and returns a value of any ComputeData type. The result is immediately wrapped in a fresh Datum. Container from the current Datum is not carried forward since the function may change the data type entirely; attach a container explicitly via tap() before apply() if it must survive.

Template Parameters
FuncCallable type: (const DataType&) -> U
Parameters
funcTransformation to apply
Returns
New FluentExecutor whose DataType is the return type of func

Definition at line 224 of file OperationChain.hpp.

225 {
226 if (!m_successful) {
227 error<std::runtime_error>(
229 std::source_location::current(),
230 "Cannot continue chain after failed operation in apply");
231 }
232
233 using ResultType = std::invoke_result_t<Func, const DataType&>;
234
235 try {
236 auto result = std::forward<Func>(func)(m_data.data);
237 auto next = FluentExecutor<Executor, ResultType>(
238 m_executor, Datum<ResultType>(std::move(result)));
239 next.m_operation_history = m_operation_history;
240 next.m_operation_history.push_back("custom_function");
241 return next;
242 } catch (const std::exception& e) {
243 m_successful = false;
244 record_error(std::string("Custom function failed: ") + e.what());
247 std::source_location::current(),
248 "Exception in custom function: " + std::string(e.what()));
249 }
250 }
void record_error(const std::string &err)
std::shared_ptr< Executor > m_executor
std::vector< std::string > m_operation_history
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP)
void error_rethrow(Component component, Context context, std::source_location location=std::source_location::current(), std::string_view additional_context="")
Catch and log an exception, then rethrow it.
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
T data
The actual computation data.
Definition DataIO.hpp:25