-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
=doc #3886 improved example of PartialFunction.orElse composition #2023
Conversation
``PartialFunction.orElse`` chaining. | ||
Sometimes it can be useful to share common behavior among a few actors, or compose one actor's behavior from multiple smaller functions. | ||
This is is possible because an actor's :meth:`receive` method returns an ``Actor.Receive``, which is a type alias for ``PartialFunction[Any,Unit]``, | ||
and partial functions can be chained together using the ``PartialFunction#orElse`` method. You can chain however many functions you need, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can chain however many functions you need, however ...
how about
You can chain as many functions as you need, however ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, good catch - thanks!
Sometimes it can be useful to share common behavior among a few actors, or compose one actor's behavior from multiple smaller functions. | ||
This is is possible because an actor's :meth:`receive` method returns an ``Actor.Receive``, which is a type alias for ``PartialFunction[Any,Unit]``, | ||
and partial functions can be chained together using the ``PartialFunction#orElse`` method. You can chain as many functions you need, | ||
however you should keep in mind that "first match" wins - which may be important when combining functions that both can handle the same type of parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/parameter/message/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, done
LGTM, thanks for the improvement! Doc fixes can still go in for 2.3.0. |
Changed orElse composition example to better highlight it's possibilities. This is a follow up PR based on a discussion on akka-user: https://groups.google.com/forum/#!topic/akka-user/vVUZPMeJmzw
LGTM |
Cool, feedback addressed and squashed :) |
LGTM, thanks |
Great job. Thanks @ktoso. |
=doc #3886 improved example of PartialFunction.orElse composition
Changed
PartialFunction#orElse
composition example to better highlight it's possibilities.This is a follow up to a discussion on akka-user: https://groups.google.com/forum/#!topic/akka-user/vVUZPMeJmzw
Opened issue for this here: https://www.assembla.com/spaces/akka/simple_planner#/ticket:3886
Existing docs: http://doc.akka.io/docs/akka/snapshot/scala/actors.html#Extending_Actors_using_PartialFunction_chaining