Tail recursion and climbing promises

I am currently playing with non-blocking Scalaz futures. Promises I'm struggling to make the following tail-recursive function:

@tailrec
private def repeat( res: Promise[I] ):Promise[I] =
  res map p flatMap { 
    (b:Boolean) =>
      if( b ) repeat( res flatMap f ) else res
  }

where pis a predicate with type I=>Boolean, and fis a parallel function with type I=>Promise[I].

The method compiles without annotation.

Any clues? Thanks

+3
source share
2 answers

Your method is not recursive at all. resis a computation that potentially works in another thread. res map p flatMap fwill immediately return a promise regarding your method. Repetition of k repeatwill occur in another process.

Promise , flatMap .

+4

, , - . , , . (, - , , p)

- . , .

+1

All Articles