Is it possible to get the first element from flux without converting flux into stream?

akreddy.21 picture akreddy.21 · Mar 5, 2019 · Viewed 7.3k times · Source

Is it possible to get the first element from flux without converting flux into stream?

Answer

Simon Baslé picture Simon Baslé · Mar 6, 2019

Alternatively to take(1), if you need a Mono<T> that represents the first element of the Flux<T> you can use .next().

Or if you need the i-th element, use .elementAt(i) (must be sure that such an element exists though, unlike take and next which just return an empty publisher if not enough elements).