O'Reilly logo

Actors in Scala by Frank Sommers, Philipp Haller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.5 Functions as control structures

Java developers seldom think about control structures such as for, while, or if—these are part of the Java language. Scala, by contrast, has a richer set of control structures, and many of those control structures are implemented as methods that consume functions as their parameters. The Actor API defines a handful of carefully crafted control structures designed to direct actor behavior, such as act, receive, or reply.

Scala makes creating new control structures even more natural with a little syntactic sugar: when a Scala method has only one parameter, you can surround the method argument with curly braces instead of parentheses. The following are equivalent uses of the same method:

  doItByName(println(

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required