Android Rxjava Operator List

Source: Internet
Author: User
Tags set time throwable

Preface

All the operators that are now in contact with the operator are all sorted in, easy to access, new will be added in the encounter. Synchronize updates with Rxjavalearn's readme.md.

operator Decision Tree
    • Create a observable directly (create action)
    • Combining multiple observable (combined operations)
    • Perform a transform operation on the data emitted by the observable (transform operation)
    • Take a specific value from the data emitted by the observable (filter operation)
    • Partial value of forwarding observable (conditional/Boolean/filter operation)
    • Evaluation of data sequence of observable emission (arithmetic/aggregation operation)
Create action

operator to create a observable

    • Create
      Create a observable from scratch by invoking the observer's method

    • Empty/never/throw
      Create special observable with restricted behavior

    • Defer
      Do not create this observable before the viewer subscribes, creating a new observable for each observer

    • Just
      Converts an object or collection of objects into a observable that will emit these objects

    • From
      Convert other objects or data structures to observable

    • Range
      Creates a observable,range operator that emits an integer sequence of the specified range, and launches the count number from start

    • Interval
      Interval to send a number, starting from 0. itself runs on the Schedulers.computation () line range

    • Repeat
      The repeat acts on the observable, and it repeats the Count times.

    • Timer
      The timer emits a number 0 after the specified time, noting that it is also running on computation Scheduler

Transform Operations

Change the data emitted by the observable to convert the data into the format we want,

    • Buffer
      The cache, which can be simply understood as caching, collects data from observable periodically into a collection, and then packs these data sets for launch, rather than firing one at a time

    • FlatMap
      A flattened map that transforms the data emitted by observable into a observables collection, and then flattens the data emitted by these observable into a single observable, which can be thought of as a process of expanding nested data structures.

    • GroupBy
      Grouping, the original observable is split into a observable collection, the original observable emitted data is grouped by key, each observable launch a different set of data

    • Map
      mapping, by applying a function transform to each item of the sequence observable the emitted data, essentially executing a function on each item in the sequence, the parameter of the function is the data item

    • Scan
      Scan, continuously apply a function to each item of the data sequence, and then emit the result consecutively, each result based on the previous result. Accumulator function.

    • Window
      window, periodically splits the data from observable into some observable windows, then launches these windows instead of firing one item at a time. Similar to buffer, but buffer emits data, window emits observable, and each observable emits a subset of the original observable data.

    • ToList
      Returns an Observable that emits a single item, a list composed of all the items emitted by the source Observable. Converts a observable to a list.

filtering Operations

Filter out the data we don't want in the data set. Used to select from the data emitted from the observable.

  • Throttlewithtimeout
    The source observable will be timed each time a data is emitted, and if the source observable has new data emitted before the set time is over, the data will be discarded and the timings restarted.

  • Debounce
    Only after a period of idle time to launch the data, in layman's terms, is if there is no operation for a period of time, to perform an operation. You can also limit flow based on a function. The return value of this function is a temporary observable,
    If the source observable is launching a new data, the previous data generated by the function of the temporary observable has not ended, not called OnComplete, then the previous data will be filtered out. If it is the last one, it will be fired.

  • Distinct
    Deduplication, filtering out all duplicate data items

  • Distinctutilchanged
    Filter out adjacent duplicates

  • ElementAt
    Take a value and take the data item at a specific location

  • Filter
    filter, filter out data items that are not tested by the predicate, and only emit the tested

  • First
    Takes the first one that satisfies the condition, such as no meeting condition data throws an exception. You can use TAKEFISRT () and only transfer oncomplete.
    Null data will throw a null pointer exception, to be sentenced to empty processing.
    Only the first data that satisfies the condition is taken. can be used with blockingobservable. You can convert a observable object to a Blockingobservable object by observable.toblocking or Blockingobservable.from method

  • Last
    Last item, only one final piece of data is emitted.

  • Ignoreelements
    Ignore all data and keep only termination notifications (onerror or oncompleted)

  • Sample
    Sampling, the regular launch of the latest data, is equal to the data sampling, some implementation called Throttlefirst

  • Throttlefirst
    Will periodically launch the first data emitted by the source observable in this time period.

  • Skip
    Skip the previous number of data

  • Skiplast
    Skip a few of the following data

  • Take
    Keep only a few previous items of data

  • Takelast
    Keep only a few subsequent items of data

  • Takefirst
    Empty pointer exception when null data is thrown, to be sentenced to null processing
    Same as first, but does not throw an exception when all data does not meet the criteria, just call OnComplete.

