pipe()

The pipe linq operator returns a linq object containing the same elements as the collection, but first performs an 'action' on each element. The pipe operator is very similar to the foreach operator, but where the foreach operator does not return anything, the pipe operator returns a collection with the same elements as the originial collection.
var arr = ["John", "Mary", "David", "Kenneth"];

// col1 = ["john", "mary", "david", "kenneth"]
// Note, the function passed to the pipe operator is not returning new
// elements, but modifying them.  A similar call that instead returns new
// elements would be:
//
// var col1 = $linq(arr).select(function (x) { return x.toLowerCase(); }).toArray();
var col1 = $linq(arr).pipe(function (x) { x[0] = x[0].toLowerCase(); }).toArray();

// col2 = ["John", "Mary", "David", "Kenneth"];
// This will also alert each of the names prefixed with the index (e.g., "(1) John", etc.)
var col2 = $linq(arr)
    .pipe(function (x, i) { alert('(' + (i + 1) + ') ' + x); })
    .toArray();

Last edited Oct 16, 2012 at 8:07 PM by battousai999, version 1