Reputation: 5552
I am very new to scala, I am trying to map the values of a list to the values obtained by running a function on the values of another list
What I mean is that I have an list A and another B. There is a function say func(b) which takes input as an element of the list B.
If I were to map it to list elements to a function of its own elements I could do it like this
val evalData = A.map(a=>(a, func(a)))
But I can't understand how to do it for my use case. Can someone please help me !! Thanks !
Upvotes: 0
Views: 1061
Reputation: 1285
I suspect from your question that list A and B have the same length. For example, you could have:
val listA = List(1,2)
val listB = List(3,4)
def f(a:Int) = a+1
val result = listA zip (listB map f)
result: List[(Int, Int)] = List((1,4), (2,5))
Upvotes: 4