RxEither

Either type for RxJava

License

License

Categories

Categories

Net
GroupId

GroupId

net.jokubasdargis.rxeither
ArtifactId

ArtifactId

rxeither
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

RxEither
Either type for RxJava
Project URL

Project URL

https://github.com/eleventigers/RxEither/
Source Code Management

Source Code Management

https://github.com/eleventigers/RxEither/

Download rxeither

How to add to project

<!-- https://jarcasting.com/artifacts/net.jokubasdargis.rxeither/rxeither/ -->
<dependency>
    <groupId>net.jokubasdargis.rxeither</groupId>
    <artifactId>rxeither</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.jokubasdargis.rxeither/rxeither/
implementation 'net.jokubasdargis.rxeither:rxeither:1.2.0'
// https://jarcasting.com/artifacts/net.jokubasdargis.rxeither/rxeither/
implementation ("net.jokubasdargis.rxeither:rxeither:1.2.0")
'net.jokubasdargis.rxeither:rxeither:jar:1.2.0'
<dependency org="net.jokubasdargis.rxeither" name="rxeither" rev="1.2.0">
  <artifact name="rxeither" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.jokubasdargis.rxeither', module='rxeither', version='1.2.0')
)
libraryDependencies += "net.jokubasdargis.rxeither" % "rxeither" % "1.2.0"
[net.jokubasdargis.rxeither/rxeither "1.2.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.pacoworks.rxsealedunions » rxsealedunions jar 1.0.0
io.reactivex : rxjava jar 1.1.0

test (3)

Group / Artifact Type Version
com.google.truth : truth jar 0.27
junit : junit jar 4.12
org.mockito : mockito-core jar 2.0.36-beta

Project Modules

There are no modules declared in this project.

RxEither Build Status

Either is a value of one of two possible types.

Inspired by Jeffrey van Gogh's discussion with the Rx.Net users, RxEither is a port of Scala's Either for the RxJava world.

Usage

  • Progress reporting

    public class ProgressExample {
    
         public static void main(String[] args) {
                PublishSubject<Integer> progress = PublishSubject.create();
    
                Observable<String> results = Observable.fromCallable(() -> {
                    progress.onNext(0);
                    TimeUnit.SECONDS.sleep(1);
                    progress.onNext(100);
                    return "Hello, world!";
                }).subscribeOn(Schedulers.io());
    
                Observable<Either<Integer, String>> either = RxEither.from(progress, results).share();
    
                RxEither.filterLeft(either).subscribe(System.out::println);
                RxEither.filterRight(either).toBlocking().subscribe(System.out::println);
            }
    }

    Prints:

    0
    100
    Hello, world!
    
  • Switch

    public class SwitchActionExample {
    
        public static void main(String[] args) {
            System.out.println("Type Either a string or an Int: ");
    
            String in = "";
            Either<String, Integer> either;
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
                in = reader.readLine();
                either = Either.right(Integer.parseInt(in));
            } catch (NumberFormatException | IOException e) {
                either = Either.left(in);
            }
    
            either.fold(
                s -> {
                    System.out.println("You passed me the String: " + s);
                },
                x -> {
                    System.out.println(
                            "You passed me the Int: " + x
                                    + ", which I will increment. " + x + " + 1 = "
                                    + (x + 1));
                });
        }
    }

    Prints:

    Type Either a string or an Int:
    1
    You passed me the Int: 1, which I will increment. 1 + 1 = 2
    

Download

Maven:

<dependency>
  <groupId>net.jokubasdargis.rxeither</groupId>
  <artifactId>rxeither</artifactId>
  <version>1.2.0</version>
</dependency>

Gradle:

compile 'net.jokubasdargis.rxeither:rxeither:1.2.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2016 Jokubas Dargis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.2.0
1.1.0
1.0.1
1.0.0