Combine Operations
  • And/then/when
    Combining two or more observable emitted datasets by pattern (and condition) and plan (then order)

  • Combinelatest
    When any one of the two observables emits a data, the latest data emitted by each observable is combined by a specified function (total two data), and then the result of the function is emitted.

    Two conditions must be met:
    1) All observable have been sent data.
    2) When the condition 1 is met, any one of the observable emits a single data, and all the observable's latest data is assembled and emitted in accordance with the provided function.

    Under these two conditions, some of the emitted data may be ignored.

  • Join
    Whenever a observable launches a data item, the data emitted by the two observable is combined and emitted as long as it is within the time window defined by another observable-emitted data item

    Parameter description:
    1) target observable to be combined by source observable
    2) A function that observable the data emitted from the source, and returns a observable, which determines the lifetime of the data emitted from the source observable by the observable life cycle.
    3) A function that observable the data emitted from the target, and returns a observable, which determines the lifetime of the target observable emitted data.
    4) A function that receives data emitted from the source observable and the target observable, and returns the final combined data.

  • Merge
    Merge two observable data sets into one
    The merge may let the merged observables emit data Interleaved (you can use the concat operator, which does not stagger the data, it will emit multiple observables in order, one after the other).

  • Startwith
    A specified data sequence or data item is emitted before the original observable data sequence is emitted.

    Inserts a specified item at the beginning of the data series
    You can also pass a observable to Startwith,
    It will insert that observable emitter before the data sequence emitted by the original observable. This can be seen as a reversal of the concat.

  • Switch, the implementation of Rxjava is Switchonnext
    Converts the observable of a sequence of emitted observable into such a observable: it launches the data that the observable recently launched.
    Used to convert a source observable that emits multiple small observable into a observable, and then launch the data emitted by these small observable.
    It is important to note that if a small observable is transmitting data, the source observable launches a new small observable, then the data emitted by the previous observable is discarded, The data emitted by the new small observable is fired directly.

  • Zip

    • Zip
    • Zipwith
      Package, using a specified function to combine the data emitted by multiple observable, and then emit the result of the function as a single data
      The ZIP operator combines the data emitted by multiple observable in order, with each data being combined only once and ordered.
      The amount of data that is eventually combined is determined by the observable that emits the least data.
Error Handling

These operators are used to recover from error notifications

    • Catch
      Capture, resume sequence operation, replace error with normal data, recover from OnError notification

      • Onerrorreturn
        When an error occurs, let observable emit a pre-defined data and gracefully terminate it without throwing an exception
      • Onerrorresumenext
        When an error occurs, another observable replaces the current observable and continues to emit data.
      • Onexceptionresumenext
        Similar to Onerrorresume, the difference is that it will judge the type of data thrown by OnError,
        If it is exception, another observable will be used instead of the original observable to continue to launch the data,
        Otherwise, the error will be distributed to subscriber.
    • Retry
      Retry, if observable fired an error notification, re-subscribe to it and expect it to terminate normally

      • Retry
        The retry operator re-subscribes when an error occurs, and can be repeated several times,
        So the data emitted may produce duplicates. If you repeat the specified number of times and there are errors, you will return the error to the Observer, which will drop onerror
      • Retrywhen
        When an error occurs, Retrywhen receives OnError's throwable as a parameter and returns a observable based on the defined function, and if the observable launches a data, it is re-subscribed.
        It is important to note that when using Retrywhen, because each re-subscription will produce an error, the obserbvable as a parameter will continuously emit data, using the Zipwith operator can limit the number of re-subscriptions, otherwise there will be unlimited re-subscription.
        will end normally, call oncompleted
