take

Pass n incoming elements downstream and then complete

Simple operators

Signature

Source.takeSource.take Flow.takeFlow.take

Description

Pass n incoming elements downstream and then complete

Example

Scala
sourceSource(1 to 5).take(3).runForeach(println)
// 1
// 2
// 3
Java
sourceSource.from(Arrays.asList(1, 2, 3, 4, 5)).take(3).runForeach(System.out::println, system);
// this will print:
// 1
// 2
// 3

Reactive Streams semantics

emits while the specified number of elements to take has not yet been reached

backpressures when downstream backpressures

completes when the defined number of elements has been taken or upstream completes