|
| 1 | +# RxKotlinOperators |
| 2 | + |
| 3 | +Learn RxKotlin with simple coding examples |
| 4 | + |
| 5 | + |
| 6 | +# Migration from RxKotlin 1.0 to RxKotlin 2.0 |
| 7 | + |
| 8 | +To allow having RxKotlin 1 and RxKotlin 2 side-by-side, RxKotlin 2 is under the maven coordinates io.reactivex.rxjava2:rxjava:2.x.y and classes are accessible below io.reactivex. |
| 9 | +Users switching from 1.x to 2.x have to re-organize their imports, but carefully. |
| 10 | + |
| 11 | +## Using RxKotlin 2.0 Library in your application |
| 12 | + |
| 13 | +Add this in your build.gradle |
| 14 | + |
| 15 | +`compile 'io.reactivex.rxjava2:rxjava:2.1.1'` |
| 16 | + |
| 17 | +If you are using RxAndroid also, then add the following |
| 18 | + |
| 19 | +`compile 'io.reactivex.rxjava2:rxandroid:2.0.1'` |
| 20 | + |
| 21 | +# Quick Look on few changes done in RxKotlin2 over RxKotlin1 |
| 22 | + |
| 23 | +### RxJava1/RxKotlin1 -> RxJava2/RxKotlin2 |
| 24 | + |
| 25 | +* `onCompleted` -> `onComplete` - without the trailing d |
| 26 | +* `Func1` -> `Function` |
| 27 | +* `Func2` -> `BiFunction` |
| 28 | +* `CompositeSubscription` -> `CompositeDisposable` |
| 29 | +* `limit` operator has been removed - Use `take` in RxKotlin2 |
| 30 | + |
| 31 | +....... and so on |
| 32 | + |
| 33 | +# RxOperators : |
| 34 | + |
| 35 | +* `map()` -> Transform the items emitted by an Observable by applying a function to each item |
| 36 | +* `zip()` -> Combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this function |
| 37 | +* `take()` -> Emit only the first n items emitted by an Observable |
| 38 | +* `timer()` -> Create an Observable that emits a particular item after a given delay |
| 39 | +* `flatMap()` -> Transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable |
| 40 | +* `interval()` -> Create an Observable that emits a sequence of integers spaced by a given time interval |
| 41 | +* `debounce()` -> Only emit an item from an Observable if a particular time span has passed without it emitting another item |
| 42 | +* `Single Observer` -> A Single is something like an Observable, but instead of emitting a series of values — anywhere from none at all to an infinite number — it always either emits one value or an error notification. |
| 43 | +* `reduce()` -> Apply a function to each item emitted by an Observable, sequentially, and emit the final value |
| 44 | +* `buffer()` -> Periodically gather items emitted by an Observable into bundles and emit these bundles rather than emitting the items one at a time |
| 45 | +* `filter()` -> Emit only those items from an Observable that pass a predicate test |
| 46 | +* `skip()` -> Suppress the first n items emitted by an Observable |
| 47 | +* `scan()` -> Apply a function to each item emitted by an Observable, sequentially, and emit each successive value |
| 48 | +* `replay()` -> Ensure that all observers see the same sequence of emitted items, even if they subscribe after the Observable has begun emitting items |
| 49 | +* `concat()` -> Emit the emissions from two or more Observables without interleaving them |
| 50 | +* `merge()` -> Combine multiple Observables into one by merging their emissions |
| 51 | +* `defer()` -> The Defer operator waits until an observer subscribes to it, and then it generates an Observable, typically with an Observable factory function. It does this afresh for each subscriber, so although each subscriber may think it is subscribing to the same Observable, in fact each subscriber gets its own individual sequence. |
| 52 | +* `distinct()` -> Suppress duplicate items emitted by an Observable |
| 53 | +* `Replay Subject` -> Replays events (in a configurable bounded or unbounded manner) to current and late Observers. |
| 54 | +* `Publish Subject` -> Subject that, once an Observer has subscribed, emits all subsequently observed items to the subscriber |
| 55 | +* `Behaviour Subject` -> Subject that emits the most recent item it has observed and all subsequent observed items to each subscribed Observer. |
| 56 | +* `Aync Subject` -> A Subject that emits the very last value followed by a completion event or the received error to Observers. |
| 57 | +* `Throttle First` -> Emit the first items emitted by an Observable within periodic time intervals |
| 58 | +* `amb()` -> Given two or more source Observables, emits all of the items from the first of these Observables to emit an item |
| 59 | +* `Catch` -> Recover from an onError notification by continuing the sequence without error |
| 60 | +* `Retry` -> If a source Observable emits an error, resubscribe to it in the hopes that it will complete without error |
| 61 | + |
| 62 | +* Coming More |
| 63 | +## TODO |
| 64 | + |
| 65 | +Adding more operator examples |
| 66 | + |
| 67 | +## Highlights : |
| 68 | +* [SimpleOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/SimpleOperatorActivity.kt) - Using `Simple` operator |
| 69 | +* [MapOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/transformingOperators/MapOperatorActivity.kt) - Using `Map` operator |
| 70 | +* [ZipOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/combiningOperators/ZipOperatorActivity.kt) - Using `Zip` observer |
| 71 | +* [DisposableOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/DisposableOperatorActivity.kt) - Using `Disposable` operator |
| 72 | +* [FlatMapOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/transformingOperators/FlatMapOperatorActivity.kt) - Using `FlatMap` Operator |
| 73 | +* [IntervalOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/creatingOperators/IntervalOperatorActivity.kt) - Using `Interval` Operator |
| 74 | +* [TakeOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/filteringOperators/TakeOperatorActivity.kt) - Using `Take` Operator |
| 75 | +* [TimerOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/TimerOperatorActivity.kt) - Using `Timer` Operator |
| 76 | +* [DebounceOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/filteringOperators/DebounceOperatorActivity.kt) - Using `Debounce` Operator |
| 77 | +* [SingleObserverOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/SingleObserverOperatorActivity.kt) - Using `Single Observer` Operator |
| 78 | +* [FlowableOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/FlowableOperatorActivity.kt) - Using `Flowable` |
| 79 | +* [ReduceOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/mathematicalOperators/ReduceOperatorActivity.kt) -Using `Reduce` Operator |
| 80 | +* [BufferOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/transformingOperators/BufferOperatorActivity.kt) -Using `Buffer` Operator |
| 81 | +* [FilterOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/filteringOperators/FilterOperatorActivity.kt) -Using `Filter` Operator |
| 82 | +* [SkipOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/filteringOperators/SkipOperatorActivity.kt) -Using `Skip` Operator |
| 83 | +* [ScanOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/transformingOperators/ScanOperatorActivity.kt) -Using `Scan` Operator |
| 84 | +* [ReplayOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/connectableOperators/ReplayOperatorActivity.kt) -Using `Replay` Operator |
| 85 | +* [ConcatOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/mathematicalOperators/ConcatOperatorActivity.kt) -Using `Concat` Operator |
| 86 | +* [MergeOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/combiningOperators/MergeOperatorActivity.kt) -Using `Merge` Operator |
| 87 | +* [DeferOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/creatingOperators/DeferOperatorActivity.kt) -Using `Defer` Operator |
| 88 | +* [DistinctOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/filteringOperators/DistinctOperatorActivity.kt) -Using `Distinct` Operator |
| 89 | +* [ReplaySubjectOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/connectableOperators/ReplaySubjectOperatorActivity.kt) -Using `Replay Subject` Operator |
| 90 | +* [PublishSubjectOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/connectableOperators/PublishSubjectOperatorActivity.kt) -Using `Publish Subject` Operator |
| 91 | +* [BehaviorSubjectActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/BehaviorSubjectActivity.kt) -Using `Behavior Subject` Operator |
| 92 | +* [AsyncSubjectOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/AsyncSubjectOperatorActivity.kt) -Using `Aync Subject` Operator |
| 93 | +* [ThrottleFirstOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/ThrottleFirstOperatorActivity.kt) -Using `Throttle First` Operator |
| 94 | +* [ThrottleLastOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/ThrottleLastOperatorActivity.kt) -Using `Throttle Last` Operator |
| 95 | +* [WindowOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/transformingOperatorsWindowOperatorActivity.kt) -Using `Window` Operator |
| 96 | +* [AmbOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/conditionalOperators/AmbOperatorActivity.kt) -Using `Amb` Operator |
| 97 | +* [DelayOperatorActivity](https://github.com/AnkitDroidGit/RxJava-RxKotlin-Android/blob/master/app/src/main/java/com/freeankit/rxjava2samples/ui/operators/utilityOperators/DelayOperatorActivity.kt) -Using `Delay` Operator |
| 98 | + |
| 99 | +* Coming More |
| 100 | + |
| 101 | + |
| 102 | +### Contact - Let's connect to learn together |
| 103 | +- [Twitter](https://twitter.com/KumarAnkitRKE) |
| 104 | +- [Github](https://github.com/AnkitDroidGit) |
| 105 | +- [LinkedIn](https://www.linkedin.com/in/kumarankitkumar/) |
| 106 | +- [Facebook](https://www.facebook.com/freeankit) |
| 107 | +- [Slack](https://ankitdroid.slack.com) |
| 108 | +- [Stackoverflow](https://stackoverflow.com/users/3282461/android) |
| 109 | +- [Android App](https://play.google.com/store/apps/details?id=com.freeankit.ankitprofile) |
| 110 | + |
| 111 | + |
| 112 | +### License |
| 113 | + |
| 114 | + Copyright 2017 Ankit Kumar |
| 115 | + |
| 116 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 117 | + you may not use this file except in compliance with the License. |
| 118 | + You may obtain a copy of the License at |
| 119 | + |
| 120 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 121 | + |
| 122 | + Unless required by applicable law or agreed to in writing, software |
| 123 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 124 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 125 | + See the License for the specific language governing permissions and |
| 126 | + limitations under the License. |
0 commit comments