Wpis z mikrobloga

#scala
#programowanie
https://docs.scala-lang.org/pl/tour/nested-functions.html

object FilterTest extends App {
def filter(xs: List[Int], threshold: Int) = {
def process(ys: List[Int]): List[Int] =
if (ys.isEmpty) ys
else if (ys.head < threshold) ys.head :: process(ys.tail)
else process(ys.tail)
process(xs)
}
println(filter(List(1, 9, 2, 8, 3, 7, 4), 5))
}

Mam pytanie czemu jest tutaj wywoływana funkcja process(xs), na samym końcu metody process?
  • 4
  • Odpowiedz
  • Otrzymuj powiadomienia
    o nowych komentarzach