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

can't easily convert to javascript Map #52

Open
jmagaram opened this issue May 10, 2018 · 3 comments
Open

can't easily convert to javascript Map #52

jmagaram opened this issue May 10, 2018 · 3 comments

Comments

@jmagaram
Copy link

Maybe I'm missing something here, but when you have an enumerable you can to toDictionary but you can't do toMap to create a regular javascript map. Very confused. I think ENikS/LINQ allows you to do that quite simply.

@mihaifm
Copy link
Owner

mihaifm commented May 14, 2018

They seem to be having the same source code in ENikS/LINQ
https://github.com/ENikS/LINQ/blob/master/lib/linq.ts#L463

It's a bit tricky.
What is the scenario where you need this ? You could use get or set, or even dictionary.buckets (not recommended).

@jmagaram
Copy link
Author

Suppose you have an array of numbers and want to group them by even or odd and then put them in a JavaScript Map<boolean, number[]>. I can't figure out how to do this. Want someghing like this...

const groups = Linq
    .from([1, 2, 3, 4, 5, 6])
    .groupBy(i => (i % 2 === 0), i => i)
    .map(i=>[i.key, i]) // can't call filter or map or anything here
    .toJavascriptMap();

@mspclaims
Copy link

You can get an array:

var Linq = require('linq')
var groups = Linq
    .from([1, 2, 3, 4, 5, 6])
    .groupBy(i => (i % 2 === 0), i => i)
    .first()
    .toArray()
//  .map(i=>[i.key, i]) 
console.log(groups);

See https://repl.it/@mspclaims/LimpYoungAssembler

@juancri juancri mentioned this issue Jan 18, 2021
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

3 participants