4 ms·
Depends on the language. In Scala the idiomatic approach would be to favor the immutable/recursive version. def min(foos: List[Int]): Option[Int] = foos m
by virtualwhys 6y ago
Depends on the language.
In Scala the idiomatic approach would be to favor the immutable/recursive version.
def min(foos: List[Int]): Option[Int] = foos match {
case Nil => None
case x :: Nil => Some(x)
case x :: xs =>
min(xs).filter(_ < x) orElse Some(x)
}