I have a very simple example of a set s1 {1, 2} and I want to apply a predicate p > 1 on it. Now I have implemented this function, and it is giving me correct results.
def filter(s: Set, p: Int => Boolean): Set = {(i: Int) => s(i) && p(i)}
Where definition of set is
type Set = Int => Boolean
But is there a more elegant way of doing it in Scala?
Set
like this and not use standard Scala collection library?{}
and the type annotation afteri
, so the body would look like this:i => s(i) && p(i)
. Other than that it looks fine... :)i
by the way, because it is inferred.def filter(s: Set)(p: Int => Boolean): Set = { i => s(i) && p(i) }