Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pakoito/RxPartialApplication
Simple partial application for FuncN and ActionN on RxJava [STABLE]
https://github.com/pakoito/RxPartialApplication
Last synced: 25 days ago
JSON representation
Simple partial application for FuncN and ActionN on RxJava [STABLE]
- Host: GitHub
- URL: https://github.com/pakoito/RxPartialApplication
- Owner: pakoito
- License: other
- Created: 2016-02-14T20:34:41.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-22T00:09:14.000Z (over 7 years ago)
- Last Synced: 2024-11-15T23:30:33.046Z (27 days ago)
- Language: Java
- Homepage:
- Size: 76.2 KB
- Stars: 30
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-rxjava - RxPartialApplication - Simple partial application for FuncN and ActionN on RxJava. (Utilities)
README
# RxPartialApplication
RxPartialApplication is a library to allow [partial application](https://en.wikipedia.org/wiki/Partial_application) on RxJava function primitives.
For the RxJava 2.X version please go to [RxPartialApplication2](https://github.com/pakoito/RxPartialApplication2).
## Usage
RxPartialApplication contains two classes, `RxPartialAction` and `RxPartialFunc`. Each contains a set of `apply()` (apply parameters from left to right) and `applyEnd()` (apply parameters from right to left) methods to do partial application from any ActionN and FuncN to any type of a lower arity. For example, you can partially apply a Func6 object with 3 prefilled parameters to obtain a Func3 object to be reused.
Function to multiply numbers by 100:
```java
Func1 multiplyBy100 = RxPartialFunc.apply((int first, int second) -> { return first * second; }, 100);
int result = multiplyBy100.call(5); // result == 500
```Single parameter applicator:
```java
Action1 salutator = RxPartialAction.apply(applicator(), (String parameter) -> { System.out.println("Hello, " + parameter); } );
salutator.call("pakoito"); // prints "Hello, pakoito"
Action1 duplicator = RxPartialFunc.apply(applicator(), (int parameter) -> { System.out.println("Double of parameter is " + 2 * parameter); } );
duplicator.call(2); // prints "Double of parameter is 4"...
public static Action2, T> applicator() {
return (Action1 action, T parameter) -> { action.call(parameter); };
}
```Filter only myself:
```java
Func1 isMe = RxPartialFunc.apply(equalsFilter(), myUser);
updatesFromDatabaseObservable().filter(isMe).map(toUser()).subscribe(/* ... */);...
public static Func2 equalsFilter() {
return (T first, U second) -> { return first.equals(second); };
}
```You can also partially apply from the last parameter using `applyEnd()`
```java
Func1>> requestForUrl =
RxPartialFunc.applyEnd(this::doNetworkRequest(), localDataStorage, ServerInfo.default(), RetrofitRequest.getInstance());requestForUrl.call("http://www.mycompany.com/api/users").subscribe(/* ... */);
Observable doNetworkRequest(String url, DataStorage storage, ServerInformation server, HttpClient client){
...
}
```## Distribution
Add as a dependency to your `build.gradle`
```groovy
repositories {
...
maven { url "https://jitpack.io" }
...
}
dependencies {
...
compile 'com.github.pakoito:RxPartialApplication:1.1.0'
...
}
```
or to your `pom.xml````xml
jitpack.io
https://jitpack.io
com.github.pakoito
RxPartialApplication
1.1.0```
## License
Copyright (c) pakoito 2016
The Apache Software License, Version 2.0
See LICENSE.md