{"id":20157580,"url":"https://github.com/g4s8/tuples","last_synced_at":"2025-04-09T22:53:09.721Z","repository":{"id":40548971,"uuid":"400426460","full_name":"g4s8/tuples","owner":"g4s8","description":"Object-oriented Java tuples","archived":false,"fork":false,"pushed_at":"2024-04-29T18:16:58.000Z","size":70,"stargazers_count":16,"open_issues_count":5,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T22:53:03.921Z","etag":null,"topics":["java","library","pairs","tuples","utils"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/g4s8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-27T07:30:54.000Z","updated_at":"2023-12-17T20:39:14.000Z","dependencies_parsed_at":"2023-02-09T16:30:28.034Z","dependency_job_id":"08b10770-1a42-41be-906d-123ce2e2f9c1","html_url":"https://github.com/g4s8/tuples","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g4s8%2Ftuples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g4s8%2Ftuples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g4s8%2Ftuples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g4s8%2Ftuples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/g4s8","download_url":"https://codeload.github.com/g4s8/tuples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125637,"owners_count":21051766,"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":["java","library","pairs","tuples","utils"],"created_at":"2024-11-13T23:46:57.766Z","updated_at":"2025-04-09T22:53:09.694Z","avatar_url":"https://github.com/g4s8.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Object oriented Java tuples.\n\n - No data accessors\n - No ugly class or method names ~`pair._1()`~, ~`new Tuple3()`~\n - All tuple types are interfaces\n - Strong encapsulation of tuples data\n - Standard tuple implementations are immutable\n - Built-in support of `equals`, `hashCode`, `toString`, `Serializable` in standard implementation\n\n[![CI checks](https://github.com/g4s8/tuples/actions/workflows/ci-checks.yml/badge.svg)](https://github.com/g4s8/tuples/actions/workflows/ci-checks.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/wtf.g4s8/tuples)](https://maven-badges.herokuapp.com/maven-central/wtf.g4s8/tuples)\n\n### Usage\n\nAdd dependency\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ewtf.g4s8\u003c/groupId\u003e\n    \u003cartifactId\u003etuples\u003c/artifactId\u003e\n\u003c/dependency\u003e\n```\n\nUsing in code:\n```java\n// creating new tuples\nvar pair = Pair.of(1, \"b\"); // \u003c1, \"b\"\u003e\nvar triplet = Triplet.of(4, false, 0.2); // \u003c4, false, 0.2\u003e\n\n// applying tuple data\nString result = pair.apply((i, s) -\u003e String.format(\"%s - %d\", s, i)); // b - 1\n\n// accepting tuple data\ntriplet.accept((i, b, d) -\u003e System.out.printf(\"%d - (%b) %f\\n\", i, b, d)); // 4 - (false) 0.2 \n\n// push and pop\nUnit\u003cInteger\u003e iUnit = Unit.of(1); // \u003c1\u003e\nPair\u003cInteger, String\u003e pair = unit.push(\"a\"); // \u003c1, \"a\"\u003e\nUnit\u003cString\u003e sUnit = pair.apply((i, s) -\u003e Pair.of(s, i)).pop(); // \u003c\"a\"\u003e\nTriplet\u003cString, Double, Boolean\u003e triplet = sUnit.push(1.1).push(true); // \u003c\"a\", 1.1, true\u003e\n\n// zipping iterables\nvar zip = Pair.zip(Arrays.asList(1, 2, 3), Arrays.asList(\"a\", \"b\", \"c\")); // [\u003c1, \"a\"\u003e, \u003c2, \"b\"\u003e, \u003c3, \"c\"\u003e]\n```\n\n### Design\n\nEach tuple object specify the behavior and encapsulates the data.\nTuple primitives are interfaces with just a minimal required methods.\nData is strongly encapsulated and can not be accessed directly.\nAll types are immutable.\nThe only was yo access the data is to call `accept` or `apply` methods.\n\nThere are three objects exist:\n - `Unit\u003cT\u003e` - singleton tuple\n - `Pair\u003cT, U\u003e` - pair of two value\n - `Triplet\u003cT, U, V\u003e` - three values\n\n### API\n\nEach tuple has two primary methods:\n - `apply(function)` - apply function to tuple data, return function result\n - `accept(consumer)` - consume tuple data, return nothing\n\nAnd additional methods to add or remove data:\n - `push(item)` - change tuple type by adding new element (unit -\u003e pair -\u003e triplet)\n - `pop()` - skip last element, reduce tuple size (triplet -\u003e pair -\u003e unit)\n\n### Constructing\n\nEach tuple type has factory method `of(...)`:\n - `Unit.of(T) -\u003e Unit\u003cT\u003e`\n - `Pair.of(T, U) -\u003e Pair\u003cT, U\u003e`\n - `Triplet.of(T, U, V) -\u003e Triplet\u003cT, U, V\u003e`\n\n### ZIP\n\nAlso, there are `zip` methods available to zip two or more lists:\n - `Pair.zip(Iterable\u003cT\u003e, Iterable\u003cU\u003e) -\u003e Iterable\u003cPair\u003cT, U\u003e\u003e`\n - `Triplet.zip(Iterable\u003cT\u003e, Iterable\u003cU\u003e, Iterable\u003cV\u003e) -\u003e Iterable\u003cTriplet\u003cT, U, V\u003e\u003e`\n\n### Optional\n\nUnit tuple has `maybe` method to convert from optional:\n - `Unit.maybe(Optional\u003cT\u003e) -\u003e Optional\u003cUnit\u003cT\u003e\u003e`\n\n### Extras\n\nAll standard tuple classes created from `of` factory method\nimplements `equals`, `hashCode` and `toString` methods.\n\n### Testing\n\nEach tuple type has Hamcrest matcher in `wtf.g4s8.tuples.hm` package\n(to use it, add `org.hamcrest:hamcrest` Maven dependency):\n - `UnitMatcher\u003cT\u003e` for `Unit\u003cT\u003e`\n - `PairMatcher\u003cT, U\u003e` for `Pair\u003cT, U\u003e`\n - `TripletMatcher\u003cT, U, V\u003e` for `Triplet\u003cT, U, V\u003e`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg4s8%2Ftuples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fg4s8%2Ftuples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg4s8%2Ftuples/lists"}