Array flattening to a single dimensional array

If the property value on the original item returns an array of items, expansion behavior is slightly different. Gosu does not return an array of arrays, which is an array where every item is an array. Gosu returns an array containing all the individual elements of all the values in each array, which is known as flattening the array.

To demonstrate array flattening, create the following test Gosu class:

package test

class Family {
  var _members : String[] as Members
}

Next, paste the following lines into the Gosu Scratchpad:

uses java.util.Map
uses test.Family

// Create objects that each contain a Members property that is an array
var obj1 = new Family() { :Members = {"Peter", "Dave", "Scott"} }
var obj2 = new Family() { :Members = {"Carson", "Gus", "Maureen"} }

// Create a list of objects, each of which has an array property
var familyList : List<Family> = {obj1, obj2}

// List expansion, with FLATTENING of the arrays into a single-dimensional array
var allMembers = familyList*.Members

print(allMembers)

Running this program prints the following single-dimensional array:

["Peter", "Dave", "Scott", "Carson", "Gus", "Maureen"]

Examples

The following expression produces a name for each Form attached to a policy period.

PolicyPeriod.Forms*.DisplayName

The following expression returns a flattened array of display name values:

PolicyPeriod.ExposureUnits.Coverages*.DisplayName