Skip to content

Instantly share code, notes, and snippets.

@masahitojp
Created September 23, 2014 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masahitojp/885040aa3d9d87316a03 to your computer and use it in GitHub Desktop.
Save masahitojp/885040aa3d9d87316a03 to your computer and use it in GitHub Desktop.
object Main extends App {
def swap[A](l: List[A], topElement: A) = {
l match {
case l0:List[A] if l0.nonEmpty => {
val (l1, l2 :: l3) = l0.splitAt(l0.indexOf(topElement))
l2 :: l1 ::: l3
}
case _ => l
}
}
val list = List("D", "Z", "CERO")
println(swap(list, "Z"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment