coveo::linq
Implementation of .NET-like LINQ operators in C++
Functions

Aggregates values in a sequence to produce a single value. More...

Functions

template<typename F >
auto coveo::linq::aggregate (const F &agg_f) -> detail::aggregate_impl_1< F >
 Aggregates values using an aggregation function. More...
 
template<typename Acc , typename F >
auto coveo::linq::aggregate (const Acc &seed, const F &agg_f) -> detail::aggregate_impl_2< Acc, F >
 Aggregates values using an aggregation function, starting with a seed. More...
 
template<typename Acc , typename F , typename RF >
auto coveo::linq::aggregate (const Acc &seed, const F &agg_f, const RF &result_f) -> detail::aggregate_impl_3< Acc, F, RF >
 Aggregates values using aggregation function, seed and result selector. More...
 

Detailed Description

The aggregate operator, as its name implies, can be used to aggregate all values in a sequence into a single value. To achieve this, it needs an aggregation function that will be called repeatedly to add each element in the sequence to the aggregate.

This is a terminal operator.

.NET equivalent: Aggregate

Function Documentation

◆ aggregate() [1/3]

template<typename F >
auto coveo::linq::aggregate ( const F &  agg_f) -> detail::aggregate_impl_1<F>

Aggregates all elements in a sequence by repeatedly calling an aggregation function. The function receives two parameters: the current aggregate value, and the sequence element to add. The function must then add the element to the aggregate and return a new aggregate value. On the first call, the aggregate value is the first sequence element.

Does not work on empty sequences.

Use like this:

const int NUMS[] = { 42, 23, 66 };
using namespace coveo::linq;
auto agg = from(NUMS)
| aggregate([](int so_far, int i) { return so_far + i; });
// agg == 131
Parameters
agg_fAggregation function.
Returns
(Once applied) Final aggregate value.
Exceptions
coveo::linq::empty_sequenceThe sequence contains no elements.

◆ aggregate() [2/3]

template<typename Acc , typename F >
auto coveo::linq::aggregate ( const Acc &  seed,
const F &  agg_f 
) -> detail::aggregate_impl_2<Acc, F>

Aggregates all elements in a sequence by repeatedly calling an aggregation function. The function receives two parameters: the current aggregate value, and the sequence element to add. The function must then add the element to the aggregate and return a new aggregate value. On the first call, the aggregate value is equal to the provided seed.

Use like this:

const int NUMS[] = { 42, 23, 66 };
using namespace coveo::linq;
auto agg = from(NUMS)
| aggregate(11,
[](int so_far, int i) { return so_far + i; });
// agg == 142
Parameters
seedInitial aggregate value.
agg_fAggregation function.
Returns
(Once applied) Final aggregate value.

◆ aggregate() [3/3]

template<typename Acc , typename F , typename RF >
auto coveo::linq::aggregate ( const Acc &  seed,
const F &  agg_f,
const RF &  result_f 
) -> detail::aggregate_impl_3<Acc, F, RF>

Aggregates all elements in a sequence by repeatedly calling an aggregation function. The function receives two parameters: the current aggregate value, and the sequence element to add. The function must then add the element to the aggregate and return a new aggregate value. On the first call, the aggregate value is equal to the provided seed. Once the final aggregate value is computed, it is passed to a result selector to produce a final value to return.

Use like this:

const int NUMS[] = { 42, 23, 66 };
using namespace coveo::linq;
auto agg = from(NUMS)
| aggregate(11,
[](int so_far, int i) { return so_far + i; },
[](int so_far) { return so_far / 2; });
// agg == 71
Parameters
seedInitial aggregate value.
agg_fAggregation function.
result_fFunction used to produce final result from aggregate.
Returns
(Once applied) Result returned by result_f.