Skip to content

Instantly share code, notes, and snippets.

@giuniu
Created February 24, 2012 02:20
Show Gist options
  • Save giuniu/1896735 to your computer and use it in GitHub Desktop.
Save giuniu/1896735 to your computer and use it in GitHub Desktop.
mapBetween関数sliding版
object mapBetween2 {
def main(args:Array[String]) = {
val range = 1 to 10
println(mapBetween(range)(_+_) mkString ",")
println(mapBetween(range)(_*_) mkString ",")
println(mapBetween(range)(_-_) mkString ",")
}
def mapBetween[A,B,T>:A](seq:Seq[A])(f:(T,T)=>B): Iterator[B] = {
seq.sliding(2).map(s=>f(s(0),s(1)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment