{"id":21040730,"url":"https://github.com/l-briand/tuple","last_synced_at":"2026-02-06T11:35:43.300Z","repository":{"id":248499367,"uuid":"828860697","full_name":"L-Briand/tuple","owner":"L-Briand","description":"Tuple class and serializer for kotlinx-serialization","archived":false,"fork":false,"pushed_at":"2024-08-14T09:48:51.000Z","size":314,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T15:14:22.157Z","etag":null,"topics":["kotlin","kotlin-library","kotlin-multiplatform","kotlin-multiplatform-library","tuple","tuples"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/L-Briand.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-07-15T09:18:08.000Z","updated_at":"2024-08-14T09:48:43.000Z","dependencies_parsed_at":"2024-08-14T11:07:56.544Z","dependency_job_id":"944bbb18-52e7-46ce-8bf4-c1cd43945eb3","html_url":"https://github.com/L-Briand/tuple","commit_stats":null,"previous_names":["l-briand/tuple"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/L-Briand/tuple","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Ftuple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Ftuple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Ftuple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Ftuple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/L-Briand","download_url":"https://codeload.github.com/L-Briand/tuple/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Ftuple/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29159600,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T07:18:23.844Z","status":"ssl_error","status_checked_at":"2026-02-06T07:13:32.659Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["kotlin","kotlin-library","kotlin-multiplatform","kotlin-multiplatform-library","tuple","tuples"],"created_at":"2024-11-19T13:47:49.088Z","updated_at":"2026-02-06T11:35:43.278Z","avatar_url":"https://github.com/L-Briand.png","language":"Kotlin","readme":"# Tuples for kotlinx-serialization\n\nThis package provides basic kotlin tuples classes which are serializable with kotlinx-serialization.\nThe tuples are encoded like an ordered typed list.\n\n```kotlin\nvar tup4 = tuple(1, \"a\", 2, \"b\")\nval json = Json.encodeToString(tup4)\nassert(\"\"\"[1,\"a\",2,\"b\"]\"\"\" == json)\n```\n\nYou can create tuples up to 12 elements with the function `tuple` or their classes `Tuple1` to `Tuple12`.\n\n# Gradle\n\nAdd the dependency to your Gradle dependency like so:\n\n```kotlin\ndependencies {\n    implementation(\"net.orandja.kt:tuple:1.0.1\")\n}\n```\n\nOr in your multiplatform project:\n\n```kotlin\nkotlin {\n    // config\n    sourceSets {\n        getByName(\"commonMain\") {\n            dependencies {\n                implementation(\"net.orandja.kt:tuple:1.0.1\")\n            }\n        }\n    }\n}\n```\n\n## Custom class serialization\n\nIf you need to serialize your own class into tuple, you can use the associated serializer. (like `Tuple3.Serializer`)\n\n```kotlin\n@Serializable(UserSerializer::class)\ndata class User(val name: String, val age: Int)\n\nclass UserSerializer : KSerializer\u003cUser\u003e {\n    private val delegate = Tuple2.Serializer(\n        String.serializer(),\n        Int.serializer()\n    )\n\n    override fun deserialize(decoder: Decoder): User {\n        val tuple = delegate.deserialize(decoder)\n        return User(tuple.first, tuple.second)\n    }\n\n    override fun serialize(encoder: Encoder, value: User) {\n        val tuple = tuple(value.name, value.age)\n        delegate.serialize(encoder, tuple)\n    }\n}\n\nfun main() {\n    val json = Json.encodeToString(User(\"John\", 23))\n    assert(\"\"\"[\"John\",23]\"\"\" == json)\n}\n```\n\n## More than 12 value tuples?\n\nI don't know if it's useful at this point, but you can copy the way the tuple classes are made and create your own\nTuple32 class.\n\nThis is how the Tuple4 class is created:\n\n```kotlin\nfun \u003cT1, T2, T3, T4\u003e tuple(\n    first: T1, second: T2, third: T3, fourth: T4\n) = Tuple4(first, second, third, fourth)\n\n@Serializable(Tuple4.Serializer::class)\ndata class Tuple4\u003cT1, T2, T3, T4\u003e(\n    val first: T1,\n    val second: T2,\n    val third: T3,\n    val fourth: T4,\n) : Tuple {\n    class Serializer\u003cT1, T2, T3, T4\u003e(\n        private val t1Serializer: KSerializer\u003cT1\u003e,\n        private val t2Serializer: KSerializer\u003cT2\u003e,\n        private val t3Serializer: KSerializer\u003cT3\u003e,\n        private val t4Serializer: KSerializer\u003cT4\u003e,\n    ) : AbstractTupleSerializer\u003cTuple4\u003cT1, T2, T3, T4\u003e\u003e(\n        t1Serializer.descriptor,\n        t2Serializer.descriptor,\n        t3Serializer.descriptor,\n        t4Serializer.descriptor,\n    ) {\n        override fun CompositeDecoder.deserializeTuple(): Tuple4\u003cT1, T2, T3, T4\u003e = tuple(\n            decode(0, t1Serializer),\n            decode(1, t2Serializer),\n            decode(2, t3Serializer),\n            decode(3, t4Serializer)\n        )\n\n        override fun CompositeEncoder.serializeTuple(value: Tuple4\u003cT1, T2, T3, T4\u003e) {\n            encode(0, t1Serializer, value.first)\n            encode(1, t2Serializer, value.second)\n            encode(2, t3Serializer, value.third)\n            encode(3, t4Serializer, value.fourth)\n        }\n    }\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl-briand%2Ftuple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl-briand%2Ftuple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl-briand%2Ftuple/lists"}