Open VBAndCs opened 3 years ago
I am also thinking of dropping the []
where #
exists, so:
dim stdunetsNames= Students[#Name]
can just be:
Dim stdunetsNames= Students#Name
where # means: Select the name property of each item in the Students list.
Note that stdunetsNames is IEnumerable just like using direct LinQ, so, we can just use it as usual. We can chain selectors as we do with LinQ:
Dim stdunetsNames= Students[#Grade > 3]#Name' The '[]
are required for conditions, and direct # is best for property selection.
I thinl it is not possible to select more than property by this syntax. I may think of:
`Dim stdunetsNames= Students[#Grade > 3][(#Name, #Grade)]'
but it will be confusing and less readable. I prefer to mix selectors with LinQ in such cases:
Dim stdunetsNames= Students[#Grade > 3].
Select(Function(x) New with {x.Name, x.Grade})'
Which will be mush better if rewritten as:
Dim stdunetsNames= Students[#Grade > 3].Select(#Name, #Grade)'
And this is where we van rethink of LinQ syntax as:
Dim stdunetsNames= Students Where #Grade > 3
Select #Name, #Grade
As a special case, dim result = Students[#Name] maybe rewritten as: dim result = Students[ ].Name
dim result = arr.Select(function(x) x > 3) . . . dim result = Students.Select(function(x) x.Address.Street(0) = "a" OrElse x.Address.Street(0) = "a")
Ummm. What are you expecting these to return?
Because, in both cases, result
will be an IEnumerable(Of Boolean)
, which is not what your discussion suggests to me.
It looks like you meant Where
, not Select
?
It looks like you meant Where, not Select?
My bad :)
Suppose we have an array named arr, and want to select items > 3:
I want to rewrite it like this:
Note: In #556, I asked for allowing [] for arrays and indexer. I am using this here to avoid any confusion with any old code using
()
.It items are objects with properties:
then:
Which can be shorten to:
note that I previously wanted to use dot instead of #, but this can cause some confusion inside With Blocks.
Now, Suppose we have a list like this:
lets complicate the selector a little:
or with LinQ:
We can make this shorter by defining a var for the selector and reuse it:
Note using the type #Student so we avoid late binding and have intellisense support. which can be more compact if VB always the in array syntax:
or in another way (since the selector is an expression tree, if can be some sort of a function delegate expression:
and if add a StartsWithAny extension method to the string class: