Reputation: 1437
I would like to do a pattern match that looks like :
sinceOp match {
case None |Some(lastUpdate) if lastUpdate<= update.time =>
Saddly this does not work. Any ideas ?
Thanks
Upvotes: 5
Views: 235
Reputation: 40461
You could can also test the reverse condition:
sinceOp match {
case Some(lastUpdate) if lastUpdate > update.time => //...
case _ => //...
}
The second case covers both None
and the case where the last update is smaller.
Upvotes: 10
Reputation: 10776
Or you can replace pattern matching with chain of functions
sinceOp.filterNot(_ <= update.time).getOrElse(println("if None"))
Upvotes: 3