question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.ToDictionary should return a Dictionary<TKey, TValue>

See original GitHub issue

https://github.com/kutyel/linq.ts/pull/136

This is not allowing me to use the following syntax:

const questions = new List<PCSQuestion>([]);
const questionDic = questions.ToDictionary((x) => x.id);
const questionDicProperty = questionDic[''].something;

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
schotimecommented, Mar 8, 2021

A sample implementation is

function ToDictionaryLookup<T, TRet>(items: T[], id: (item: T) => string, value: (item: T) => TRet) {
    return items.reduce((r, x) => ({ ...r, [id(x)]: value(x) }), {} as { [id: string]: TRet });
}
2reactions
kutyelcommented, Jan 15, 2021

As I said, please provide a unit test with a complete example with types and the input and output that you expect and that way we will know if this is something that needs to be fixed 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

ToDictionary Method in C# with Examples - Dot Net Tutorials
Returns : It returns a System.Collections.Generic.Dictionary<TKey,TValue> collection that contains keys and values. Exceptions: This method throws the following ...
Read more >
Enumerable.ToDictionary Method (System.Linq)
Returns. A Dictionary<TKey,TValue> that contains keys and values. The values within each group are in the same order as in source .
Read more >
net - How to convert object to Dictionary<TKey, TValue> in C
The above answers are all cool. I found it easy to json serialize the object and deserialize as a dictionary. var json =...
Read more >
ToDictionary overload for IEnumerable<KeyValuePair<IKey ...
Often it would be useful to be able to create a Dictionary from an IEnumerable >. With that, it would be easier to...
Read more >
C# - Dictionary<TKey, TValue> - TutorialsTeacher
Dictionary <TKey, TValue> stores key-value pairs. · Comes under System. · Implements IDictionary<TKey, TValue> interface. · Keys must be unique and cannot be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found