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

Convert to map has issues with the ... operator #27

Closed
hediet opened this issue Jun 15, 2022 · 3 comments
Closed

Convert to map has issues with the ... operator #27

hediet opened this issue Jun 15, 2022 · 3 comments

Comments

@hediet
Copy link

hediet commented Jun 15, 2022

const combinedDiffs: { diff: RangeMapping; input: 1 | 2 }[] = [];

	for (const diffs of baseRange.input1Diffs) {
		combinedDiffs.push(...diffs.innerRangeMappings.map(diff => ({ diff, input: 1 as const })));
	}
	for (const diffs of baseRange.input2Diffs) {
		combinedDiffs.push(...diffs.innerRangeMappings.map(diff => ({ diff, input: 2 as const })));
	}

Convert to map ->

const combinedDiffs: { diff: RangeMapping; input: 1 | 2 }[] = baseRange.input1Diffs.map((diffs) => {
		return ...diffs.innerRangeMappings.map(diff => ({ diff, input: 1 as const }));
	});

	for (const diffs of baseRange.input2Diffs) {
		combinedDiffs.push(...diffs.innerRangeMappings.map(diff => ({ diff, input: 2 as const })));
	}

🐛

There is also flatMap!

@lgrammel
Copy link
Contributor

Thanks for the bug report! I've released v1.117.2, which fixes this issue.

How would you use flatMap here ideally?

@lgrammel lgrammel reopened this Jun 15, 2022
@hediet
Copy link
Author

hediet commented Jun 15, 2022

const combinedDiffs: { diff: RangeMapping; input: 1 | 2 }[] = baseRange.input1Diffs.flatMap((diffs) => {
		return diffs.innerRangeMappings.map(diff => ({ diff, input: 1 as const }));
	});

@lgrammel
Copy link
Contributor

I've added .flatMap conversion in v1.120.3 (available when there is a spread element). Thanks for the idea!

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

2 participants