Use-cases for Streams in Scala

后端 未结 4 1471
孤街浪徒
孤街浪徒 2020-12-12 13:18

In Scala there is a Stream class that is very much like an iterator. The topic Difference between Iterator and Stream in Scala? offers some insights into the similarities a

4条回答
  •  鱼传尺愫
    2020-12-12 13:33

    I could imagine, that if you poll some device in real time, a Stream is more convenient.

    Think of an GPS tracker, which returns the actual position if you ask it. You can't precompute the location where you will be in 5 minutes. You might use it for a few minutes only to actualize a path in OpenStreetMap or you might use it for an expedition over six months in a desert or the rain forest.

    Or a digital thermometer or other kinds of sensors which repeatedly return new data, as long as the hardware is alive and turned on - a log file filter could be another example.

提交回复
热议问题