{"id":19508656,"url":"https://github.com/commit451/reptar","last_synced_at":"2025-04-26T02:34:00.053Z","repository":{"id":83214008,"uuid":"75255769","full_name":"Commit451/Reptar","owner":"Commit451","description":"Roaring RxJava","archived":false,"fork":false,"pushed_at":"2022-06-27T04:33:53.000Z","size":174,"stargazers_count":94,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-04T07:04:31.790Z","etag":null,"topics":["android","kotlin","rxandroid","rxjava"],"latest_commit_sha":null,"homepage":"https://github.com/ReactiveX/RxJava","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Commit451.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-12-01T04:40:33.000Z","updated_at":"2025-01-22T22:52:25.000Z","dependencies_parsed_at":"2023-03-01T20:31:17.510Z","dependency_job_id":null,"html_url":"https://github.com/Commit451/Reptar","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Commit451%2FReptar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Commit451%2FReptar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Commit451%2FReptar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Commit451%2FReptar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Commit451","download_url":"https://codeload.github.com/Commit451/Reptar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250922214,"owners_count":21508290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","kotlin","rxandroid","rxjava"],"created_at":"2024-11-10T23:08:35.578Z","updated_at":"2025-04-26T02:33:59.733Z","avatar_url":"https://github.com/Commit451.png","language":"Java","readme":"# Reptar\nRoaring [RxJava](https://github.com/ReactiveX/RxJava). A collection of useful RxJava 2.X classes.\n\n[![Build Status](https://travis-ci.org/Commit451/Reptar.svg?branch=master)](https://travis-ci.org/Commit451/Reptar) [![](https://jitpack.io/v/Commit451/Reptar.svg)](https://jitpack.io/#Commit451/Reptar)\n\n# Gradle Dependency\nAdd the jitpack url to the project:\n```groovy\nallprojects {\n    repositories {\n        ...\n        maven { url \"https://jitpack.io\" }\n    }\n}\n```\nthen, in your app `build.gradle`\n```groovy\ndependencies {\n    compile \"com.github.Commit451.Reptar:reptar:latest.version.here\"\n    //for Retrofit support\n    compile \"com.github.Commit451.Reptar:reptar-retrofit:latest.version.here\"\n    //for Kotlin support\n    compile \"com.github.Commit451.Reptar:reptar-kotlin:latest.version.here\"\n}\n```\n\n# Usage\nUsage can be found in the sample project.\n\n### Observers\nFor instances where you only want to implement certain callbacks, use:\n* `AdapterObserver`\n* `AdapterSingleObserver`\n\n### Composable Observers\nOften times, you want to subscribe to `Observable`s and have certain rules surrounding the observers. For example, you may want to use a `SingleObserver`, but ignore any `CancellationException`s since your `Activity` or `Fragment` is probably destroyed when this exception is thrown. You could potentially override the `Observer` and do the check in the subclass. But, this can optional in tons of subclasses that all perform simple boolean checks.\n\n`ComposableSingleObserver` and `ComposableObserver` make it simple to add checks on the success and failure of observers. For example:\n```java\nsomeObservable\n    .subscribe(new ComposableSingleObserver\u003cBoolean\u003e() {\n        @Override\n        public void success(Boolean aBoolean) {\n            //do some success thing\n        }\n\n        @Override\n        public void error(Throwable t) {\n            //error block will never get CancellationExceptions\n            onHandleError(t);\n        }\n    }.add(new CancellationFailureChecker()));\n```\nCancellationFailureChecker:\n```java\npublic class CancellationFailureChecker implements FailureChecker {\n\n    @Override\n    public boolean check(Throwable t) {\n        return t instanceof CancellationException;\n    }\n}\n```\n\nYou could also just create an abstract Observer that you use throughout the app that contains these rules so that you do not have to repeat them:\n```java\npublic abstract class CustomSingleObserver\u003cT\u003e extends ComposableSingleObserver\u003cT\u003e {\n\n    public CustomSingleObserver() {\n        add(new CancellationFailureChecker());\n        //add other success and failure checks as desired\n    }\n\n}\n```\nSee `SuccessChecker` and `FailureChecker` for more.\n\n### Avoiding Null\nRxJava 2.x does not allow propagating null. Read more [here](https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#nulls). `null` is still something we may not want to have fall through into the `onError` block though. For instance, if we want to check if a value exists, we could say that `null` means no, and a valid value means yes.\n\nAs a replacement, we can use `Optional`. For example:\n```java\nOptional\u003cString\u003e optional;\nif (random.nextInt() % 2 == 0) {\n    optional = new Optional\u003c\u003e(\"hi\");\n} else {\n    optional = Optional.empty();\n}\nSingle.just(optional)\n        .subscribe(new ComposableSingleObserver\u003cOptional\u003cString\u003e\u003e() {\n            @Override\n            public void success(Optional\u003cString\u003e optional) {\n                if (optional.hasValue()) {\n                    Snackbar.make(root, \"Has a optional\", Snackbar.LENGTH_SHORT)\n                            .show();\n                } else {\n                    Snackbar.make(root, \"No optional\", Snackbar.LENGTH_SHORT)\n                            .show();\n                }\n            }\n\n            @Override\n            public void error(Throwable e) {\n                //Note that an empty optional would not be an error\n            }\n        });\n```\nThis is similar to an `Optional` in [Guava](https://github.com/google/guava/wiki/UsingAndAvoidingNullExplained#optional)\n\n# Retrofit Usage\nFor Retrofit, many times, you need to get the raw response from Retrofit, but you also want all non 2XX error codes to fall through to the `onError()`. For this, `ResponseSingleObservable` is perfect:\n```java\ngitHub.contributors(\"square\", \"okhttp\")\n    .subscribe(new ResponseSingleObserver\u003cList\u003cContributor\u003e\u003e() {\n        @Override\n        protected void responseSuccess(List\u003cContributor\u003e contributors) {\n            int responseCode = response().code();\n            //do what you need to with the response\n        }\n\n        @Override\n        public void error(Throwable e) {\n            if (e instanceof HttpException) {\n                //check the response code, do what you need to\n            } else {\n                //handle any other error\n            }\n        }\n    });\n```\nSimilarly, you can use `ResponseFunction` in replacement of `Function` to easily `flatMap` a optional without needing to worry about checking `.isSuccessful()` on the optional.\n\n# Kotlin Usage\nKotlin extensions allow for easy composition of Single and Observable for Android:\n```kotlin\ngitHub.contributors(\"jetbrains\", \"kotlin\")\n    .fromIoToMainThread()\n    .subscribe(object : CustomSingleObserver\u003cList\u003cContributor\u003e\u003e() {\n        override fun success(t: List\u003cContributor\u003e) {\n            Snackbar.make(root, \"It worked!\", Snackbar.LENGTH_SHORT)\n                    .show()\n        }\n\n        override fun error(t: Throwable) {\n            onHandleError(t)\n        }\n    })\n```\n\nLicense\n--------\n\n    Copyright 2017 Commit 451\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommit451%2Freptar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommit451%2Freptar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommit451%2Freptar/lists"}