A template trait for collections which can be traversed either once only or one or more times.
Note: IterableOnce does not extend IterableOnceOps. This is different than the general design of the collections library, which uses the following pattern:
trait Seq extends Iterable with SeqOps trait SeqOps extends IterableOps trait IndexedSeq extends Seq with IndexedSeqOps trait IndexedSeqOps extends SeqOps
The goal is to provide a minimal interface without any sequential operations. This allows third-party extension like Scala parallel collections to integrate at the level of IterableOnce without inheriting unwanted implementations.
| Supertypes | |
|---|---|
| Known subtypes | 257 types |
Iterator can be used only once
| Returns | The number of elements in this collection, if it can be cheaply computed, -1 otherwise. Cheaply usually means: Not requiring a collection traversal. |
|---|
Returns a scala.collection.Stepper for the elements of this collection.
The Stepper enables creating a Java stream to operate on the collection, see scala.jdk.StreamConverters. For collections holding primitive values, the Stepper can be used as an iterator which doesn't box the elements.
The implicit scala.collection.StepperShape parameter defines the resulting Stepper type according to the element type of this collection.
For collections of Int, Short, Byte or Char, an scala.collection.IntStepper is returned
For collections of Double or Float, a scala.collection.DoubleStepper is returned
For collections of Long a scala.collection.LongStepper is returned
For any other element type, an scala.collection.AnyStepper is returned
Note that this method is overridden in subclasses and the return type is refined to S with EfficientSplit, for example scala.collection.IndexedSeqOps.stepper. For Steppers marked with scala.collection.Stepper.EfficientSplit, the converters in scala.jdk.StreamConverters allow creating parallel streams, whereas bare Steppers can be converted only to sequential streams.
© 2002-2022 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://scala-lang.org/api/3.2.0/scala/collection/IterableOnce.html