Infinite streams in Scala

后端 未结 5 1561
忘了有多久
忘了有多久 2021-02-03 17:28

Say I have a function, for example the old favourite

def factorial(n:Int) = (BigInt(1) /: (1 to n)) (_*_)

Now I want to find the biggest value

5条回答
  •  执笔经年
    2021-02-03 18:09

    Stream.from(1)
    

    creates a stream starting from 1 and incrementing by 1. It's all in the API docs.

提交回复
热议问题