RxPartialApplication


Source link: https://github.com/pakoito/RxPartialApplication

RxPartialApplication

RxPartialApplication is a library to allow partial application on RxJava function primitives.

For the RxJava 2.X version please go to 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:

Func1<Integer, Integer> multiplyBy100 = RxPartialFunc.apply((int first, int second) -> {
 return first * second; 
}
, 100);
 int result = multiplyBy100.call(5);
 // result == 500

Single parameter applicator:

Action1<String> salutator = RxPartialAction.apply(applicator(), (String parameter) -> {
 System.out.println("Hello, " + parameter);
 
}
 );
 salutator.call("pakoito");
 // prints "Hello, pakoito" Action1<Integer> 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 <T> Action2<Action1<T>, T> applicator() {

  return (Action1<T> action, T parameter) -> {
 action.call(parameter);
 
}
; 
}

Filter only myself:

Func1<Object, Boolean> isMe = RxPartialFunc.apply(equalsFilter(), myUser);
 updatesFromDatabaseObservable().filter(isMe).map(toUser()).subscribe(/* ... */);
  ...  public static <T, U> Func2<T, U, Boolean> equalsFilter() {

  return (T first, U second) -> {
 return first.equals(second);
 
}
; 
}

You can also partially apply from the last parameter using applyEnd()

Func1<String, Observable<String>>> requestForUrl =

 RxPartialFunc.applyEnd(this::doNetworkRequest(), localDataStorage, ServerInfo.default(), RetrofitRequest.getInstance());
  requestForUrl.call("http://www.mycompany.com/api/users").subscribe(/* ... */);
  Observable<String> doNetworkRequest(String url, DataStorage storage, ServerInformation server, HttpClient client){

... 
}

Distribution

Add as a dependency to your build.gradle

repositories {

  ...
  maven {
 url "https://jitpack.io" 
}

  ... 
}

dependencies {

  ...
  compile 'com.github.pakoito:RxPartialApplication:1.1.0'
  ... 
}

or to your pom.xml

<repositories>
  <repository>

<id>jitpack.io</id>

<url>https://jitpack.io</url>
  </repository> </repositories>  <dependency>
  <groupId>com.github.pakoito</groupId>
  <artifactId>RxPartialApplication</artifactId>
  <version>1.1.0</version> </dependency>

License

Copyright (c) pakoito 2016

The Apache Software License, Version 2.0

See LICENSE.md

Resources

A simple change color of star in rating bar.

An android library that makes it really easy to deal with dynamic permissions. Based on the context, library automatically decides whether to show a dialog (in case app is in foreground) or a notification (in case permission is required by a background service).

An android library to effortlessly connect to available WiFi networks.

A view pager indicator view to deal with a large amount of pages. Nice scale and transition animations are supported.

Shows Ribbon view example.

This is a simple library to display text with multicolor.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes