This project contains the examples of the 'Learning Reactive Programming With Java 8' book.
-
Of course you'll need Git :).
-
To run these examples you need Java 8, if you don't have it, navigate to Oracle's site and download/install it.
-
Now you can clone this project by running :
git clone https://github.com/meddle0x53/learning-rxjava.git
-
Navigate to the root of the project (
cd learning-rxjava
) and run :./gradlew build
-
This will download and install all the dependencies needed by the project and will compile it.
-
You can open the project with Eclipse and run the examples. You'll need the Gradle plugin for Eclipse.
./gradlew execute -Pchapter=1 -Pexample=ReactiveSumV1
Here are the descriptions of all the examples in the book.
This example is used in the book in the 'Comparing the Iterator pattern and the RxJava Observable' of the first chapter.
It demonstrates the difference between RxJava's Observables and the Iterators, by iterating over a list of strings.
The Observable.from
method is introduced here for the first time, as well as subscribing.
The example can be found here ObservableVSIterator
This is example demonstrates a reactive sum, which is updated on change of any of its collectors. It is demonstrates many of the features of RxJava, like Observers, Schedulers Observable transformations, filtering and combining.
The example can be found here ReactiveSumV1
Demonstrates creating and using lambdas, passing them to methods, that receive Functional Interfaces as parameters and references to existing methods.
The example can be found here Java8LambdasSyntaxIntroduction
Another implementation of the 'Reactive Sum', similar to the on of the first chapter, but it uses the new Java 8 syntax with lambdas.
The example can be found here ReactiveSumV2
Demonstrates pure and higher order functions. Applies higher order functions to other functions.
The example can be found here PureAndHigherOrderFunctions
Shows implementation and uses of a monad. The Optional monad.
The example can be found here Monads
Shows that Observables are not true monads. They are monad-like structures though and benefit from that.
The example can be found here ObservablesAndMonads
A set of examples of using the Observable.from method for creating Observables from collections, arrays and Iterables.
The example can be found here CreatingObservablesWithFrom
Demonstrates creating Observables using the Observable.from(Future) method.
The example can be found here CreatingObservablesWithFromFuture
Demonstrates creating Observables using the Observable.just method.
The example can be found here CreatingObservablesUsingJust
Demonstrates using Observable.interval, Observable.timer, Observable.error, Observable.never, Observable.empty and Observable.range for Obsevable creation.
The example can be found here CreatingObservablesUsingVariousFactoryMethods
Demonstrates using Observable.create for creating custom Observables. Contains unsubscribing and implementing unsubscribing logic in Observable.create.
The example can be found here ObservableCreateExample
Demonstration of ConnectableObservables and the methods realted to them - publish, refCount, share.
The example can be found here UsingConnectableObservables
Demonstrates using a Subject to subscribe to an Observables, propagating its notifications to multiple Subscribers.
The example can be found here SubjectsDemonstration
The 'Reactive Sum' is implemented through reactive properties, which are in fact BehaviorSubjects.
The example can be found here ReactiveSumV3
Demonstration of using map, flatMap, flatMapIterable and switchMap.
The example can be found here MappingExamples
Demonstration of using flatMap with an Observable created by directory stream, reading all the files from it, using Observables.
The example can be found here FlatMapAndFiles
Demonstrates how the groupBy operator can be used.
The example can be found here UsingGroupBy
Demonstration of working with the cast, materialize, timestamp and timeInterval operators.
The example can be found here VariousTransformationsDemonstration
Demonstrates the filter, takeLast, last, takeLastBuffer, lastOrDefault, skipLast, skip, first, elementAt, distinct, distinctUntilChanged and ofType operators.
The example can be found here FilteringExamples
Demonstrates the scan operator and contains an example of working with data using the majority of the operators learned through the chapter.
The example can be found here ScanAndUsingMultipleOperators
Demonstrates combining Observables using Observable.zip, Observable.merge and Observable.concat.
The example can be found here CombiningObservables
Demonstration of using the Observable.amb, Observable.takeWhile, Observable.takeUntil, Observable.skipUntil and Observable.defaultIfEmpty.
The example can be found here Conditionals
A demonstrates working with Observable.onErrorReturn, Observable.onErrorResumeNext and Observable.onExceptionResumeNext as well as retrying with Observable.retry and Observable.retryWhen.
The example can be found here HandlingErrors
Using multiple Observable operators in order to handle and augment an HTTP response from Github.
The example can be found here HttpRequestsExample
More information of Observable.interval and its default Scheduler. Contains an example of debugging information of the emitted items and the current Thread.
The example can be found here IntervalAndSchedulers
A collection of examples of using the different Schedulers.
The example can be found here SchedulersTypes
Demonstrates using subscribeOn and observeOn with Schedulers and Observables.
The example can be found here SubscribeOnAndObserveOn
Demonstrates parallelism by executing a number of requests in parallel.
The example can be found here ParallelRequestsExample
Demonstrates using the Observable#sample, Observable#buffer, Observable#window Observable#throttleLast, Observable#debounce, Observable#onBackpressureDrop and Observable#onBackpressureBuffer operators
The example can be found here BackpressureExamples
Examples of using BlockingObservable and their operators - BlockingObservable#forEach, BlockingObservable#first, BlockingObservable#next, BlockingObservable#last and BlockingObservable#single. Includes examples of Observable#count and Observable#toList combined with the Observable#toBlocking operator.
The example can be found here BlockingObservablesAndOperators
32. Unit test demonstrating different ways of testing Observables (Chapter 7, pages 131-133, 136-138)
Includes simple subscription test, test with BlockingObservable and test with TestSubscriber.
The example can be found here SortedObservableTest
A unit test testing the custom reateObservable#interval method.
The example can be found here CreateObservableIntervalTest
Demonstration of custom resource management with Observable#using.
The example can be found here ResourceManagement
Demonstrates implementing values with indices using lift and the custom operator Indexed.
The example can be found here Lift
The example can be found here IndexedTest
Example of implementing a Transformer and passing it to Observable#compose.
The example can be found here Compose
The example can be found here OddFilterTest