Advertisement
Guest User

Untitled

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