Created
September 23, 2014 09:28
-
-
Save masahitojp/885040aa3d9d87316a03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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