About
object SearchExamples { def main(args: Array[String]): Unit = { val exampleListThree: List[Int] = List(1, 2, 3, 4, 5)
def is2(n: Int): Boolean = n == 2
def is3multiple(n: Int): Boolean = n % 3 == 0
def therels(n: Int, list: List[Int]): Boolean = list.contains(n)
def therelsOneSatisfyingP(p: Int => Boolean, list: List[Int]): Int = list.find(p).getOrElse(-1)
println(therels(2, exampleListThree)) // Returns: true
println(therels(5, exampleListThree)) // Returns: false
println(therelsOneSatisfyingP(is2, 1 :: 2 :: 3 :: 4 :: Nil)) // Returns: 2
println(therelsOneSatisfyingP(is3multiple, 2 :: 5 :: 18 :: 19 :: Nil)) // Returns: 18
println(therelsOneSatisfyingP(is3multiple, 2 :: 5 :: Nil)) // Returns: -1
} }