There is an option In Scala match case to use Boolean extractors in match case .
The unapply method instead of returning an object returns Boolean expression.
The following example demonstrates it :
class DataEntity (val mValue:Int) extends IDataEntityobject DataEntityValueChecker {def unapply(pIDataEntity: IDataEntity): Boolean ={pIDataEntity.mValue > 164}}object MeshamemLiMavet10 extends App {println ("Starting MeshamemLiMavet 10 ")val theIDataEntity: IDataEntity = new DataEntity(165)theIDataEntity match {case pIDataEntity @ DataEntityValueChecker() => {println (pIDataEntity.mValue.toString() + " > 164")}case _ => {println ( " > 164")}}
And the result:
Starting MeshamemLiMavet 10
165 > 164
אין תגובות:
הוסף רשומת תגובה