Alex Rivera | Logout

How to flatten a List of different types in Scala?

Asked 2009-11-15T12:44:02.750
12

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]]

I tried to zip them and I obtained a nested list that I can't apply flatten to because it says: no implicit argument matching parameter type.

How can I solve this? should I try another way or is there any way to make the flatten work?

I'm kinda new to scala so it may be a dumb question :D Thanks in advance! clau

Edit
Report

1 Answer

4

The question is very vague. You should plain paste what you have, instead of trying to describe it. It would make everyone's (including your's) life much easier.

The code below is one example based on an assumption of what you have.

scala> List(List(1))
res0: List[List[Int]] = List(List(1))

scala> List(List(2))
res1: List[List[Int]] = List(List(2))

scala> List(List(3))
res2: List[List[Int]] = List(List(3))

scala> List(List(4))
res3: List[List[Int]] = List(List(4))

scala> res0 ::: res1 ::: res2 ::: res3
res4: List[List[Int]] = List(List(1), List(2), List(3), List(4))
answered 2009-11-15T23:17:26.993

Your Answer