Created
February 24, 2012 02:20
-
-
Save giuniu/1896735 to your computer and use it in GitHub Desktop.
mapBetween関数sliding版
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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