How do I make a function involving futures tail recursive?

前端 未结 4 552
野性不改
野性不改 2020-11-29 09:52

In my Scala app, I have a function that calls a function which returns a result of type Future[T]. I need to pass the mapped result in my recursive function call. I want t

4条回答
  •  再見小時候
    2020-11-29 10:52

    How about using foldLeft instead?

    def factorial(n: Int): Future[Int] = future {
      (1 to n).foldLeft(1) { _ * _ }
    }
    

提交回复
热议问题