{"id":13803878,"url":"https://github.com/pakoito/RxFunctions","last_synced_at":"2025-05-13T17:30:41.723Z","repository":{"id":139227809,"uuid":"53002524","full_name":"pakoito/RxFunctions","owner":"pakoito","description":"Advanced Function composition to use with RxJava [STABLE]","archived":false,"fork":false,"pushed_at":"2017-01-21T19:12:31.000Z","size":62,"stargazers_count":49,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-03T00:52:30.817Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pakoito.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-03-02T22:51:26.000Z","updated_at":"2023-08-13T16:32:41.000Z","dependencies_parsed_at":"2024-01-03T01:49:09.664Z","dependency_job_id":null,"html_url":"https://github.com/pakoito/RxFunctions","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pakoito%2FRxFunctions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pakoito%2FRxFunctions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pakoito%2FRxFunctions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pakoito%2FRxFunctions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pakoito","download_url":"https://codeload.github.com/pakoito/RxFunctions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213870460,"owners_count":15650178,"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":[],"created_at":"2024-08-04T01:00:38.713Z","updated_at":"2024-08-04T01:02:56.347Z","avatar_url":"https://github.com/pakoito.png","language":"Java","funding_links":[],"categories":["Utilities"],"sub_categories":[],"readme":"# RxFunctions\n\nRxFunctions is a library to smooth RxJava usage by functionally composing functions.\n\nFor the RxJava 2.X version please go to [RxFunctions2](https://github.com/pakoito/RxFunctions2).\n\n## Rationale\n\nOftentimes you want to filter an `Observable` based off several criteria, i.e. get your users above a certain age that also live in a certain city; a string that should not be null or empty; or two objects being equal and both higher than 0.\n\nOther times you have to chain several map operations in a row, like converting your network data from string to dto, and from dto to a viewmodel.\n\nWhere you could write 2-9 operations every time that chain surfaces, instead you can compose them a create a new, single, more meaningful function.\n\n## Usage\n\n### General Functions\n\nThese functions work for any type and situation.\n\n#### Same\n\nIt allows you to chain `Func1\u003cT, T\u003e` that have the same input and output types, like two `Func1\u003cString String\u003e`, or six `Func1\u003cInteger, Integer\u003e`.\n\nThe end result is a `Func1\u003cT, T\u003e` that applies all of them sequentially and returns the result of the last one.\n\n#### Chain\n\nChain allows composition of functions that change type, but maintain a logical sequence. This is useful in map operations, like transforming a string into an object `Func1\u003cString, User\u003e`  and then retrieving one of the fields `Func1\u003cUser, List\u003cLocations\u003e\u003e` to finally compose our target class `Func1\u003cList\u003cLocations\u003e, LocationDirectory\u003e`.\n\nThe end result is a `Func1\u003cT, R\u003e` that applies all of them sequentially and returns a function that takes a parameter from the first one and returns the result of the last one.\n\n#### Combine\n\nCombine allows you to add up small operations into bigger ones. This case is common for object mutation, where you take one type parameter UserDto and have 4 functions `Func1\u003cUserDto, String\u003e` to transform its fields into strings used by a constructor function `Func4\u003cString, String, String, String, UserViewModel\u003e`.\n\nThe end result is a function that applies several `Func1\u003cT, U\u003e` `Func1\u003cT, V\u003e` `Func1\u003cT, W\u003e` parameters to the final aggregation function whose arity is one for each `Func3\u003cU, V, W, R\u003e`\n\n#### Reduce\n\nReduce is the most complicated to understand, as it allows for incremental composition. You provide:\n\n+ An initial value of type R\n\n+ An aggregation function of type `Func2\u003cR, R, R\u003e` that takes the previous state, a new value obtained from the function being evaluated, and returns the new state\n\n+ Any number of `Func1\u003cT, R\u003e`.\n\nEach function will be applied individually to the initial value by using the aggregation function until the last one gives the final result.\n\nOne example is the composition `and()` described below. It represents an operation of type `Func1\u003cT, Boolean\u003e`, which takes an initial value of true, a set of functions returning booleans, and applies aggregation by doing `\u0026\u0026` between them.\n\nThe end result is a function `Func1\u003cT, R\u003e` that has one input object, and returns the result of the internal aggregation.\n\n### Boolean functions\n\nThe next composers work only for `Func1\u003cT, Boolean\u003e`.\n\n#### Not\n\nNot negates the result of a `Func1\u003cT, Boolean\u003e` to allow the creation of opposite functions. The most common case is testing if a filter does not fit a function defined previously.\n\n#### And\n\nAnd aggregates the result of any number of `Func1\u003cT, Boolean\u003e` by means of `\u0026\u0026`. This helps composing more fine-grained filters into a single operation.\n\n#### Or\n\nAnd aggregates the result of any number of `Func1\u003cT, Boolean\u003e` by means of `||`. This helps composing more fine-grained filters into a single operation.\n\n## Examples\n\n```java\nFunc1\u003cInteger, Integer\u003e INCREMENT = num -\u003e num + 1;\nFunc1\u003cInteger, Integer\u003e SUM_FOUR =\n                        RxFunctions.\u003cInteger\u003esame(INCREMENT, INCREMENT, INCREMENT, INCREMENT).call(0) // returns 4\n\nFunc1\u003cInteger, String\u003e TO_STRING = num -\u003e num + \"\";\nFunc1\u003cInteger, String\u003e TO_INT = string -\u003e Integer.parseInt(string);\nFunc1\u003cInteger, String\u003e ROUND TRIPS =\n                        RxFunctions.chain(TO_STRING, TO_INT, TO_STRING, TO_INT, TO_STRING).call(5); // returns \"5\"\n```\n\nOr more complex cases:\n\n```java\nFunc1\u003cUser, Boolean\u003e BEST_USERS_FILTER =\n                            RxFunctions.and(NOT_NULL,\n                                            RxFunctions.not(IS_DEACTIVATED)\n                                            RxFunctions.or(HAS_MANY_PURCHASES,\n                                                            IS_HIGH_INCOME));\nList\u003cUser\u003e bestUsersList = getUserList().filter(BEST_USERS_FILTER).toList().toBlocking().first();\n```\n\n## Distribution\n\nAdd as a dependency to your `build.gradle`\n```groovy\nrepositories {\n    ...\n    maven { url \"https://jitpack.io\" }\n    ...\n}\n    \ndependencies {\n    ...\n    compile 'com.github.pakoito:RxFunctions:1.0.0'\n    ...\n}\n```\nor to your `pom.xml`\n```xml\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003ejitpack.io\u003c/id\u003e\n        \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.pakoito\u003c/groupId\u003e\n    \u003cartifactId\u003eRxFunctions\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## License\n\nCopyright (c) pakoito 2016\n\nThe Apache Software License, Version 2.0\n\nSee LICENSE.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpakoito%2FRxFunctions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpakoito%2FRxFunctions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpakoito%2FRxFunctions/lists"}