Callable object performing a tree-like reduction of all elements of a product type. The given map function is applied before excution the reduction to each element of the input.
On record types, this function operates on the underlying values, not on the fields themselves.
- Note
- For associative operations, this produces the same result as a left or right fold preceeded by map, but have different intermediate evaluation order.
inline constexpr
#include <kumi/algorithm/reduce.hpp>
template<typename Function, monoid M, product_type T>
constexpr auto map_reduce(Function f, M && m, T && t);
constexpr map_reduce_t map_reduce
Callable object performing a tree-like reduction of all elements of a product type....
Definition reduce.hpp:307
template<typename Function, monoid M, product_type T, typename V>
constexpr auto reduce(Function f, M && m, T && t, V init);
constexpr reduce_t reduce
Callable object performing a tree-like reduction of all elements of a product type.
Definition reduce.hpp:232
- f: Mapping function to apply
- m: Monoid callable function to apply
- t: Product Type to reduce
- init: Optional initial value of the reduction.
The result of reducing the elements of `t` by `m` after beeing processed by `f`,
recursively combining elements in a tree structure.
namespace kumi::result
{
template<mono
id M, product_type T>
struct map_reduce;
template<monoid M, product_type T>
template<mono
id M, product_type T,
typename Value>
struct map_reduce;
template<monoid M, product_type T, typename Value>
}
Computes the return type of a call to kumi::map_reduce
#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
auto times_two = [&](auto e){ return 2*e; };
auto is_pair = [&](auto e){ return e%2==0; };
}
constexpr kumi::function::numeric_add plus
Forms a binary monoid callable that can be used in kumi::algoritm. It represents the addition.
Definition monoid.hpp:134
constexpr kumi::function::numeric_prod multiplies
Forms a binary monoid callable that can be used in kumi::algoritm. It represents the multiplication.
Definition monoid.hpp:143
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33
#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto r1 =
kumi::record{
"a"_id = 2.,
"b"_id = 5,
"c"_id =
short{3},
"d"_id =
'\4'};
auto r2 =
kumi::record{
"a"_id = 2 ,
"b"_id = 1,
"c"_id =
short{55},
"d"_id =
' '};
auto times_two = [&](auto e){ return 2*e; };
auto is_pair = [&](auto e){ return e%2==0; };
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36