More list operations to mimick C++ list operations - Mendix Forum

More list operations to mimick C++ list operations


For several of our projects we need some extra functionality on lists (which we made using java actions), but as they seem like basic list operations, we'd rather be able to select them from the list operation menu. As a reference, here's the C++ list set:

Reverse: in the parts below, we refer to the lack of sorting the list on something other than its contents. Reverse is such a way. It basically reverses the list from front to back to back to front. So {A, B, C} becomes {C, B, A}

Iterators: at the moment, there is only one iterator and it's front to back. As we cannot sort the list to reorder it from back to front (only sorting on attributes is possible) and then use the 'normal' iterator, it's hard to loop over a list back to front. So it would be nice if we either could select which iterator to use when looping. So selecting the reverse iterator would loop a list {A, B, C} starting at {C, B, A}

Front/back: at the moment, we only have access to the head (front) and the tail (the rest of the 'body' of the list, except the head). Again, as we cannot reverse a list from back to front, it's not possible to easily grab the 'back' part of a list (last element added). Also the terminology of head vs tail is ambiguous (where head is easy to understand, but tail can either mean the last element of the list or in Mendix case: everything except the head (so basically the tail includes the body as well). So it would be nice to have access to the front part (head) and the back part (last element of the list) as well. So requesting the back of {A, B, C} would give us C.

push_front: another feature we miss while working with lists is the ability to add an element on another place besides the last element (basically push_back inserts the element after the previously last element of the list; same behavior as Mendix at the moment). However, it might also be wanted at times to add an element in the front of the list (push_front). So adding D to the front of {A, B, C} would yield {D, A, B, C}.

pop_front/pop_back: another one is the simple pop operation: pop_front: get the first element in the list and remove it from the list (so the first element in the remaining list is the second element before the pop_front (in Mendix, pop_front is a combination of Head and subtract the head from the list). So say my list is {A, B, C} and I use pop_front, I get A, while the list remains {B, C}. Same with pop_back, which retrieves the last element from the list and removes it. So pop_back on {A, B, C} will get me C, while the list will only contain {A, B}.

3 answers

Dear Mendix Team,
A backward iterator would be so helpful, indeed – please, make it a part of the Mendix concepts, if anyhow possible.
Thanks, Reinhard


Yeah, I did implement them using java actions and microflows (to circumvent some shortcomings of java code in Mendix), but would be prettier (and easier to use) if it was just a list option.

Imagine the reverse function: I have a java action that takes input of a list…in the java action the list is reversed (so A, B, C becomes C, B, A). I need to return the newly reversed list so I can use the result of the reverse java function.

This is simple the limitation of the way Mendix seems to approach java actions (my guess is they put a copy of the list inside my java action… the list is manipulated in the java action, but when the java action finished, the list is still as is). Similar behavior is found when you create a list in a nanoflow, call a sub nano flow that alters the list… in the sub nanoflow, the changes are there; as soon as you exit the nanoflow and return to the main one, the changes are no longer part of the list.

If you do the same with a microflow, the changes are remembered. I need that same functionality (so changes to the list are remembered after the function is finished (so the changes need to be made to the original object, not a copy).

Hence the best way to achieve this is by having it supported in Mendix list operations (I’d think) :-)


Hi Alex

This could be implemented (except for the iterator) with Java Actions and Java Script actions and would be a valuable addition to the Commons libs.

Cheers, Andries