Both map and flatMap take a function which is applied to successive elements of the list/sequence/…
Is there a variant already in the standard library which applies the function to successive lists/sequences/… instead? I’m not sure if this idea even makes sense for non-lists. I’m interested to see how it might.
Here is my implementation for List. which is not tail recursive, but a robust version of course should be.
def maplist[A1,R](f:List[A1]=>R,data:List[A1]):List[R] = {
data match {
case Nil => Nil
case head::tail => f(data)::maplist(f,tail)
}
}