Hi,
I am playing around with Java 8 and Akka.
In Scala I liked to use currying in some scenarios in combination with Akka
Props factory methods.
I tried to use a similar approach with classes from the new
java.util.function package and would be interested to know if there are
better approaches to achieve currying with Java.
Example:
Scala:
object ActorB {
def props (externalDependency: ExternalDependency) () =
Props(new ActorB(externalDependency))
}
class ActorA(actorBProps: () => Props) extends Actor {
val actorB = context.actorOf(actorBProps(), "actorB");
...
}
Bootstrap {
val actorBProps = ActorB.props(externalDependency)
system.actorOf(ActorA.props(actorBProps));
}
Java 8:
ActorB {
public static Function<ExternalDependency, Supplier<Props>> props() {
return x -> () -> Props.create(ActorB.class, () -> new ActorB(x));
}
...
}
ActorA {
public static Function<Supplier<Props>, Supplier<Props>> props() {
return p -> () -> Props.create(ActorA.class, () -> new ActorA(p));
}
ActorA(Supplier<Props> props) {
//create actorB
ActorRef actorB = context.actorOf(props.get(), "actorB");
}
...
}
Bootstrap {
Supplier<Props> actorBProps = ActorB.props().apply(externalDependency);
system.actorOf(ActorA.props().appyl(actorBProps), "ActorA");
}
Looking forward to get some feedback.
Thanks
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.