Created
September 28, 2015 18:00
-
-
Save sam/7be14ce3f7632e97a8b7 to your computer and use it in GitHub Desktop.
Trying to figure out how to chain partial functions with inheritance...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Parser { self: Actor => | |
def parse: PartialFunction[Opened, Unit] | |
def receive: Receive = parse orElse(super.receive) andThen(_ => done()) | |
def collectWork: Receive | |
def done(): Unit = { | |
context become collectWork | |
context.self ! Done | |
} | |
} | |
trait StoryListParser extends Parser { self: Actor => | |
def parse = { | |
case Opened(url, content) if url.getPath.endsWith("stories/") => | |
// ... PARSE LIST OF STORIES ... | |
} | |
} | |
trait StoryParser extends Parser { self: Actor => | |
def parse = { | |
case Opened(url, content) if url.getPath.matches("""stories\/[^\/]+$""") => | |
// ... PARSE INDIVIDUAL STORY ... | |
} | |
} | |
class Job extends Actor with StoryListParser with StoryParser { | |
def collectWork: Receive = { | |
case Done => context.parent ! Done | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment