flatMap内での再帰呼び出しの最適化 Functional Programming in Scalaexercise 4.5traverse def traverseA,B(f:A=>Option[B]):Option[List[B]]= as match{ | case Nil => Some(Nil) | case (h::t) => for{ | hh <- f(h) | tt <- traverse(t)(f) | } yield(hh::tt) | } traverse: A, B(f: A => Option[B])Option[List[B]] traverse((1 to 10000).toList)(i => Some(i)) liststackoverflow flatMap flatMapstacksafe
GitHub`foldRight``traverse`1
<
<
3`List.foldRight``foldRight``traverse`ScalaList`foldRight`
xcX3v84RxoQ-4GxG32940ukFUIEgYdPy
125e7150be7900fd6a008dd156c12ef4
Stop