I’m trying to figure the correct syntax in Scala to apply a set of functions to an object. Say I have a class:
class MiTestClass {
def isValid() : Bool = {...}
def isGreen() : Bool= {...}
def isYellow() : Bool = {...}
}
and I create a new object val miTestObj = new MiTestClass now I want to apply a subset of methods to my object like
val conditions:List[MiTestClass => Boolean] = List(_.isGreen, _.isYellow)
and to perform some operation, say for instance to check that all properties hold
val result:Bool = resultOfApplyingFunctions.foldLeft(true)(and)
What is the syntax for getting such functionality? In Haskell you would write something like
map (\f -> f miTestObj) conditions
but I can not get the Scala syntax right
1 Answer