Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is Scala "filling in" missing arguments to a case class?

When I call:

actor_ ! Exit

How is this being converted into a construction of:

case class Exit(from: AbstractActor, reason: AnyRef)

In particular, how is it that when I call this from a remote (client) actor which has been linked to a remote (server) actor, that the server receives an instance of Exit where the from property is an actor:

'remotesender0@Node(10.10.7.90,8366)

Basically I'd like to figure out how I can get a handle on this remote-client-actor object!

like image 497
oxbow_lakes Avatar asked Jun 29 '09 14:06

oxbow_lakes


People also ask

What does _ _1 mean in Scala?

_1 is a method name. Specifically tuples have a method named _1 , which returns the first element of the tuple.

For which kind of data should you use a case class in Scala?

A Scala Case Class is like a regular class, except it is good for modeling immutable data. It also serves useful in pattern matching, such a class has a default apply() method which handles object construction. A scala case class also has all vals, which means they are immutable.

What is difference between class and case class in Scala?

A class can extend another class, whereas a case class can not extend another case class (because it would not be possible to correctly implement their equality).

Can Scala case class have methods?

Case Classes You can construct them without using new. case classes automatically have equality and nice toString methods based on the constructor arguments. case classes can have methods just like normal classes.


1 Answers

What you are sending is the singleton object Exit. In the Scala API, just scroll down past the classes, and look up the objects.

object Exit 
extends (AbstractActor, AnyRef) => Exit

Now, I haven't seen your code, so I don't know how you are using it. Notice, though, that this object Exit is (actually, extends) a function, which takes two parameters and returns an Exit case class formed by them. It will also have some stuff put in it by the case class statement.

Or, in other words, Exit.apply(x,y) (the function Exit being applied) has the same result as Exit(x,y) (the constructor for class Exit). But while you can't pass a class, you can pass an object.

like image 170
Daniel C. Sobral Avatar answered Oct 13 '22 10:10

Daniel C. Sobral