0

I'm pretty new to scala and I can't find a way to get rid of my Array[Seq[(Int, String)]] to one big Seq[(Int, String)] containing the (Int, String) of each Seq[(Int, String)].

Here is a more explicit example:

Array[Seq[(Int, String)]]:

ArrayBuffer((1,a), (1,group), (1,of))

ArrayBuffer((2,following), (2,clues))

ArrayBuffer((3,three), (3,girls))

And here is what I want my Seq[(Int, String)]] to looks like:

Seq((1,a), (1,group), (1,of), (2,following), (2,clues), (3,three), (3,girls))

1 Answer 1

2

You are looking for flatten: val flat: Array[(Int, String)] = originalArray.flatten

If you want it to be a Seq rather than an array (good choice), just tuck a .toSeq at the end: originalArray.flatten.toSeq

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.