270 * .peek(e -> System.out.println("Filtered value: " + e));
271 * .map(mappingFunction)
272 * .peek(e -> System.out.println("Mapped value: " + e));
273 * .collect(Collectors.toIntSummaryStastistics());
274 * }</pre>
275 *
276 * @param action a <a href="package-summary.html#NonInterference">
277 * non-interfering</a> action to perform on the elements as
278 * they are consumed from the stream
279 * @return the new stream
280 */
281 IntStream peek(IntConsumer action);
282
283 /**
284 * Returns a stream consisting of the elements of this stream, truncated
285 * to be no longer than {@code maxSize} in length.
286 *
287 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
288 * stateful intermediate operation</a>.
289 *
290 * @param maxSize the number of elements the stream should be limited to
291 * @return the new stream
292 * @throws IllegalArgumentException if {@code maxSize} is negative
293 */
294 IntStream limit(long maxSize);
295
296 /**
297 * Returns a stream consisting of the remaining elements of this stream
298 * after discarding the first {@code startInclusive} elements of the stream.
299 * If this stream contains fewer than {@code startInclusive} elements then an
300 * empty stream will be returned.
301 *
302 * <p>This is a <a href="package-summary.html#StreamOps">stateful
303 * intermediate operation</a>.
304 *
305 * @param startInclusive the number of leading elements to skip
306 * @return the new stream
307 * @throws IllegalArgumentException if {@code startInclusive} is negative
308 */
309 IntStream substream(long startInclusive);
310
311 /**
312 * Returns a stream consisting of the remaining elements of this stream
313 * after discarding the first {@code startInclusive} elements and truncating
314 * the result to be no longer than {@code endExclusive - startInclusive}
315 * elements in length. If this stream contains fewer than
316 * {@code startInclusive} elements then an empty stream will be returned.
317 *
318 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
319 * stateful intermediate operation</a>.
320 *
321 * @param startInclusive the starting position of the substream, inclusive
322 * @param endExclusive the ending position of the substream, exclusive
323 * @return the new stream
324 * @throws IllegalArgumentException if {@code startInclusive} or
325 * {@code endExclusive} is negative or {@code startInclusive} is greater
326 * than {@code endExclusive}
327 */
328 IntStream substream(long startInclusive, long endExclusive);
329
330 /**
331 * Performs an action for each element of this stream.
332 *
333 * <p>This is a <a href="package-summary.html#StreamOps">terminal
334 * operation</a>.
335 *
336 * <p>For parallel stream pipelines, this operation does <em>not</em>
337 * guarantee to respect the encounter order of the stream, as doing so
338 * would sacrifice the benefit of parallelism. For any given element, the
339 * action may be performed at whatever time and in whatever thread the
340 * library chooses. If the action accesses shared state, it is
341 * responsible for providing the required synchronization.
342 *
343 * @param action a <a href="package-summary.html#NonInterference">
344 * non-interfering</a> action to perform on the elements
345 */
346 void forEach(IntConsumer action);
347
348 /**
|
270 * .peek(e -> System.out.println("Filtered value: " + e));
271 * .map(mappingFunction)
272 * .peek(e -> System.out.println("Mapped value: " + e));
273 * .collect(Collectors.toIntSummaryStastistics());
274 * }</pre>
275 *
276 * @param action a <a href="package-summary.html#NonInterference">
277 * non-interfering</a> action to perform on the elements as
278 * they are consumed from the stream
279 * @return the new stream
280 */
281 IntStream peek(IntConsumer action);
282
283 /**
284 * Returns a stream consisting of the elements of this stream, truncated
285 * to be no longer than {@code maxSize} in length.
286 *
287 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
288 * stateful intermediate operation</a>.
289 *
290 * @apiNote
291 * While {@code limit()} is generally a cheap operation on sequential
292 * stream pipelines, it can be quite expensive on ordered parallel pipelines,
293 * especially for large values of {@code maxSize}, since {@code limit(n)}
294 * is constrained to return not just any <em>n</em> elements, but the
295 * <em>first n</em> elements in the encounter order. Using an unordered
296 * stream source (such as {@link #generate(IntSupplier)}) or removing the
297 * ordering constraint with {@link #unordered()} may result in significant
298 * speedups of {@code limit()} in parallel pipelines, if the semantics of
299 * your situation permit. If consistency with encounter order is required,
300 * and you are experiencing poor performance or memory utilization with
301 * {@code limit()} in parallel pipelines, switching to sequential execution
302 * with {@link #sequential()} may improve performance.
303 *
304 * @param maxSize the number of elements the stream should be limited to
305 * @return the new stream
306 * @throws IllegalArgumentException if {@code maxSize} is negative
307 */
308 IntStream limit(long maxSize);
309
310 /**
311 * Returns a stream consisting of the remaining elements of this stream
312 * after discarding the first {@code n} elements of the stream.
313 * If this stream contains fewer than {@code n} elements then an
314 * empty stream will be returned.
315 *
316 * <p>This is a <a href="package-summary.html#StreamOps">stateful
317 * intermediate operation</a>.
318 *
319 * @apiNote
320 * While {@code skip()} is generally a cheap operation on sequential
321 * stream pipelines, it can be quite expensive on ordered parallel pipelines,
322 * especially for large values of {@code n}, since {@code skip(n)}
323 * is constrained to skip not just any <em>n</em> elements, but the
324 * <em>first n</em> elements in the encounter order. Using an unordered
325 * stream source (such as {@link #generate(Supplier)}) or removing the
326 * ordering constraint with {@link #unordered()} may result in significant
327 * speedups of {@code skip()} in parallel pipelines, if the semantics of
328 * your situation permit. If consistency with encounter order is required,
329 * and you are experiencing poor performance or memory utilization with
330 * {@code skip()} in parallel pipelines, switching to sequential execution
331 * with {@link #sequential()} may improve performance.
332 *
333 * @param n the number of leading elements to skip
334 * @return the new stream
335 * @throws IllegalArgumentException if {@code n} is negative
336 */
337 IntStream skip(long n);
338
339 /**
340 * Performs an action for each element of this stream.
341 *
342 * <p>This is a <a href="package-summary.html#StreamOps">terminal
343 * operation</a>.
344 *
345 * <p>For parallel stream pipelines, this operation does <em>not</em>
346 * guarantee to respect the encounter order of the stream, as doing so
347 * would sacrifice the benefit of parallelism. For any given element, the
348 * action may be performed at whatever time and in whatever thread the
349 * library chooses. If the action accesses shared state, it is
350 * responsible for providing the required synchronization.
351 *
352 * @param action a <a href="package-summary.html#NonInterference">
353 * non-interfering</a> action to perform on the elements
354 */
355 void forEach(IntConsumer action);
356
357 /**
|