src/main/scala/accumulate.scala

1
2
3
4
5
6
7
8
9
import scala.annotation.tailrec

class Accumulate {
  @tailrec
  final def accumulate[A, B](fn: A => B, list: List[A], acc: List[B]=Nil): List[B] = list match {
    case Nil => acc
    case x :: xs => accumulate(fn, xs, acc :+ fn(x))
  }
}

@abo64 thinks this looks great

Comments


You're not logged in right now. Please login via GitHub to comment