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

Typescript, generic Linq functions #100

Open
tomgallagher opened this issue Jan 4, 2023 · 0 comments
Open

Typescript, generic Linq functions #100

tomgallagher opened this issue Jan 4, 2023 · 0 comments

Comments

@tomgallagher
Copy link

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();
}
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