fork download
  1. object Main {
  2. import scala.annotation._
  3. @tailrec
  4. def unfoldr_foldl[A, B, C](f: A => Option[(A, B)])(a: A)(g: B => C => C)(c: C): C = f(a) match {
  5. case None => c
  6. case Some((a, b)) => unfoldr_foldl(f)(a)(g)(g(b)(c))
  7. }
  8. def main(args: Array[String]) {
  9. val a = unfoldr_foldl[Int,String,Int](i => List("1", "2", "3", "end")(i) match {
  10. case "end" => None
  11. case s => Some(i + 1, s)
  12. })(0)(a => b => a.toInt + b)(0)
  13. println(a)
  14. }
  15. }
  16.  
  17.  
Success #stdin #stdout 0.19s 211776KB
stdin
Standard input is empty
stdout
6