Git Product home page Git Product logo

rxjava's Introduction

Getting started with RxJava

This is one of the repositories I use for studying Java. In here you can find a getting started with RxJava Observables.

Source: Introduction to RxJava by Hackers at Cambridge

What is in here?

  • A basic introduction to Rx Observables using RxJava library.
  • Creating an Observable of Fibonacci numbers
  • Handling fake user input through (guess what?) Observables
  • Handling real user input through an Observable that reads from system in
  • Some operators and logic

Fake user input:

public Observable<Integer> fakeUserInput() {
    Random random = new Random();
    return Observable.intervalRange(0, 100, 500, 50, MILLISECONDS)

            .concatMap(number -> Observable.just(random.nextInt(20))
                    .delay(random.nextInt(500), MILLISECONDS))
            .map(number -> random.nextInt(20));
}

Real user input

Observable<String> lines(BufferedReader reader) {
    return Observable.<String>create(subscriber -> {
        String line;

        while (StringUtils.isNotBlank(line = reader.readLine())) {
            subscriber.onNext(line);

            if(subscriber.isDisposed()) {
                break;
            }
        }

        subscriber.onComplete();
    }).subscribeOn(Schedulers.io());
}

Observable<String> linesFromInput() {
    return lines(new BufferedReader(new InputStreamReader(System.in)));
}

Dependencies

You need a JDK 8 installed in your machine in order to run this. If you don't have one, I recommend using SDKMan, it easily installs any JDK version you need. See how to download and use it here

How to run it?

Inside a terminal, just invoke .gradlew (on Mac and Linux) or gradlew.bat (Windows).

Disclaimer

This is, as said, just repository I created for study purposes. The code contained here is a slightly adapted version of the code you can see in the YouTube video series. If you plan to use it as a reference, do it AT YOUR OWN RISK. I don't take any responsibility for what you do.

About me

I am Felipe Lautenschlager. A java developer with years of Legacy systems experience seeking to improve my skills on more modern frameworks (not just Java).

If you want to get in touch, feel free to send me a message:

Twitter: @devLauten

LinkedIn: felipelauten

rxjava's People

Contributors

felipelauten avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.