Skip to content

Commit f029ed5

Browse files
committed
Improve README
Explaining widening conversions, fixing errors, and clarifying the role of Steppers in the API.
1 parent 2ffa4d7 commit f029ed5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,27 @@ class Test {
121121

122122
Scala collections gain `seqStream` and `parStream` as extension methods that produce a Java 8 Stream
123123
running sequentially or in parallel, respectively. These are automatically specialized to a primitive
124-
type if possible. For instance, `List(1,2).seqStream` produces an `IntStream`. Maps additionally have
124+
type if possible, including automatically applied widening conversions. For instance, `List(1,2).seqStream`
125+
produces an `IntStream`, and so does `List(1.toShort, 2.toShort).parStream`. Maps additionally have
125126
`seqKeyStream`, `seqValueStream`, `parKeyStream`, and `parValueStream` methods.
126127

127128
Scala collections also gain `accumulate` and `stepper` methods that produce utility collections that
128129
can be useful when working with Java 8 Streams. `accumulate` produces an `Accumulator` or its primitive
129130
counterpart (`DoubleAccumulator`, etc.), which is a low-level collection designed for efficient collection
130131
and dispatching of results to and from Streams. Unlike most collections, it can contain more than
131-
`Int.MaxValue` elements. `stepper` produces a `Stepper` which is a fusion of `Spliterator` and `Iterator`.
132-
`Stepper`s underlie the Scala collections' instances of Java 8 Streams.
132+
`Int.MaxValue` elements.
133+
134+
`stepper` produces a `Stepper` which is a fusion of `Spliterator` and `Iterator`. `Stepper`s underlie the Scala
135+
collections' instances of Java 8 Streams. Steppers are intended as low-level building blocks for streams.
136+
Usually you would not create them directly or call their methods but you can implement them alongside custom
137+
collections to get better performance when streaming from these collections.
133138

134139
Java 8 Streams gain `toScala[Coll]` and `accumulate` methods, to make it easy to produce Scala collections
135140
or Accumulators, respectively, from Java 8 Streams. For instance, `myStream.to[Vector]` will collect the
136141
contents of a Stream into a `scala.collection.immutable.Vector`. Note that standard sequential builders
137142
are used for collections, so this is best done to gather the results of an expensive computation.
138143

139-
Finally, there is a Java class, `ScalaStreamer`, that has a series of `from` methods that can be used to
144+
Finally, there is a Java class, `ScalaStreamSupport`, that has a series of `stream` methods that can be used to
140145
obtain Java 8 Streams from Scala collections from within Java.
141146

142147
#### Performance Considerations
@@ -218,7 +223,7 @@ def mapToSortedString[A](xs: Vector[A], f: A => String, sep: String) =
218223
#### Java Usage Example
219224

220225
To convert a Scala collection to a Java 8 Stream from within Java, it usually
221-
suffices to call `ScalaStreaming.from(xs)` on your collection `xs`. If `xs` is
226+
suffices to call `ScalaStreamSupport.stream(xs)` on your collection `xs`. If `xs` is
222227
a map, you may wish to get the keys or values alone by using `fromKeys` or
223228
`fromValues`. If the collection has an underlying representation that is not
224229
efficiently parallelized (e.g. `scala.collection.immutable.List`), then
@@ -237,14 +242,14 @@ Here is an example of conversion of a Scala collection within Java 8:
237242

238243
```java
239244
import scala.collection.mutable.ArrayBuffer;
240-
import scala.compat.java8.ScalaStreaming;
245+
import scala.compat.java8.ScalaStreamSupport;
241246

242247
public class StreamConvertersExample {
243248
public int MakeAndUseArrayBuffer() {
244249
ArrayBuffer<String> ab = new ArrayBuffer<String>();
245250
ab.$plus$eq("salmon");
246251
ab.$plus$eq("herring");
247-
return ScalaStreaming.from(ab).mapToInt(x -> x.length()).sum(); // 6+7 = 13
252+
return ScalaStreamSupport.stream(ab).mapToInt(x -> x.length()).sum(); // 6+7 = 13
248253
}
249254
}
250255
```

0 commit comments

Comments
 (0)