{"id":21899071,"url":"https://github.com/johnsonlee/mutator","last_synced_at":"2025-04-15T18:53:02.100Z","repository":{"id":57735677,"uuid":"479027394","full_name":"johnsonlee/mutator","owner":"johnsonlee","description":"Mutator for Immutable Object","archived":false,"fork":false,"pushed_at":"2022-04-10T15:56:43.000Z","size":72,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T23:51:11.942Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","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/johnsonlee.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}},"created_at":"2022-04-07T14:46:37.000Z","updated_at":"2024-04-19T15:48:25.000Z","dependencies_parsed_at":"2022-08-23T20:30:52.833Z","dependency_job_id":null,"html_url":"https://github.com/johnsonlee/mutator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"johnsonlee/kotlin-library-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnsonlee%2Fmutator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnsonlee%2Fmutator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnsonlee%2Fmutator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnsonlee%2Fmutator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnsonlee","download_url":"https://codeload.github.com/johnsonlee/mutator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249135760,"owners_count":21218365,"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-11-28T14:37:22.021Z","updated_at":"2025-04-15T18:53:02.068Z","avatar_url":"https://github.com/johnsonlee.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mutator\n\n## Why Mutator?\n\nAs the [immutable object](https://en.wikipedia.org/wiki/Immutable_object) becomes the default pattern of functional programming language, such as [Value Object](https://en.wikipedia.org/wiki/Value_object) in Java, and [Data Class](https://kotlinlang.org/docs/data-classes.html) in Kotlin, even the immutable pattern has a lot of advantages, modifying properties of deeply nested immutable objects is still not very convenient, for example:\n\n```kotlin\ndata class Person(\n    val name: String,\n    val address: Address\n)\n\ndata class Address(\n    val nation: Nation,\n    val state: String,\n    val street: String\n)\n\ndata class Nation(\n    val name: String,\n    val code: String\n)\n```\n\nIf we want to modify the `Person.address.nation.code`, we have to write code like this:\n\n```kotlin\nval person = Person(...)\n// ...\nval clone = person.copy(\n    address = person.address.copy(\n        nation = person.address.nation.copy(\n            code = \"New Code\"\n        )       \n    )\n)\n```\n\n## Getting Started\n\n1. Add dependency into `build.gradle` or `build.gradle.kts`\n\n    ```kotlin\n    dependencies {\n        implementation(\"io.johnsonlee:mutator:1.2.0\")\n    }\n    ```\n\n1. Call the extension function `mutate(...)`\n\n    ```kotlin\n    val clone = person.mutate(Person::address, Address::nation, Nation::code, \"New Code\")\n    ```\n   \n    The code above is equivalent to the following\n\n    ```kotlin\n    val clone = person.copy(\n       address = person.address.copy(\n           nation = person.address.nation.copy(\n               code = \"New Code\"\n           )       \n       )\n    )\n    ```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnsonlee%2Fmutator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnsonlee%2Fmutator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnsonlee%2Fmutator/lists"}