Итерация по заполнению таблицы 2 HasSets функционально в Scala

3
задан Phoen 3 March 2019 в 16:00
поделиться

1 ответ

Может, просто транспонировать подойдет вам?

val table = Array(
      Array("Product A","Customer 1"),
      Array("Product B","Customer 1"), 
      Array("Product C","Customer 2"),
      Array("Product A","Customer 2")
)

val Array(productSet, customerSet) = table.transpose.map(_.toSet)

productSet //Set(Product A, Product B, Product C)
customerSet //Set(Customer 1, Customer 2)
0
ответ дан Krzysztof Atłasik 3 March 2019 в 16:00
поделиться
Другие вопросы по тегам:

Похожие вопросы: