I came across this classes in functional programming in scala 4 edition and book say that if Keyed is purely functional then MemoKeyed is purely functional. Does it mean we can sometimes have variable and assign value and still have purely functional code?
class Keyed {
def computeKey: Int = ... // this will take some time
...
}
class MemoKeyed extends Keyed {
private var keyCache: Option[Int] = None
override def computeKey: Int = {
if (!keyCache.isDefined) keyCache = Some(super.computeKey)
keyCache.get
}
}