I use scala to implement some common algorithms. When I tried to recreate the view of the bubble, I ran into this problem
Here is an implementation of the inner loop that bubbles up the upper value:
def pass(xs:List[Int]):List[Int] = xs match {
case Nil => Nil
case x::Nil => x::Nil
case l::r::xs if(l>r) => r::pass(l::xs)
case l::r::xs => l::pass(r::xs)
}
My problem is with case Nil => Nil. I understand that I need this because I can apply Nilto this function. Is there a way to ensure that Nilit cannot be provided as an argument in a way that the compiler will satisfy, so that I can eliminate this case?
source
share