xtendxpand

How can I return a list based on a condition on the referencing elements of the list


I want to return a list of elements of 'ListOfObjects' that are being referenced by 'SomeOtherObject' with it's(SomeOtherObject's) attribute satisfying the condition. I'm trying this code:

ParentObj.ListOfObjects.select(e|e.referencingContainers.typeSelect(SomOtherObject).attr.isValid());

'ListOfObjects' extracts a list of particular objects from the 'ParentObj'.But the above code gives me nothing. Please help me out in figuring out what's wrong here.


Solution

  • It's because, in the above piece of code, the result of the expression inside the select returns a list and not an a boolean. To make it boolean I'd have to rewrite the code this way:

    ParentObj.ListOfObjects.select(e|e.referencingContainers.typeSelect(SomOtherObject).select(el|el.attr.isValid()).size > 0);
    

    The select inside the select along with the check for size is what made the difference there.