Hyston blog
About • RSS

Developer diaries #0: LINQ

2018-05-08 23:09

When I’m writing linq queries, I’m often forgetting, how powerful is it. At least a half dozen times I have wrote a query, that includes objects from one array, that are not exist in another one, like this:
var firstUnique = first.Where(l => !second.Contains(l));
But only today I was enlightened, that much simpler version exist:
var firstUnique = first.Except(second);
It may seem very similar, but make huge difference on structures, that are more difficult than List<int>
Too bad that typescript does not have linq abilities. However, I have found today a spread separator, which helps a lot working with structures. I.e. I have flattened complex dto like this:
var segments = .concat(...groupedSegments.map(bs => bs.segments))
Here groupedSegments is array of objects, each of them contain segments , which is array of objects, that I actually need. With one call I make this structure flat.


Next entry → ← Prev entry