equiZip()

The equiZip linq operator returns a new linq object that contains the elements of the collection "zipped-up" with the elements of the "second" collection such that each value of the returned collection is a projection based upon the corresponding values of the originating and the second collections.

If the size of the originating collection and the second collection are not equal, then an exception will be thrown.
var arr1 = ['a', 'b', 'c', 'd', 'e'];
var arr2 = [1, 2, 3, 4, 5];

// col1 = ['a1', 'b2', 'c3', 'd4', 'e5']
var col1 = $linq(arr1).equiZip(arr2, "(x, y) => x + y").toArray();

// this will throw an exception since the two collections are not the same size
var col2 = $linq(arr1)
    .take(3)
    .equiZip(arr2, "(x, y) => {letter: x, number: y}")
    .toArray();

zipLongest()

The zipLongest linq operator returns a new linq object that contains the elements of the collection "zipped-up" with the elements of the "second" collection such that each value of the returned collection is a projection based upon the corresponding values of the originating and the second collections.

The zipLongest operator also takes two parameters ("defaultForFirst" and "defaultForSecond") that are used if the size of the originating collection and the second collection are not equal. If they are not equal, then the shorter of the collections will be augmented with its corresponding "default" value.
var arr1 = ['a', 'b', 'c', 'd', 'e'];
var arr2 = [1, 2, 3, 4, 5];

// col1 = ['a1', 'b2', 'c3', 'd4', 'e5']
var col1 = $linq(arr1).zipLongest(arr2, "(x, y) => x + y", "-", 0).toArray();

// col2 = [{letter: 'a', number: 1}, 
//    {letter: 'b', number: 2}, 
//    {letter: 'c', number: 3}, 
//    {letter: '-', number: 4}, 
//    {letter: '-', number: 5}]
var col2 = $linq(arr1)
    .take(3)
    .zipLongest(arr2, "(x, y) => {letter: x, number: y}", "-", 0)
    .toArray();
    
// col3 = [{letter: 'a', number: 1}, 
//    {letter: 'b', number: 2}, 
//    {letter: 'c', number: 3}, 
//    {letter: 'd', number: 0}, 
//    {letter: 'e', number: 0}]
var temp = $linq(arr2).take(3);
var col3 = $linq(arr1)
    .zipLongest(temp, "(x, y) => {letter: x, number: y}", "-", 0)
    .toArray();

Last edited Oct 4, 2012 at 3:30 AM by battousai999, version 3