Q:

Passing a function to another function as statement

I want to write a function which will return true if given an even number as an argument or false otherwise. additionally, write a function that will filter a list of numbers returning just the even numbers. All done using Scala functional programming. This is what I have:
def isEven(n:Int): Boolean = n % 2 == 0
    println(isEven(4))

val filterEven  =  ( xs :List[Int] )  => {
    for(  x <- xs;   if x % 2 == 0  )  yield x
}
println(filterEven(List(3,2,4,5,6,22,91)))

My question is, how can I pass the first function "isEven" to to the "filterEven" function in order to replace the "if-statement"?
Regards.

A:

You can pass isEven as a parameter to xs.filter
def filterEven(xs: List[Int]) = xs.filter(isEven)
This is functionally equivalent to:
def filterEven(xs: List[Int]) = for { x <- xs if isEven(x) } yield x

