Recently when I was experimenting with Spark and Scala I encountered two patterns that I liked; Tap and Hydrate. So I decided to add them to the toolbox as LINQ extensions.
Tap is a simply a function to "tap into" the enumerable of data. The most common use for this one is probably debugging, but it could also be used to add logging or just to do multiple things on the enumerable.
Then Hydrate is a method to force enumeration of a collection. The use for this one is ensure you have the complete collection before you start working with it. Typically because you want to enumerate it multiple times but you only have an IEnumerable. Most of you probably just use ToArray or ToList for this (and Hydrate is implemented calling one of those), but there is a small difference in that the word hydrate (hopefully) better expresses your intent in the code.
Let me know if you find these useful.
Post a Comment