Hi, I'm rater new to scala, but basically have found my way around...
Here, I'm asking for the recommended/best practice/idiomatic way of implementing this:
- internally, MyClass uses a state type, which is implemented by a sealed hierarchy of case classes
- but on the API, only some boolean predicate should be exposed, which gets implemented by matching against the (internal) state.
Currently, my implementation is along the lines of...
def isSane: Boolean = state match {
case Ok(_,'valid) => true
case _ => false
}
But this solution feels awkward to me, as if expressing something in 3 lines of code which has only information content worth one line of code. Actually, what I'd like to write would be:
def isSane: boolean = state matches Ok(_, 'valid)
Probably/likely it's possible to implement a suitable operator yourself in scala, but before I look into that, I'd like to know what would be the usual way to solve this problem. Maybe there's also some existing library implementation around?