I have list containing several elements (lets say 10). I want to get the first 5 elements of the list in a new list (Copy). Later on I could need the same but starting at element 3 up until element 8.
In C# I would use the GetRange method but I find nothing like this in OutSystems. Is this possible without a foreach loop and if so, how?
Hi Vincent,
Why not just use the startindex and maxiterations on the foreach ?
for optics : A ForEach + ListAppend takes about the same space as a ListFilter + ListAppendAll
for performance : It is faster than a ListFilter, as that will allways go through the whole list
for semantics : I find it easier to understand what's going on (but that's subjective, i know)
Dorine
PS you might get a warning if startindex is not 0 and count is not matching linecount of a widget, but that's all it is, a warning, ignore it.
Hi Dorine,
You are right, if the List isn't too big this is probably just as fast as the ListFilter trick on Traditional Web (or just as fast, I'm not sure what the overhead is of the ListAppend).
I would imagine that internally, a ListFilter with a condition is implemented as a loop going over every item checking if the condition is true, then appending to the ListFilter result list.
Or is there a trick about using the ListFilter to avoid that ?
Otherwise, I think a Listfilter is as fast as using startindex and maxcount if we take all items, and is always slower if we only take part of the items.
(not that the difference in performance is likely to be important unless the amount of items is very large)
I think ListFilter uses specific C# constructions that are faster than the equivalent in OutSystems.
this post was begging for a little test :
Whaddayaknow, ListFilter seems slower than For Each + ListAppend, who would've thought! Thanks for the test!
if ListFilter had a "position" property could be done, but without it I couldn't find a way.
Why don't you create an extension for the GetRange method in C#?
Regards
With Traditional Web, you can use the CurrentRowNumber property of the List in combination with a ListFilter to get a certain subsection of a List in a new List. Unfortunately, this doesn't work for Reactive Web, you'd have to resort to JavaScript.
Hello Vicent,
I took some time and set up an example for you with OutSystems technique.
I hope it's something like this you're looking for.
greetings,Rui
ps: for some reason the site won't let me publish the example oml here, so I had to publish it in forgehttps://www.outsystems.com/forge/Component_Overview.aspx?ProjectId=11868