Re: Re: What does this mean ?
Oliver Ruebenacker <[email protected]> Mon, 11 Apr 2016 10:25:54 -0400
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAA=X4OCizcVOOQkrguos5WKetvdSQxG+B0C1o25b1DueNo1G-w@mail.gmail.com> |
Hello,
The receive method takes one partial function. A partial function can
consist of multiple case statements.
scala> val pf : PartialFunction[Int, String] = { case 1 => "one"; case 2=>
"two"}
pf: PartialFunction[Int,String] = <function1>
scala> (1 to 10).collect(pf)
res1: scala.collection.immutable.IndexedSeq[String] = Vector(one, two)
Best, Oliver
On Sun, Apr 10, 2016 at 11:20 PM, John Michael Lafayette <
[email protected]> wrote:
> So the "receive" method takes in an arbitrary number of partial functions
> of type partialFunction[Any, A] as its parameter and it dynamically
> checks the input against each partial function using isDefinedAtuntil it
> gets a match.
>
> But the type signature for receive is: receive[A](f: PartialFunction[Any,
> A]): A
>
> It should only take in a single partial function, f, not a vararg or list
> or array of partial functions. Is " case Stop => Console.println("Pong:
> stop") " a single partial function or is it part of a single partial
> function object?
>
>
>
>
> On Wednesday, February 17, 2016 at 9:40:20 AM UTC-5, Clement Dourval wrote:
>>
>> Hi, I'm currently Learning Scala and more precisely, concurrent
>> programming with scala.
>>
>> I found this code :
>>
>> class Pong extends Actor {
>> def act() {
>> var pongCount = 0
>> while (true) {
>> receive {
>> case Ping =>
>> if (pongCount % 1000 == 0)
>> Console.println("Pong: ping "+pongCount)
>> sender ! Pong
>> pongCount = pongCount + 1
>> case Stop =>
>> Console.println("Pong: stop")
>> exit()
>> }
>> }
>> }
>> }
>>
>> This is from a tutorial, so i'm expecting it to work, the only problem is
>> I do not understand how.
>>
>> The main problem is, how does this code use the case keyword since there
>> is no match !
>> (adress of the tutorial : http://www.scala-lang.org/old/node/242)
>>
>> Anyway, i understood what was the tutorial was supposed to do (with ping
>> pong), I just don't understand what is written, I'd like to be able to
>> write it myself.
>> But it seems i'm missing some syntax subtleties
>> And even if these are deprecated, i found the same synthax with the akka
>> Library ! So I'm asking myself how to read this.
>>
>> Anyone can help ? Thanks in advance !
>>
> --
> You received this message because you are subscribed to the Google Groups
> "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal
<http://www.type2diabetesgenetics.org/>, Broad Institute
<http://www.broadinstitute.org/>
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.