A tiny LINQ like function or two?

kanaida

Active Member
Licensed User
Longtime User
I know this is probably a tall order, but i feel it would make things so much less verbose.

If you've ever used LINQ, the syntax is something like this

B4X:
Dim Stuff() as SomeObjectType = from x in SomeList Where x.contains("123") order by x.SomeProperty

Basically like in-line sql queries.

To do the equivalent right now it would take a few loops, if statements, etc... and it's not as nice and clear as the example above.

Now I know that java itself doesn't natively support this, but we are *converting* to java aren't we? :) so at least some basic functions could be implemented in the syntax like the where and sort clauses, giving us a list or array in return.

Perhaps:

B4X:
Dim Stuff() as MyClass
Stuff = SomeNewBaFunction(YourOriginalListOfStuff() as object, WhereClause as string)

Dim Stuff2() as MyClass
Stuff = SomeNewBaFunction2(YourOriginalListOfStuff() as object, WhereClause as string,OrderBy as string)

Might work :)
I'm just paying attention to the things I seem to be coding repeatedly to do pretty much anything.

The other thing we can perhaps do is related to strings to write less code is allow in-line values where b4A takes care of all the &'s and "" around text when used like this:

Dim Value1 as string = "SomeValue"
Dim Value2 as string = "SomeOtherValue"

Dim FinalString = "The first <%= Value1 %> does not equal: <%= Value2 %>"
 

kanaida

Active Member
Licensed User
Longtime User
Good call :D Can anyone please move this thread to the B4A wishlist?

thanks
 

COBRASoft

Active Member
Licensed User
Longtime User
Linq is a nice thing to have, Lambda expressions even nicer since they form the base for Linq. I can imagine that implementing Lambda expressions (and Linq) would require a LOT of work from Erel and it's probably not worth the effort for the coming year(s).

Lambda expressions are translated into functional code, so you can make your own functions for searching through a list, sorting a list, ... like you already suggested.
In my grid module you can find some of these functions for lists made by me (where, sort, ...). They're not Lambda or Linq, but help you a lot further to accomplish difficult or repetitive tasks already.
 

wl

Well-Known Member
Licensed User
Longtime User
Bumping this thread as it might be nice of including something like this in B4A 2.8 :)
 
Top