Filtering items from multi

Learn how to filter and select items from a multi.

When observing a Multi, you may want to not forward all the received items to your downstream. Use the group to select items. To select items passing a given predicate, use

List<Integer> list = multi
        .select().where(i -> i > 6)

where accepts a predicate called for each item. If the predicate returns true, the item propagated downstream. Otherwise, it drops the item.

The predicate passed to where is synchronous. The when method provides an asynchronous version:

List<Integer> list2 = multi
        .select().when(i -> Uni.createFrom().item(i > 6))

when accepts a function called for each item. Unlike where where the predicate returns a boolean synchronously, the function returns a Uni<Boolean>. It forwards the item downstream if the uni produced by the function emits true. Otherwise, it drops the item.