4 ms·
I don't think people understanding the problem LINQ attempts to solve with expression trees. Let me give you a more Internet'ish example. Let's say I have a R
by kasajian 8y ago
I don't think people understanding the problem LINQ attempts to solve with expression trees. Let me give you a more Internet'ish example. Let's say I have a REST api that's something like this:
https://movies.org/movie https://movies.org/movie
which returns all movies
but if you want only certain movies, you issue:
https://movies.org/movie?year>2016 https://movies.org/movie?year>2016
to get movies created after 2016.
Let's say you didn't issue the query but instead you got the entire set of movies and filtered locally:
var movies = get("https://movies.org/movie" https://movies.org/movie")
foreach( var movie in movies) {
if (movie.year > 2016) addToTable(movie)
}
Let's do this with LINQ:
foreach( var movie in movies.Where(movie => movie > 2016)) {
addToTable(movie)
}
The naive observer will assume the two pieced of code are about the same. But in actuality, if you had a fictitious "LINQ to Movies", it could, internally, construct the correct REST API for you.
What I'm saying is that, this code:
var list = movies.Where(movie => movie > 2016))
would translate into:
var movies = get("https://movies.org/movie?year>2016" https://movies.org/movie?year>2016")
Not so hypothetical. This is how OData works from C#.
Look at the C# example under "Step 2: Requesting an individual resource" at http://www.odata.org/getting-started/understand-odata-in-6-steps/ http://www.odata.org/getting-started/understand-odata-in-6-s...
See how elegant it is compared to the other examples using Java, Node, etc.
Doing this requires meta-programming, which many other languages have. I don't know much about Clojure, Scala or Ruby, but I'm pretty sure stuff like this can be (and possibly already are) built using the existing meta-programming constructs.
- Const-me 8y agoI agree that it’s very easy to use, but it’s extremely hard to implement new LINQ providers. When I needed that, I implemented the subset of the functionality without LINQ (1). See the usage example (2). (1) https://github.com/Const-me/EsentSerialize/tree/master/Core/EsentSerialize81/Linq https://github.com/Const-me/EsentSerialize/tree/master/Core/... (2) https://github.com/Const-me/EsentSerialize/blob/master/Demos/ConsoleDemo/Program.cs https://github.com/Const-me/EsentSerialize/blob/master/Demos...