In .NET / C# I have input data of type IEnumerable<T>
with T
having some properties I want to use for lookups.
How can I build a two-level (maybe three-level) lookup using LanguageExt without producing hard to read code like this:
var items = Range(1, 1000)
.Map(i => new
{
Number = i,
Section = (byte) (i % 10),
Text = $"Number is i"
}); // just some test data
HashMap<byte, HashMap<int, string>> lookup
= toHashMap(
from item in items
group item.Text by (item.Section, item.Number) into gInner
group gInner by gInner.Key.Section into gOuter
select ( gOuter.Key, toHashMap(gOuter.Map(_ => (_.Key.Number, _.Head()))) )
);
Expected output: lookup hashmap with Section
as outer key, Number
as inner key and Text
as value.
I prefer solutions using LINQ syntax (maybe making it easier to combine this with transforming / filtering / ordering ...).