I'm attempting to return a value from a inner loop. I could create a outside list and populate it within the inner loop as suggested in comments below but this does not feel very functional. Is there a function I can use to achieve this ?
The type of the loop/inner loop is currently Unit but I would like it to be of type List[Int] or some similar collection type.
val data = List(Seq(1, 2, 3, 4), Seq(1, 2, 3, 4))
//val list : List
for(d <- data){
for(d1 <- data){
//add the result to the val list defined above
distance(d , d1)
}
}
def distance(s1 : Seq[Int], s2 : Seq[Int]) = {
s1.zip(s2).map(t => t._1 + t._2).sum
}