This project is read-only.

groupJoin(inner, outerKeySelector, innerKeySelector, resultSelector[, comparer, arg])

Correlates the elements of two sequences based on key equality and groups the results. A specified equality comparer is used to compare keys.

Syntax

Parameters

inner
The sequence to join to the first sequence.
outerKeySelector
Type: function(value, key, arg)
A function to extract the join key from each element of the first sequence.
innerKeySelector
Type: function(value, key, arg)
A function to extract the join key from each element of the second sequence.
resultSelector
Type: function(outerValue, innerValueCollection, arg)
A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.
comparer
Type: function(key1, key2, arg): boolean
An equality comparer to hash and compare keys.
arg
An external argument.
Return Value

An iteratable object that contains elements that are obtained by performing a grouped join on two sequences.

Examples

var magnus = { name: "Hedlund, Magnus" };
var terry = { name: "Adams, Terry" };
var charlotte = { name: "Weiss, Charlotte" };

var barley = { name: "Barley", owner:  terry };
var boots = { name: "Boots", owner:  terry };
var whiskers = { name: "Whiskers", owner:  charlotte };
var daisy = { name: "Daisy", owner:  magnus };

var people = [ magnus, terry, charlotte ];
var pets =  [ barley, boots, whiskers, daisy ];

// Create a list where each element is an anonymous 
// type that contains a person's name and 
// a collection of names of the pets they own.
var query =
    $from(people).groupJoin(pets,
        "person => person",
        "pet => pet.owner",
        function(person, petCollection) {
            return {
                ownerName: person.name,
                pets: petCollection.select("$name")
            }
        }
    );

query.each(function(obj) {
    document.writeln(obj.ownerName + ":");
    obj.pets.each("document.writeln(' ' + $)");
});

/*
This code produces the following output:

Hedlund, Magnus:
Daisy
Adams, Terry:
Barley
Boots
Weiss, Charlotte:
Whiskers
*/

Last edited May 17, 2012 at 7:22 AM by suckgamoni, version 2

Comments

No comments yet.