I have some filters expressed as a list of function List(MyClass => Boolean) . Im trying to get the logical conjunction (AND) of all the members . I have a feeling, I could use a fold here .but Im not getting the syntax especially around how to pass the MyClass argument to the functions.
Share
That’s pretty simple. Assuming your
List(MyClass => Boolean)of functions is namedpredicates andMyClassyou are testing is namedmyClass`:Or in a wrapping function:
Explanation: if you list of predicates consists of three functions:
foo(myClass: MyClass): Boolean,bar(myClass: MyClass): Booleanandbuzz(myClass: MyClass): Booleanthe code above is roughly equivalent to:I wrote an article a while ago about such use cases of
foldLeft.