Unable to filter list based on the node type
- 14
- 3
- swtechno
- Nov 27
Hi everybody,
I'm trying to write a mapping inside a loop-macro, but I wasn't able to achieve what I wanted.
I have a list of rootElements with different nodes instances implementing interfaces (so I can tell what they are all about). At some point in my logic I want to do something like:
node.rootElements.ofType<node<ILinkNode>>
But, unfortunately, all the nodes are returned without taking into account the type, can anybody point out the way of achieving this filtering?
Regards
Peter.
I'm trying to write a mapping inside a loop-macro, but I wasn't able to achieve what I wanted.
I have a list of rootElements with different nodes instances implementing interfaces (so I can tell what they are all about). At some point in my logic I want to do something like:
node.rootElements.ofType<node<ILinkNode>>
But, unfortunately, all the nodes are returned without taking into account the type, can anybody point out the way of achieving this filtering?
Regards
Peter.
- Magvay
- Nov 28
Hello Peter,
I think you can try something like this:
node.rootElements.where({~it => it.isInstanceOf(ILinkNode; })
Here "where" is an operation from j.m.collections language (you should import it),
{~it => it.isInstanceOf(ILinkNode; } is a closure and ".isInstanceOf" is a node operation.
Also you can filter this list in a simple for loop using ".isInstanceOf" check.
Best regards,
Ilya
I think you can try something like this:
node.rootElements.where({~it => it.isInstanceOf(ILinkNode; })
Here "where" is an operation from j.m.collections language (you should import it),
{~it => it.isInstanceOf(ILinkNode; } is a closure and ".isInstanceOf" is a node operation.
Also you can filter this list in a simple for loop using ".isInstanceOf" check.
Best regards,
Ilya
- swtechno
- Nov 28
I already tried that but doesn't return any node. I guess is because each item in the list is of type node<ILinkNode> and not just ILinkNode.
I finally ended up doing something like:
node.rootElements.where({~it => it.concept.isSubConceptOf(ILinkNode); }).ofType<node<ILinkNode>>;
Not really sure if there is another shortcut to do it. Let me know if you think there is one so I can improve my code.
Thanks for your help!
I finally ended up doing something like:
node.rootElements.where({~it => it.concept.isSubConceptOf(ILinkNode); }).ofType<node<ILinkNode>>;
Not really sure if there is another shortcut to do it. Let me know if you think there is one so I can improve my code.
Thanks for your help!
- Mihail Muhin
- Dec 02
Peter,
operation checks exactly what you need - that the node is instance of a given concept. This operation differs from baseLanguage's "instanceof" operation.
So, IMO, Ilya is right and the code he provided should work.
Regards,
Mihail
Our node.isInstanceOf(concept)
So, IMO, Ilya is right and the code he provided should work.
Regards,
Mihail