Created
October 11, 2017 05:29
-
-
Save eHammarstrom/02a3e7b0ddd8da9359e5bc0ee2701ccb 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
import scala.collection._ | |
val myList = List(1, 2, 3, 4, 5) | |
val myArray = Array(1, 2, 3, 4, 5) | |
def intersperse[T](xs: Traversable[T], in: T): Traversable[T] = | |
xs.flatMap(x => List(x, in)) | |
println(intersperse(myList, 0)) | |
println(intersperse(myArray, 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment