In Scala, how would I combine event driven programming with a functional approach?

Viewed 3908

To clarify what I mean by event driven I'm referring to a situation where I have

def onTrade(...)

Which is called every time a particular stock trades. Suppose I want to track the daily highest trade price. To me the obvious solution is:

var dailyHigh = 0

def onTrade(...) {
    if (price > dailyHigh) dailyHigh = price
}

Is there a way to achieve this functionality using val instead of var? Assume also that I may want to add dailyLow, volumeHigh, volumeLow etc in the future.

5 Answers
Related