3 ms·
I'm a little late to the party, but I don't think I would hire an experienced C# developer that didn't immediately know this could be a one liner: var csv =
by caseymarquis 6y ago
I'm a little late to the party, but I don't think I would hire an experienced C# developer that didn't immediately know this could be a one liner:
var csv = ImmutableList<ImmutableList<string>>.Empty;
var map = csv.ToImmutableDictionary(y => y.First(), y => y.Skip(1).ToImmutableList());
I would hope they would then tell me that this will throw an exception when there is a repeat header in the csv data. I'm not sure the functional and safe version is that much cleaner than a for loop:
var map = csv
.Where(x => !string.IsNullOrWhiteSpace(x.FirstOrDefault()))
.GroupBy(x => x.First())
.ToImmutableDictionary(x => x.Key, x => x.First().Skip(1).ToImmutableList());
Edit: But I would hire a developer that knew how to do the equivalent in Clojure without hesitation.