Handling Custom Returns in C++

The C++ API allows users to return custom objects from their workflows.

To do so, the user must create a functor object which overloads the operator() function. Lemon provides two implementations for C++ streams (such as std::cout) and associative arrays (such as std::map). These two examples are given below to guide users in the creation of their own custom functors for new types. It is recommended that the user use C++ templates to obtain the most flexible implementations.

struct lemon::print_combine

Functor to stream workflow results to an ostream object

This is a template functor which streams workflow results to a collector. This class is typically used to stream text results from workflows to the std::cout object. Any class which derives from std::ostream is supported.

Public Functions

print_combine(std::ostream &collector)

Construct a print_combine which streams results to collector.

This contructor will create a print_combine object which streams results to collector. This argument must derive from the std::ostream class and therefore provide an overload to the << operator. Common examples of collector are std::cout and friends. All workflow results are streamed to the collect after all entries have been evaluated.

Parameters
  • collector: An object for each workflow objects will be streamed to

template<typename Map1>
struct lemon::map_combine

Functor to combine the results of a workflow into a map

This is a template functor which opens combines the results of a workflow into a single map object. Use this class only when the work flow returns a map oject or other type of associative array.

Public Functions

map_combine(Map1 &collector)

Construct a map_combine class which fills the collector

This constructor will copy all results to the collector object. This operation is performed when the workflow completes for all entries.

Parameters
  • collector: A map like object to store results in.

template<typename Map2 = Map1>
void operator()(const Map2 &map2) const

Add a map to the current collector.

Python alternative

This feature is under current development for the Python API, but is not yet supported. Instead, users should store the results of their workflows in the self object and rely on the finalize function to analyze the result.