Questions tagged [partialfunction]

Questions about the Scala's PartialFunction type. For questions about the broader concept of partial functions (i.e. functions not defined for all of their inputs), use [partial-functions]. For questions about partially applied functions, use [partial-application].

120 questions
0
votes
1 answer

Type mismatch in Play controller action when recovering a future

I'm having a problem to return the correct type in a scala play controller method can someone give me a hint here? I'm using for comprehantion to deal with two service methods that returns a Future, and I would like to handle elegantly the result…
simonC
  • 4,101
  • 10
  • 50
  • 78
0
votes
1 answer

How are we creating an object for a trait?

If PartialFunction is a trait, then how does this code work? Are we creating an object of the trait? def x=new PartialFunction[Any, Unit] { def isDefinedAt(x: Any) = x match { case "hello" => true case "world" => true case…
codingsplash
  • 4,785
  • 12
  • 51
  • 90
0
votes
1 answer

What does @ mean in Scala?

When studying sources of akka I found the following in the akka.event.slf4j.SLF4JLogger actor: def receive = { //... case event @ Warning(logSource, logClass, message) ⇒ withMdc(logSource, event) { Logger(logClass,…
user2953119
0
votes
1 answer

Scala Partial Function Application Semantics + locking with synchronized

Based on my previous question on locks based on value-equality rather than lock-equality, I came up with the following implementation: /** * An util that provides synchronization using value equality rather than referential equality * It is…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
0
votes
1 answer

How to combine PartialFunction with another function and return PartialFunction?

I have the following class: class MessageProcessorActor(private val destination : ActorRef) extends Actor{ override def receive: Receive = { case _ => destination ! { case MyActor.TracableMessage(msg) =>…
user3663882
  • 6,957
  • 10
  • 51
  • 92
0
votes
1 answer

Is there something like Map.keySet for a partial function in scala?

More specifically, I have: case class Key (key: String) abstract class abstr { type MethodMap = PartialFunction[Key, String => Unit] def myMap: MethodMap // abstract def useIt (key: Key, value: String) = { val meth = myMap(key) …
Mahdi
  • 1,778
  • 1
  • 21
  • 35
0
votes
1 answer

How to implement a partial function in a subclass

I'm trying to design a couple of classes that inherit a partial function, but I don't seem to be able to get the syntax quite right. My superclass looks like this: abstract class Controller { val react:PartialFunction[Event,Unit] } And the…
Ceilingfish
  • 5,397
  • 4
  • 44
  • 71
0
votes
1 answer

implicit from context bound on collection type parameter

I have some code that streams a response by converting a Stream of case classes to json representations using spray.json. This works fine for a single case class, but I want to genericize it. So I'm starting with case classes like this: import…
ryryguy
  • 610
  • 4
  • 15
0
votes
1 answer

Partial Functions and Execute-Once behaviour in Scala

EDIT: I agree with the sentiment of the down vote, but disagreed with the solution. So I've corrected/broken the code in the question so it has the problem as explained. I've left the answer and my original comment to it. In my opinion, the "def…
Tom
  • 313
  • 1
  • 4
  • 10
0
votes
2 answers

Scala regex and partial functions

I want to use Scala's collect function with a regular expression. Ideally I'd like to collect only those terms that match the regular expression. I've so far implemented the following which works fine val regex =…
Jon
  • 3,985
  • 7
  • 48
  • 80
0
votes
1 answer

Scala: Function definition of PartialFunction is ambiguous

Function definition of the PartialFunction is following: trait PartialFunction[-A, +B] extends (A) ⇒ B PartialFunction would allow us to filter by using case with collect on collection. For example when you have list of integers and…
user_1357
  • 7,766
  • 13
  • 63
  • 106
0
votes
1 answer

How does the case by type work in scala?

I know about case classes, pattern matching, unapply and PartialFunction, but I'm confused about bellow macros snippet. val declarations = weakTypeOf[T].declarations val methods = declarations.collect { case m: MethodSymbol => m } Scaladoc of…
sh1ng
  • 2,808
  • 4
  • 24
  • 38
0
votes
1 answer

Scala Currying: Overriding function with an empty argument by a partial function

I'm trying to implement/override a function with an empty input argument by using partial function. It is best explained by this non-working minimal example: trait T trait TFactory { def build(): T } class A(someParameter: Int) extends T object…
bluenote10
  • 23,414
  • 14
  • 122
  • 178
0
votes
3 answers

Scala PartialFunction construction with different results

I was trying to debug why some partial function composition were not working when I noticed that depending on how you instantiate the partial function you get different results. When you're using the syntactic sugar method it all works as…
Cristian Vrabie
  • 3,972
  • 5
  • 30
  • 49
-1
votes
1 answer

Scala: Partial function error: use _ if you want to treat it as a PartialFunction

The following piece of code does not work: FileSystems.getDefault.getPath is from the java.nio package Update: Method createCalculation is: Note: MyLocation is a case class that extends MyMessage def creatCalculation(myPlace: MyLocation): MyMessage…
user3825558
  • 585
  • 1
  • 8
  • 24
1 2 3 4 5 6 7
8