Skip to content
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

Merged
merged 1 commit into from
Feb 27, 2014

Conversation

ktoso
Copy link
Member

@ktoso ktoso commented Feb 19, 2014

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

``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,
Copy link

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 ...

?

Copy link
Member Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/parameter/message/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, done

@rkuhn
Copy link
Contributor

rkuhn commented Feb 20, 2014

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
@ktoso ktoso added reviewed and removed tested labels Feb 20, 2014
@bantonsson
Copy link
Member

LGTM

@ktoso
Copy link
Member Author

ktoso commented Feb 20, 2014

Cool, feedback addressed and squashed :)

@patriknw
Copy link
Member

LGTM, thanks

@ktoso ktoso added the tested label Feb 20, 2014
@jboner
Copy link
Member

jboner commented Feb 20, 2014

Great job. Thanks @ktoso.

rkuhn added a commit that referenced this pull request Feb 27, 2014
=doc #3886 improved example of PartialFunction.orElse composition
@rkuhn rkuhn merged commit d7283ab into akka:master Feb 27, 2014
@ktoso ktoso deleted the doc-3886-partialfunc-orelse-ktoso branch February 28, 2014 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reviewed Ready to merge from review perspetive, but awaiting some additional action (e.g. order of merges) tested PR that was successfully built and tested by Jenkins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants