Title: Flatten Sequence Of Sequences
Slug: flatten_sequence_of_sequences
Summary: Flatten Sequence Of Sequences Using Scala.
Date: 2017-01-03 12:00
Category: Scala
Tags: Basics
Authors: Chris Albon
If you want to learn more, check out Scala Cookbook and Programming in Scala.
In [1]:
// 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")
)
In [2]:
// Flatten the sequence
fullNames.flatten
Out[2]:
In [3]:
// Flatten the sequence and remove any duplicates
fullNames.flatten.distinct
Out[3]: