Skip to content

Instantly share code, notes, and snippets.

@missingfaktor
Created September 5, 2011 12:23
Show Gist options
  • Select an option

  • Save missingfaktor/1194836 to your computer and use it in GitHub Desktop.

Select an option

Save missingfaktor/1194836 to your computer and use it in GitHub Desktop.
Generic Fill
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