Created
July 31, 2015 11:49
-
-
Save fancellu/c2ed64da112523ef7547 to your computer and use it in GitHub Desktop.
InsertAt.scala Alternative for http://aperiodic.net/phil/scala/s-99/p21.scala
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
Alternative for http://aperiodic.net/phil/scala/s-99/p21.scala | |
def insertAt[A](e: A, n: Int, ls: List[A]) = | |
ls.patch(n, List(e), 0) | |
insertAt('new,1,li) //> res1: List[Symbol] = List('a, 'new, 'b, 'c, 'd) | |
insertAt('new,0,li) //> res2: List[Symbol] = List('new, 'a, 'b, 'c, 'd) | |
insertAt('new,99,li) //> res3: List[Symbol] = List('a, 'b, 'c, 'd, 'new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment