Should I be exposing Stream on my interface?

前端 未结 3 1568
失恋的感觉
失恋的感觉 2021-01-06 08:39

If I am writing .NET code I would often expose IEnumerable where-ever it could possibly make sense. Maybe it was down to LINQ and the fact you could us

3条回答
  •  臣服心动
    2021-01-06 08:46

    Whether or not you want to be a Stream yourself, primarily depends on whether you're truly a Stream with the corresponding powers, i.e. support parallelization (not all Streams do, but it's one of the many benefits of Streams, and it's an important one). Normally I'd rather be a Collection and let myself be Streamed by the corresponding API calls.

    The getStuff() method, returning Stream from myCollection.stream() looks right to me.

提交回复
热议问题