O'Reilly logo

Scala Functional Programming Patterns by Atul S. Khot

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

Akka actors take the stage

Akka is a Scala library, which let's us implement the message-based concurrency systems. An actor is like a small program with a message queue of its own. You can only get an actor to do some work by passing it a message.

Here is our FileFinder object as an actor:

import akka.actor._
import akka.util.Timeout
import scala.io.Source

object FileFinder { // 1
  def props() = Props(new FileFinder)
  case class FileFinderMsg(pat: String, rootDir: String)
}

class FileFinder extends Actor { // 2 
  import FileFinder._
  import context._
  import java.io.File

  val grepActor = system.actorOf(Props(new GrepAFile), ""GrepAFile"") // 3

  def recurseIntoDir(dir: File): Iterable[File] = { // 4
    val itsChildren = new Iterable[File] {
 def ...

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