RxEither

Either type for RxJava

Лицензия

Лицензия

Категории

Категории

Сеть
Группа

Группа

net.jokubasdargis.rxeither
Идентификатор

Идентификатор

rxeither
Последняя версия

Последняя версия

1.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

RxEither
Either type for RxJava
Ссылка на сайт

Ссылка на сайт

https://github.com/eleventigers/RxEither/
Система контроля версий

Система контроля версий

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

Скачать rxeither

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
com.pacoworks.rxsealedunions » rxsealedunions jar 1.0.0
io.reactivex : rxjava jar 1.1.0

test (3)

Идентификатор библиотеки Тип Версия
com.google.truth : truth jar 0.27
junit : junit jar 4.12
org.mockito : mockito-core jar 2.0.36-beta

Модули Проекта

Данный проект не имеет модулей.

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.

Версии библиотеки

Версия
1.2.0
1.1.0
1.0.1
1.0.0