Secondary Operations
  • Delay
    Delay the launch of the result data for some time

  • Delaysubscription
    Delay registering on Observer

  • Do
    The Do operator is to add a series of callback listeners to each stage of the observable's life cycle, which is triggered when observable executes to this stage.

    • Dooneach
      Observable triggers this callback every time a data is emitted, including not only OnNext but also onerror and oncompleted.

    • Doonnext
      Only the onnext will be triggered.

    • Doonsubscribe,doonunsubscribe
      The callback is triggered when the subscriber is subscribed and reversed.
      When a observable is terminated by onerror or oncompleted, all subscriber are reversed. Tied up in Android and life cycle, because some observable do not finish.

    • Doonsubscribeon
      Do some work before you start registering. is in the current thread, not subscribeon the specified thread.

    • Doonerror
      Triggers a callback when onerror occurs, and passes the Throwable object as a parameter into the callback function.

    • Dooncomplete
      Triggers a callback when the oncompleted occurs.

    • Doonterminate
      The callback will be triggered before the end of the observable, whether normal or abnormally terminated.

    • Finallydo,doafterterminate
      Triggers a callback at the end of the observable, whether normal or abnormally terminated.

  • Materialize,dematerialize
    The meterialize operator converts onnext/onerror/oncomplete into a notification object and emits it in the original order, dematerialize the opposite
    You can see the print values and types using Integernotification.getvalue () + "," + integernotification.getkind ().

  • Observeon
    Specify Subscriber scheduler (worker thread)

  • Subscribeon
    Specifies the scheduler on which the observable should execute

  • Serialize
    Force observable to emit data sequentially and the function is valid

  • Subscribe
    Actions performed after receiving data and notifications from observable

  • TimeInterval
    Converts a observable to a time-consuming observable between transmitting two data
    The timeinterval intercepts the emitted data, replacing the time interval between two and two data emitted. For the first emitted data, the time interval is the interval after the subscription to the first launch.

  • Timeout
    Adds a timeout mechanism that emits an error notification if no data is emitted over a specified period of time
    The timeout operator adds a timeout to observable, resets the timer every time a data is fired, and throws a timeout exception when the next data is not fired for more than a predetermined period.
    Rxjava will implement timeout as a number of different functions of the operator, such as the timeout after the use of a backup observable continue to launch data.

  • Timestamp
    Add a timestamp to each data item emitted by observable
    Timestamp will repack each data item and add a timestamp to indicate the time of each launch.

  • Using
    Create a one-time resource that exists only during the life cycle of observable

    The using operator creates a resource that survives within the observable life cycle, as well as understanding:
    We create a resource and use it, use a observable to limit the resource's use time, and when the observable terminates, the resource is destroyed.
    The using requires three parameters, namely:
    1) Create this one-time resource function
    2) Create a observable function
    3) function to release resources

  • Onbackpressurebuffer
    instructs an Observable it is emitting items faster than it observer can consume them to buffer these items Indefin Itely until they can be emitted.
    Observable the speed of production data is greater than the speed of observer consumption, it will throw missingbackpressureexception. Use this operator to cache data for observer consumption. Specific reference RxJava Tutorial Part IV: Concurrent data stream launch too fast how to do

conditions and Boolean operations

