4 ms·
Wow, that's interesting. Is 'x' just a magic var for whatever Select() yields in each iteration?
by famousactress 14y ago
Wow, that's interesting. Is 'x' just a magic var for whatever Select() yields in each iteration?
- Fishkins 14y agox is the input variable to that anonymous function. Instead of the named syntax e.g. doSomething(x) { return x * x; } the syntax for C# anonymous functions is x => x * x
- archivator 14y agoThe argument to Where() is a Func<TSource, Boolean>, and that "x => x .. " business is C#'s lambda syntax. x is just a variable name, no magic there.
- daeken 14y agoIt's a lambda. Saying x => foo(x) is the same as lambda x: foo(x) from Python.
- adambard 14y agox is the variable in the anonymous function 'x => x != ""'. I don't know C# but I presume that everything before '=>' is the argument list and the rest is the function body (with implicit return). You can see it again in '(a, b) => a + "\n" + b'. As a side note, I find it a bit funny how C# chooses method names in Linq for the benefit of programmers who know SQL, despite `Select`, `Where`, and `Aggregate` acting exactly like what other functional languages would call `map`, `filter`, and `reduce`. Not wrong, just sort of quirky.
- cpeterso 14y agoJavaScript will use the same "fat arrow" syntax for anonymous functions in ES6: http://css.dzone.com/articles/javascript-fat-city http://css.dzone.com/articles/javascript-fat-city
- adambard 14y agoCoffeescript uses it already.
- vorg 14y ago> `Select`, `Where`, and `Aggregate` acting exactly like what other functional languages would call `map`, `filter`, and `reduce`. Not wrong, just sort of quirky. Or `collect`, `findAll`, and `inject`.
- adambard 14y agoYeah, I don't know what the precedent is for Ruby's versions. I'm glad map, filter and reduce are also present.