MayaFlux 1.0.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 344 of file OperationChain.hpp.

345 {
346 if (!m_successful) {
347 error<std::runtime_error>(
349 std::source_location::current(),
350 "Cannot continue chain after failed operation in apply");
351 }
352
353 using ResultType = std::invoke_result_t<Func, const DataType&>;
354
355 try {
356 auto result = std::forward<Func>(func)(m_data.data);
357 auto next = FluentExecutor<Executor, ResultType>(
358 m_executor, Datum<ResultType>(std::move(result)));
359 next.m_operation_history = m_operation_history;
360 next.m_operation_history.push_back("custom_function");
361 return next;
362 } catch (const std::exception& e) {
363 m_successful = false;
364 record_error(std::string("Custom function failed: ") + e.what());
367 std::source_location::current(),
368 "Exception in custom function: " + std::string(e.what()));
369 }
370 }
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:27