Rxjava: filter + map in a single operator

Created on 11 Aug 2016  Â·  3Comments  Â·  Source: ReactiveX/RxJava

Hello there!

I've seen several times (specially when working with Buses or generic events) this kind of method chain:

observable.filter(clazz::isInstance).map(clazz::cast)

Would make sense to have another operator that does this already? Something like a filterClass or similar?

If so I could gladly create a PR with all the needed changes.

Cheers!

Most helpful comment

There is already operator for your case: ofType().

On Thu, 11 Aug 2016, 15:04 Alberto Ballano, [email protected]
wrote:

Hello there!

I've seen several times (specially when working with Buses or generic
events) this kind of method chain:

observable.filter(clazz::isInstance).map(clazz::cast)

Would make sense to have another operator that does this already?
Something like a filterClass or similar?

If so I could gladly create a PR with all the needed changes.

Cheers!

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ReactiveX/RxJava/issues/4341, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA7B3H_1WEOGG5KhaQB951Ux36Sf3Casks5qew_ZgaJpZM4JiDWv
.

All 3 comments

There is already operator for your case: ofType().

On Thu, 11 Aug 2016, 15:04 Alberto Ballano, [email protected]
wrote:

Hello there!

I've seen several times (specially when working with Buses or generic
events) this kind of method chain:

observable.filter(clazz::isInstance).map(clazz::cast)

Would make sense to have another operator that does this already?
Something like a filterClass or similar?

If so I could gladly create a PR with all the needed changes.

Cheers!

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ReactiveX/RxJava/issues/4341, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA7B3H_1WEOGG5KhaQB951Ux36Sf3Casks5qew_ZgaJpZM4JiDWv
.

Ouch, I must be blind, thank you Artem!

This has come up before and i always forget it exists. For discoverability
purposes I'd support the addition of an alias method (preferably beginning
with filter).

On Thu, 11 Aug 2016, 22:48 Alberto Ballano [email protected] wrote:

Closed #4341 https://github.com/ReactiveX/RxJava/issues/4341.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ReactiveX/RxJava/issues/4341#event-752605671, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AATa6zpUhLHj7KYTOwMNVlA59lQ4IPu_ks5qexn9gaJpZM4JiDWv
.

Was this page helpful?
0 / 5 - 0 ratings