How to call a method n times in Scala?

后端 未结 5 1015
轮回少年
轮回少年 2021-02-18 23:04

I have a case where I want to call a method n times, where n is an Int. Is there a good way to do this in a \"functional\" way in Scala?

case class Event(name: S         


        
5条回答
  •  日久生厌
    2021-02-18 23:48

    import List._
    
    fill(10) { println("hello") }
    

    Simple, built-in, and you get a List of Units as a souvenier!

    But you'll never need to call a function multiple times if you're programming functionally.

提交回复
热议问题