Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uses for Scala continuations

How are people using continuations on a larger and smaller scale in Scala?

Are any parts of the Scala standard library written in CPS?

Are there any major performance penalties in using continuations?

like image 402
Mohamed Bana Avatar asked Oct 26 '10 09:10

Mohamed Bana


1 Answers

I'm using this to turn asynchronous functions of the form def func(...)(followup: Result => Unit): Unit so that instead of writing

foo(args){result1 => 
  bar(result1){result2 => 
     car(result2) {result3 =>
       //etc.
     }
  }
}

you can write

val result1 = foo(args)
val result2 = bar(result1)
val result3 = car(result2)

or

car(bar(foo(args)))

(note: the functions are not limited to one argument or just the use of previous results as arguments)

See http://www.tikalk.com/java/blog/asynchronous-functions-actors-and-cps

like image 59
IttayD Avatar answered Sep 17 '22 22:09

IttayD