Scalar list merge question

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

I'd like to merge the list with or condition. For example,

List(List(1), List(2))
List(List(1), List(2), List(3))
List(List(2), List(3))
List(List(4))

Merge the above four lists to result values

List(List(1), List(2), List(3))
List(List(4))

I'd like to get a total of two lists.

list scala

2022-09-20 15:31

1 Answers

Please keep that in mind

val a = List(List(1), List(2))
val b = List(List(1), List(2), List(3))
val c = List(List(2), List(3))
val d = List(List(4))

val mergeList = a ::: b ::: c ::: d
val splitList = mergeList.toSet.toList.splitAt(3)

splitList._1
// // List[List[Int]] = List(List(1), List(2), List(3))
splitList._2
// // List[List[Int]] = List(List(4))


2022-09-20 15:31

If you have any answers or tips


© 2022 pinfo. All rights reserved.