Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. def loop(in: List[Int], acc: Int): Int =
  2. in match {
  3. case Nil => acc // 終了条件
  4. case head :: tail =>
  5. val result = head * 2 // headのタスク
  6. loop(tail, acc + result) // 残りのリストと計算途中を渡して処理を継続
  7. }
  8.  
  9. val result = loop((1 to 10).toList, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement