major
nice-to-have
defect
major
enhancement
minor
#23108
Search expressions: Implicit flat map semantics from .get(...) to collections
If you want to navigate through multiple levels, you can do so using search expressions as follows:
x -> $x.get(`myModule:MyType#ref1`).get(`myModule:MyType#ref2`)
The prerequisite is that the first attribute, ref1, is not "multiple"—that is, it must return a single value rather than a collection. If ref1 is declared as "multiple," the code becomes somewhat cumbersome:
x -> $x.get(`myModule:MyType#ref1`).foreach(y -> $y.get(`myModule:MyType#ref2`))
If ref2 is also “multiple,” you even have to write the following to avoid getting a collection of collections, which the framework cannot handle at all:
x -> $x.get(`myModule:MyType#ref1`).foreach(y -> $y.get(`myModule:MyType#ref2`)).flatten()
With the automatic flat-map semantics of ` get(...) `, you can now simply use the first variant in all cases and get the expected result.
Test
- The derivedPath attribute in tl-demo.