C# LINQ
- brief notes, mapping Microsoft's SQL based names to more conventional FP names
LINQ (Language INtegrated Query) - this is how C# provides set operations such as 'map' or 'filter' as extensions to the C# language.
One difficulty with learning LINQ, if you are coming from another language such as Scala or JavaScript or TypeScript, is the naming of the methods.
The naming of LINQ methods is different from most languages, since Microsoft originally introduced LINQ as a way to query databases. So, the method names are much closer to SQL, than to regular set operations.
Here is an incomplete table, mapping conventional names to their LINQ equivalents:
'filter' = Where
'flatmap' = SelectMany
'groupBy' = GroupBy
'head' = First / FirstOrDefault
'map' = Select
'reduce/fold' = Aggregate
'sort' = OrderBy
'take' = Take
LINQ is definitely an important extension of C# to learn, for writing more 'functional' C# (for example avoiding for loops and avoiding state management).
Tutorial blog:
https://codeblog.jonskeet.uk/category/edulinq/
- brief notes, mapping Microsoft's SQL based names to more conventional FP names
LINQ (Language INtegrated Query) - this is how C# provides set operations such as 'map' or 'filter' as extensions to the C# language.
One difficulty with learning LINQ, if you are coming from another language such as Scala or JavaScript or TypeScript, is the naming of the methods.
The naming of LINQ methods is different from most languages, since Microsoft originally introduced LINQ as a way to query databases. So, the method names are much closer to SQL, than to regular set operations.
Here is an incomplete table, mapping conventional names to their LINQ equivalents:
'filter' = Where
'flatmap' = SelectMany
'groupBy' = GroupBy
'head' = First / FirstOrDefault
'map' = Select
'reduce/fold' = Aggregate
'sort' = OrderBy
'take' = Take
LINQ is definitely an important extension of C# to learn, for writing more 'functional' C# (for example avoiding for loops and avoiding state management).
Tutorial blog:
https://codeblog.jonskeet.uk/category/edulinq/
Comments
Post a Comment