These operators can be used with single or multiple data items, or they can be used for observable

  • All
    Determine if all of the data items emitted by observable meet a certain condition

    The all operator judges all data emitted by the source observable according to a function, and the result of the final return is the result of this judgment.
    This function is applied to all data emitted and returns true if all are satisfied, otherwise false.

  • Amb
    The AMB operator can combine up to 9 observable to compete with each other.
    Which observable first launches the data (including OnError and OnComplete) will continue to launch the observable data, the other observable the data emitted will not be discarded.

  • Contains
    Determines whether the observable will emit a specified data item
    The contains operator is used to determine whether the data emitted by the source observable contains a certain data, and if the inclusion returns TRUE, returns False if the source observable has ended and the data has not been emitted.

  • IsEmpty
    The IsEmpty operator is used to determine if the source observable has transmitted data, and no data has been emitted to return true.
    Null is also a data

  • DefaultIfEmpty
    Launches data from the original observable, and if the original observable does not emit data, it launches a default data
    Determines whether the source observable emits data, and if the source observable emits the data, the data is emitted normally, and if not, a default data is emitted.

  • SequenceEqual
    Determine if two observable are in the same data sequence
    The sequenceequal operator is used to determine whether the data sequence emitted by the two observable is the same (the data emitted is the same, the data sequence is the same, the end state is the same), or False if the same return true

  • Skipuntil
    SKIPUNITL is based on a flag observable to judge, when this symbol observable no data emitted, all the source observable data will be skipped; When the flag observable fired a data, The data is started to be emitted normally.
    Wait until Skipuntil launches the data to emit the source observable data, and ignores the data for this time period.

  • SkipWhile
    SkipWhile is based on a function to determine whether to skip the data, when the return value of the function is true, the data is skipped from the source observable, and when the function returns FALSE, it starts to emit data normally.

  • Takeuntil
    and Skiputil exactly the opposite, just get the data before observable in Takeuntil

  • TakeWhile
    In contrast to SkipWhile, get data that satisfies skipwhile

arithmetic and aggregation operations
    • Concat
      Combine multiple observable into a single observable and emit data, and transmit the data strictly in sequence, the previous observable data is not fired, and the data behind the observable is not emitted.

    • Count
      The count operator is used to count the amount of data emitted by the source observable, and finally the number is emitted;
      If the source observable emits an error, the error is reported directly, and count does not emit statistics until the source observable is terminated.

    • Reduce
      The reduce operator uses a function to receive the computed results of the observable emitted data and functions as the next calculated parameter, outputting the final result.
      Similar to the scan operators we've seen before, only scan outputs the results of each calculation, and reduce only outputs the final result.

    • Collect
      The collect is used to collect data from the source observable to be collected into a single data structure, using two parameters:
      A function that produces a collection of data structures
      A function that receives the data structure generated by the first function and the data emitted by the source observable as a parameter.

Connection Operation

Some special observable that have precise and controllable subscription behavior

What is connectable Observable:
is a special kind of observable object, not to launch the data when Subscrib, but only to apply the Connect operator to start transmitting data,
So it can be used to control the timing of data launch more flexibly.

Use the publish operator to convert Observable to connectable Observable, which can then be controlled by connect.

    • Publish
      Converts a normal observable to a connected
      The publish operator is used to convert an ordinary Observable object into a connectable Observable. It is important to note that if the launch data is already started then the subscription can only receive data that is emitted later.

    • Connect
      The Connect operator is used to trigger connectable observable emission data.
      After applying the Connect operator, a subscription object is returned, and through this subscription object, we can invoke its Unsubscribe method to terminate the transmission of the data.
      In addition, the Connect operator can be used to start transmitting data if there is no subscriber subscription.

    • RefCount
      The refcount operator converts a connectable Observable object back into a normal Observable object, which triggers the launch of the data when subscribers subscribe.

    • Replay
      The replay operator returns a connectable Observable object and can cache its emitted data, so that even if a subscriber subscribes after the data is transmitted, it can receive data that was previously transmitted.
      However, we'd better limit the size of the cache by using the replay operator, otherwise the cached data is too much to occupy a large chunk of memory.
      The control of the cache can be achieved from two aspects of space and time.

      Return directly to a connectable observable without publish

Conversion Operations
    • To
Custom Operators
    • Lift
    • Compose

Android Rxjava Operator List

Related Article

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.