2

I'm trying to combine pattern matching and condition, but this code (that's a Samza task):

override def process(incomingMessageEnvelope: IncomingMessageEnvelope, messageCollector: MessageCollector, taskCoordinator: TaskCoordinator): Unit = {
    val event = (incomingMessageEnvelope getMessage).asInstanceOf[Map[String, Date]]
    val symbol = (event get "symbol").asInstanceOf[String]
    val eventDate = (event get "date").asInstanceOf[Date]

    (store get symbol) match {
      case x: java.util.Date if x.equals(eventDate) || x.after(eventDate) => _ 
      case _ => {
        this.store.put(symbol, eventDate)
      }
    }
  }

returns this error:

Error:(30, 38) unbound placeholder parameter
  case x if isGreaterOf(x, x) => _
                                 ^

Have you any idea of the error?

Thank you

Regards

Gianluca

rucka
  • 61
  • 1
  • 9
  • 1
    You're error doesn't exactly match the example code, but the important question is: what's supposed to happen when the pattern matches and passes the filters (i.e. the `if` conditions)? What code is supposed to be run? – jwvh Aug 01 '15 at 07:29

1 Answers1

6

The Exception does not match your code, but there is one line, that would throw the same error:

case x: java.util.Date if x.equals(eventDate) || x.after(eventDate) => _ 

because _ is a placeholder that can be used in patterns for matching and return types. It cannot not be used to indicate a Unit return value. To return a Unit value without executing code, you could just do

case x: java.util.Date if x.equals(eventDate) || x.after(eventDate) => ()

instead.

Sascha Kolberg
  • 7,092
  • 1
  • 31
  • 37
  • You can just omit the value completely: `case x: java.util.Date if x.equals(eventDate) || x.after(eventDate) =>` (It'll actually be Unit automatically) – Kolmar Aug 01 '15 at 17:17
  • That is right. However, I prefer to at least write something that makes my intent clear. And `()` is less work than a comment ;) – Sascha Kolberg Aug 01 '15 at 17:21