So, why exactly is LINQ not considered purely functional?
Is it because side effects can occur? Or is it maybe because it exists in an imperative environment?
LINQ technology is a form of declarative, functional programming.
LINQ syntax is typically less efficient than a foreach loop. It's good to be aware of any performance tradeoff that might occur when you use LINQ to improve the readability of your code. And if you'd like to measure the performance difference, you can use a tool like BenchmarkDotNet to do so.
The difference between functional programming and imperative programming is that functional programming considers the computations as mathematical functions and avoids changing state and mutable data while imperative programming uses the statements that change the programs state.
C# developers are also used to other functional techniques, especially LINQ with its heavy usage of lambda expressions, and extension methods. C# supports various functional aspects so that it may be worth to take a glance at the previously introduced core fundamentals of functional programming from its perspective.
LINQ is not a purely functional programming model as it permits side effects, is thus not referentially-transparent, which is a common definition of "purely functional".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With