Skip to content

Instantly share code, notes, and snippets.

@aryairani
Last active December 28, 2015 16:59
Show Gist options
  • Save aryairani/7532946 to your computer and use it in GitHub Desktop.
Save aryairani/7532946 to your computer and use it in GitHub Desktop.
val l = List("a","b","c","d")
val getStyle = (k: Int) => l(k % l.length)
val styles = List.tabulate(10)(getStyle)
// styles: List[String] = List(a, b, c, d, a, b, c, d, a, b)
// or
def getStyle[A](styles: Seq[A]) = (k: Int) => styles(k % styles.length)
val l2 = List(1, 5, 9)
val styles = List.tabulate(10)(getStyle(l2))
// styles: List[Int] = List(1, 5, 9, 1, 5, 9, 1, 5, 9, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment