Skip to content

Instantly share code, notes, and snippets.

@oluies
Created August 21, 2012 09:03
Show Gist options
  • Save oluies/3413761 to your computer and use it in GitHub Desktop.
Save oluies/3413761 to your computer and use it in GitHub Desktop.
findGaps
scala> List(3,4,5,8,9,10,12).sliding(2).collect{ case Seq(x, y) if(y != x + 1) => (x,y) }
res39: Iterator[(Int, Int)] = non-empty iterator
scala> .foreach(println(_) )
(5,8)
(10,12)
scala> def findGaps[T <: Int](xs:List[T]) = xs.sliding(2).collect{ case Seq(x, y) if(y != x + 1) => (x,y) }
findGaps: [T <: Int](xs: List[T])Iterator[(T, T)]
scala> findGaps(List(3,4,5,8,9,10,12))
res41: Iterator[(Int, Int)] = non-empty iterator
scala> .foreach(println(_) )
(5,8)
(10,12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment