Closed vgpro54321 closed 2 years ago
I don't do this often but had to implement left join. This is not easy, a couple of shorthands from LINQ, GroupJoin and DefaultIfEmpty are not present. Can they be introduced? Thanks!
let list1: KV[] = [ { key: 0, value: 'a' }, { key: 1, value: 'b' }, { key: 2, value: 'c' }, { key: 3, value: 'd' }, ]; let list2: KV[] = [ { key: 0, value: 'aa' }, { key: 1, value: 'bb' }, { key: 3, value: 'dd' }, ]; let rightGroups = from(list2) .groupBy(x => x.key) .toMap(x => x.key); let groupLeftJoin = from(list1).select((left) => { let matches = rightGroups.get(left.key); return { left: left, right: matches ? from(matches) : from([null]) }; }); let leftJoin = groupLeftJoin.selectMany((x) => x.right.select((right) => ({ left: x.left, right, })) );
I'll look into this once I get some time. You can also create a PR to add these APIs in.
Default If Empty will be part of the next release
Added APIs in https://www.npmjs.com/package/linq-to-typescript/v/10.0.0-beta2
I don't do this often but had to implement left join. This is not easy, a couple of shorthands from LINQ, GroupJoin and DefaultIfEmpty are not present. Can they be introduced? Thanks!