Flatten
Syntax
$setOfSets.flatten()
Description
Calculates a set that contains all elements from all element sets in the set setOfSets
.
Two-dimensional sets (i.e. sets that contain sets as elements again) are not supported as final result. Therefore, all elements in the inner sets must be unpacked and stored as elements of the outer set instead. One therefore needs flatten
()
for example when $set.map($func)
(see Map) is called and func
itself returns a set.
Parameter
Name | Type | Description | Mandatory | Default |
---|---|---|---|---|
setOfSets | Set | A two-dimensional set (set with sets as elements). | yes |
Return Value
Type: Set
A set containing all the individual elements of the original set elements.
Examples
Simple two-diemnsional set
list(1, 4, 9)
.map(x -> concat($x, 2, 3))
.flatten()
Output: A set with the elements [1, 2, 3, 4, 2, 3, 9, 2, 3].
The elements of the three result sets [1, 2, 3], [4, 2, 3], and [9, 2, 3] are unwrapped and inserted as elements of a single set.
Set-valued reference attributes
Assuming that the type my.module:MyTyp
has a set-valued reference attribute others
, then the expression
all(`my.module:MyType`)
.map(x -> $x.get(`my.module:MyType#others`)
would return a set of sets with all objects referenced in others
, which is not supported as the end result of, for example, a search. Therefore, the result set must be flattened:
all(`my.module:MyType`)
.map(x -> $x.get(`my.module:MyType#others`)
.flatten()