Filter operator function of RxJava2.0 and filter operator of rxjava2.0

Source: Internet
Author: User

Filter operator function of RxJava2.0 and filter operator of rxjava2.0

Filter OPERATOR: filters or filters events sent by the observer and events accepted by the observer.

1. filter events based on conditions

(1), Filter ()

Purpose: Filter specific conditions.

Example:

Running result:

(2) ofType

Purpose: filter data of a specific data type.

Instance:

Running result:

(3) skip () skip a forward event/skipLast () skip a reverse event

Running result:

(4) distinct ()/distinctUntilChanged ()

Purpose: Filter repeated events/continuous recurring events in the event sequence.

Example of distinct:

Running result:

DistinctUntilChanged (): removes the example of continuous repetition.

Running result:

2. filter events based on the specified number of events

(1) take: specifies the maximum number of events that an observer can accept.

Running result:

(2) takeLast

Purpose: Specify the last few events that the observer can only receive.

Running result:

3. filter conditions based on the specified time

(1) throttleFirst

Purpose: within a certain period of time, only the first event within the specified period of time can be sent.

Running result:

(2) throttleLast

Purpose: only the last event of the specified time period can be sent.

Running result:

(3) sample: within a certain period of time, only the latest (last) events within the specified period of time are sent, which is similar to throttleLast ().

(4) throttleWithTimeout ()/debounce ()

Purpose: when a data event is sent, if the interval between two events is less than the specified time, the previous data will be lost, the last data is sent until no new data is sent within the specified time.

Running result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.