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

Zips two sequences by combining corresponding elements. More...

Functions

template<typename Seq2 , typename ResultSelector >
auto coveo::linq::zip (Seq2 &&seq2, ResultSelector &&result_sel) -> detail::zip_impl< Seq2, ResultSelector >
 Zips two sequences. More...
 

Detailed Description

The zip operator scans two source sequences and and passes elements with the same index to a result selector, then produces a sequence containing the results returned by that selector.

.NET equivalent: Zip

Function Documentation

◆ zip()

template<typename Seq2 , typename ResultSelector >
auto coveo::linq::zip ( Seq2 &&  seq2,
ResultSelector &&  result_sel 
) -> detail::zip_impl<Seq2, ResultSelector>

Scans two source sequences and calls the provided result selector with elements of the two sequences that have the same index. Then, produces a sequence of the results returned by that selector. The resulting sequence will be as long as the shortest of the two input sequences.

Use like this:

const int ONE[] = { 42, 23, 66, 11, 7 };
const int TWO[] = { 8, 21, 90, 4 };
using namespace coveo::linq;
auto seq = from(ONE)
| zip(TWO, [](int i, int j) { return i + j; });
// seq = { 50, 44, 156, 15 }
Parameters
seq2Second sequence to scan. The first sequence is the one to which the operator is applied, e.g. the one passed to coveo::linq::from().
result_selSelector used to "zip" two corresponding sequence elements.
Returns
(Once applied) Sequence containing zipped elements from the two sequences.