Created
September 5, 2011 12:23
-
-
Save missingfaktor/1194836 to your computer and use it in GitHub Desktop.
Generic Fill
This file contains hidden or 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
| scala> import collection.generic.{GenericTraversableTemplate => GTT} | |
| import collection.generic.{GenericTraversableTemplate=>GTT} | |
| scala> import collection.generic.{TraversableFactory => TF} | |
| import collection.generic.{TraversableFactory=>TF} | |
| scala> def fill[A, CC[X] <: Traversable[X] with GTT[X, CC]] | |
| | (n: Int)(elem: => A)(tf: TF[CC]) = tf.fill(n)(elem) | |
| fill: [A, CC[X] <: Traversable[X] with scala.collection.generic.GenericTraversab | |
| leTemplate[X,CC]](n: Int)(elem: => A)(tf: scala.collection.generic.TraversableFa | |
| ctory[CC])CC[A] | |
| scala> fill(3)('d')(List) | |
| res42: List[Char] = List(d, d, d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment