Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

groupJoin produces empty result when inner is empty #5

Open
XC-Zhang opened this issue Dec 18, 2019 · 0 comments
Open

groupJoin produces empty result when inner is empty #5

XC-Zhang opened this issue Dec 18, 2019 · 0 comments

Comments

@XC-Zhang
Copy link

groupJoin produces empty result when inner is empty. Let's see the following example.

const Enumerable = require("node-enumerable");

const persons = [
  { name: "Tanja" },
  { name: "Marcel" },
  { name: "Yvonne" },
  { name: "Josefine" }
];

const pets = [];

const e = Enumerable.from(persons)
  .groupJoin(
    pets, 
    person => person.name, 
    pet => pet.owner.name,
    (person, pets) => { person, pets }
  )
  .toArray();

Online runner
The example will result in an empty array [].

Expected result would be:

[
  { person: { name: "Tanja" }, pets: [] },
  { person: { name: "Marcel" }, pets: [] },
  { person: { name: "Yvonne" }, pets: [] },
  { person: { name: "Josefine" }, pets: [] }
]

Corresponding C# code produces the expected result.

using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
  public static void Main()
  {
    var people = new Person[]
    {
      new Person("Tanja"),
      new Person("Marcel"),
      new Person("Yvonne"),
      new Person("Josefine")
    };

    var pets = new Pet[0];

    var e = people.GroupJoin(
      pets, 
      person => person.Name, 
      pet => pet.Owner.Name,
      (person, ps) => new { Person = person, Pets = ps }
    ).ToArray();
  }
}

public class Person
{
  public string Name { get; set; }
  public Person(string name)
  {
    Name = name;
  }
}

public class Pet
{
  public string Name { get; set; }
  public Person Owner { get; set; }
  public Pet(string name, Person owner)
  {
    Name = name;
    Owner = owner;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant