Christian Sousa
03/19/2020, 11:39 AMfun myFunction(list: List<String>): List<String> {
return list.map {
return it
}
}
It complains about the return type being a string instead of a List<String>diesieben07
03/19/2020, 11:40 AMreturn
is not used inside lambdas. In this case the return
is returning from myFunction
(the nearest function context). That works, because map
is inline
.
In lambdas the last expression is the "return value".Christian Sousa
03/19/2020, 11:42 AMmyFunction
diesieben07
03/19/2020, 11:42 AMreturn list.map {
it
}
Christian Sousa
03/19/2020, 11:42 AMribesg
03/19/2020, 11:52 AMribesg
03/19/2020, 11:53 AMreturn@myFunction
(equals to return
in your case) or return@map
(what you want). But it’s easier to just let the last expression be the returned valueMike
03/19/2020, 12:19 PMit
is a placeholder for something more complicated, right? Otherwise you could just return the original list.Christian Sousa
03/19/2020, 12:21 PM