You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Calling a terminal operation causes the iterators to run. These cannot be run more than
260
-
> once, so the stream is used up. Do not reuse a stream after a terminal operation is used.
260
+
> once, as the stream is used up. Do not reuse a stream after a terminal operation is used.
261
261
262
262
#### Embedded Collectors
263
263
@@ -284,6 +284,30 @@ expect(
284
284
285
285
We need to provide a `keyMapper` and a `valueMapper` function. In this example, the utility function `identity` is called to map the object to itself as the value in the map.
286
286
287
+
To get the maximum item in a `Stream` we use `max` (and for the minimum we use `min`):
288
+
289
+
```ts
290
+
const maxString =Stream.of('a', 'b', 'c)
291
+
.max(compareString); // an optional, containing 'c'
292
+
```
293
+
294
+
The result is an `Optional` which is empty when the `Stream` is empty.
295
+
296
+
We need to provide a comparator here, for which the utility function `compareString` can help us. If we're
297
+
using a `NumberStream` the comparator defaults to `compareNumber` and, thus, is optional.
298
+
299
+
We can build a comparator of a property using `comparingBy`:
`comparingBy` lets us compose a comparator from a function to select the property of the item, and then another
308
+
comparator. Or we can build our own comparator from scratch, following the same rules as a [sorting `compareFn`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description) in
309
+
JavaScript.
310
+
287
311
#### Collectors
288
312
289
313
The `collect` function uses a `Collector` to produce a final value from the contents of the Stream. This is
0 commit comments