In scala I can write:
val pf: PartialFunction[String, Unit] = {case s => println(s)}
Now I can pass pf around, calling it with appropriate values.
I'm looking for a concise way of being able to define such a pf so that it can have a state. Say a counter of how many times it has been called. One way is this:
var counter = 0
val pf: PartialFunction[String, Unit] = {case s => counter +=1; println(s)}
What I don't like here is that it is not concise and the state is exposed.