Skip to content

Instantly share code, notes, and snippets.

@gkojax
Created October 30, 2012 08:30
Show Gist options
  • Save gkojax/3978981 to your computer and use it in GitHub Desktop.
Save gkojax/3978981 to your computer and use it in GitHub Desktop.
フィボナッチを書いたんだけどprintlnの位置が気に入らない
val op: Pair[BigInt, BigInt] = Pair(1, 1)
(0 until 10).foldLeft(op) { (ab, x) =>
println(ab._1)
Pair[BigInt, BigInt](ab._2, ab._2 + ab._1)
}
val op: Pair[BigInt, BigInt] = Pair(1, 1)
(0 until 10).scanLeft(op) { (ab, x) =>
Pair[BigInt, BigInt](ab._2, ab._2 + ab._1)
}.foreach { x =>
println(x._1)
}
@gkojax
Copy link
Author

gkojax commented Oct 30, 2012

scanLeftをおすすめされた結果。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment