Check out the rest of the series:
Knowing your RxJava Operator Toolbelt 1: Creating Observables
Knowing your RxJava Operator Toolbelt 2: Transforming Observables
Knowing your RxJava Operator Toolbelt 3: Combining Observables
Knowing your RxJava Operator Toolbelt 5: Utility Observables

RxJava is Java (and Kotlin’s) form of Reactive Programming, and thus Android’s too. It bestows the ultimate power in async operations through the use of observables. If you’re new, check out my Hardly Comprehensive Introduction.

RxJava is a powerful tool that only gets better with how well you know it. It’s got a high skill cap, and how close you get to it is determined by how well you know your operators.

Filter operations are thankfully some of the simplest to understand and you’d be a real mug to have done some RxJava before and not know what ‘first’ does, so I’m gonna be blasting through these with a pOW!

Filter

Bare bones filter. You make the rules with a boolean.

Output

FirstElement

Emits only the first item and thus returns a maybe (there could be no first items at all). How can it get simpler than that?

If you want to return a single instead, you can use the firstOrError method which should be self-explanatory if you’re not an idiot.

Output

0

LastElement

Emits only the last item and thus returns a maybe. Just like with firstElement, you also have access to a lastOrError method.

Output

Skip

Skip the first n items… That’s it.

Output

SkipLast

Skip the last n items…. No seriously, that’s it.

Output

Take

Emit only the first n items or a set of items within a time period from starting the observables.

Output

TakeLast

Emit only the last n items. Or a set of items within a time period of the observable finishing.

Output

ElementAt

Emit only the element at n… That’s it.

Output

IgnoreElements

Don’t emit any items, but mirror the observable’s termination notification. Like turning the observable into a completable. It will do what it needs to try an emit those items, it just won’t actually emit them.

Output

Debounce

Whenever an item is emitted, set a timespan. All items emitted during that timespan will be ignored. A debounce in RxJava is as it would be anywhere.

Output

Distinct

All emissions shall be unique! Any duplicates will not be emitted.

Output

Sample

Periodic Time Intervals are set. At every interval, the most recent item of the observable will be emitted.

Output