Skip to content

Typescript, generic Linq functions #100

Open
@tomgallagher

Description

@tomgallagher

Hey - thanks for this library

I've got a question:

If I have a function like this, a 'left join' type function, how do I get types out of it that I need so I can object properties without the compiler complaining?

export function LeftOuterJoin<L, R>(
	leftArray: L,
	rightArray: R,
	leftKey: string,
	rightKey: string
) {
	return Enumerable.from(leftArray)
		.groupJoin(
			Enumerable.from(rightArray),
			(pk) => pk[leftKey],
			(fk) => fk[rightKey],
			(left, right) => ({ ...left, right })
		)
		.selectMany(
			(m) => m.right.defaultIfEmpty(),
			(left, right) => ({ ...left, ...right })
		)
		.select(({ right, ...rest }) => ({ ...rest }))
		.toArray();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions