score:6

Accepted answer

it's not about the codomain, it's the wrong function arity.the method map expects a function with a single argument, even if this argument is a tuple:

((int, int)) => (int, int) // function[(int, int), (int, int)]

but you are passing it a function that takes two arguments (two ints):

(int, int) => (int, int)   // function2[int, int, (int, int)]

do either this:

def fun1(t: (int, int)) = (t._1+1, t._2)
l map fun1

or this:

def fun1(t1: int,t2: int) = (t1+1,t2)
l map { case (x, y) => fun1(x, y) }

here is a similar example with a more detailed explanation for a similar issue.

score:3

you have to use case to destruct the tuple.

val l = list((1,2),(2,3),(3,4))
def fun1(t1: int,t2: int) = (t1+1,t2)
l map { case (a, b) => fun1(a, b) }

but, if you declare your function like below to make it work

def fun1(t: (int, int)) = (t._1 + 1,t._2)

l map fun1

Related Query

More Query from same tag