Lambda as a function parameter

Report a typo

We have the generic HOF mapper which transforms every A element to another R element using the transformation lambda as a function parameter:

def mapper[A, B](list: List[A], transformation: A => B): List[B]

Implement the toLengths function using mapper and your lambda to return the length of the names.

Sample Input 1:

List(John, Fitzgerald, Bob, Victoria)

Sample Output 1:

List(4, 10, 3, 8)
Write a program in Scala 3
def toLengths(names: List[String]): List[Int] =
mapper(names, ???)
___

Create a free account to access the full topic