Skip to content

Instantly share code, notes, and snippets.

@ppiotrow
Created October 30, 2013 18:17
Show Gist options
  • Save ppiotrow/7237396 to your computer and use it in GitHub Desktop.
Save ppiotrow/7237396 to your computer and use it in GitHub Desktop.
package pl.japila.scalania.s99
object S99_P17 {
def split[T](n: Int, ts: Seq[T]): (Seq[T], Seq[T]) =
{
val tsWithIndexes = ts.zipWithIndex
def filterPairValue(p: ((T, Int)) => Boolean): Seq[T] = for (x <- tsWithIndexes if p(x)) yield x._1
val first = filterPairValue(_._2 < n)
val second = filterPairValue(_._2 >= n)
(first, second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment