Scala: what is traversableOnce? What is the difference between TraversableOnce and Traversable?

TraversableOnce: "A template feature for collections that can only be passed once or one or more times ."

I do not understand this sentence. Why go through more times ? Not just once ? Thanks!

+6
source share
3 answers

Scaladoc also says

Iterator Traversable , , , foreach Builder.

"" . .

, TraversableOnce - , , . Iterator, Traversable !

, Collections, , ( ) Scala 2.8 Collection Design Tutorial .

+15

- , :

Iterator.continually(readline)

, , , .

, , Array, Map ..

Traversable , . , Traversable TraversableOnce, TraversableOnce , .

+1

, Scala 2.13 ( 2019 ) Traversable TraversableOnce: Iterable IterableOnce. ( )

IterableOnce :

A collection template feature that can only be viewed once or once or several times.

This time:

The goal is to provide a minimal interface without any sequential operations.
This allows third-party extensions, such as parallel Scala collections, to integrate at the level IterableOncewithout inheriting undesirable implementations.

0
source

Source: https://habr.com/ru/post/1622318/


All Articles