v Flatten Sequence Of Sequences - Scala

Flatten Sequence Of Sequences

If you want to learn more, check out Scala Cookbook and Programming in Scala.

Create An Array Sequence

// Create an array that contains arrays with first and last names
val fullNames = Array(
    Array("Jason", "Miller"),
    Array("Jason", "Miller"), // Duplicate
    Array("Sally", "Fields"),
    Array("Betty", "Johnson")

Flatten The Sequence

// Flatten the sequence
Array(Jason, Miller, Jason, Miller, Sally, Fields, Betty, Johnson)

Flatten The Sequence And Only Keep Unique Values

// Flatten the sequence and remove any duplicates
Array(Jason, Miller, Sally, Fields, Betty, Johnson)