{"id":19260933,"url":"https://github.com/evant/auto-value-lens","last_synced_at":"2026-04-01T20:59:34.309Z","repository":{"id":144875439,"uuid":"101348416","full_name":"evant/auto-value-lens","owner":"evant","description":"AutoValue extension to create lenses for AutoValue properties","archived":false,"fork":false,"pushed_at":"2020-06-14T22:45:24.000Z","size":110,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-21T17:41:29.533Z","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/evant.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":"2017-08-25T00:18:36.000Z","updated_at":"2018-12-03T07:37:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"091aef7d-985e-4b5f-9c59-1332a4846350","html_url":"https://github.com/evant/auto-value-lens","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/evant/auto-value-lens","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fauto-value-lens","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fauto-value-lens/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fauto-value-lens/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fauto-value-lens/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evant","download_url":"https://codeload.github.com/evant/auto-value-lens/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fauto-value-lens/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31013966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T02:58:54.984Z","status":"ssl_error","status_checked_at":"2026-03-27T02:58:46.993Z","response_time":164,"last_error":"SSL_read: 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":[],"created_at":"2024-11-09T19:23:32.686Z","updated_at":"2026-03-27T03:17:11.907Z","avatar_url":"https://github.com/evant.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoValue: Lens Extension\n\nAn extension to google's [AutoValue](https://github.com/google/auto/tree/master/value) that creates\nlenses for the properties of an AutoValue object.\n\n## Download\n\n### Java\n\n```groovy\nbuildscript {\n  repositories {\n    maven { url \"https://plugins.gradle.org/m2/\" }\n  }\n  dependencies {\n    classpath \"net.ltgt.gradle:gradle-apt-plugin:0.11\"\n  }\n}\n\napply plugin: \"net.ltgt.apt\"\n\nrepositories {\n  maven { url \"https://oss.sonatype.org/content/repositories/snapshots\" }\n}\n\ndependencies {\n  compile 'me.tatarka.lens:lens:0.1-SNAPSHOT'\n  apt 'me.tatarka.lens:auto-value-lens:0.1-SNAPSHOT'\n  compileOnly 'me.tatarka.lens:auto-value-lens-annotations:0.1-SNAPSHOT'\n}\n```\n\n### Android\n\n```groovy\nrepositories {\n  maven { url \"https://oss.sonatype.org/content/repositories/snapshots\" }\n}\n\ndependencies {\n  compile 'me.tatarka.lens:lens:0.1-SNAPSHOT'\n  annotationProcessor 'me.tatarka.lens:auto-value-lens:0.1-SNAPSHOT'\n  compileOnly 'me.tatarka.lens:auto-value-lens-annotations:0.1-SNAPSHOT'\n}\n```\n\n## Usage\n\nCreate an interface (or abstract class) similar to how you would for a builder.\n\n```java\n@AutoValue public abstract class Foo {\n  public abstract String bar();\n  public abstract int baz();\n\n  @AutoValueLenses public interface Lenses {\n    Lens\u003cFoo, String\u003e bar();\n    IntLens\u003cFoo\u003e baz();\n  }\n\n  public static Foo create(String bar, int baz) {\n    return new AutoValue_Foo(bar, baz);\n  }\n\n  public static Lenses lenses() {\n    // The generated implementation of your interface.\n    return AutoValue_Foo.Lenses.instance;\n  }\n}\n```\n\nYou can now do functional queries and updates to your fields.\n\n```java\nFoo foo = Foo.create(\"test\", 1);\nFoo.lenses().bar().get(foo); // =\u003e \"test\"\nFoo.lenses().bar().set(foo, \"new\"); // =\u003e Foo(\"new\", 1)\nFoo.lenses().baz().updateAsInt(foo, v -\u003e v + 1); // =\u003e Foo(\"test\", 2)\n```\n\n## What are lenses? Why do I want them?\n\nA lens abstracts over 'getting' and 'setting' a value. (Where setting is a functional update). What\nmakes them nice is that they are _composeable_. This makes is nicer to update a nested property.\n\nFor example, say you have the AutoValue classes:\n\n```java\n@AutoValue public abstract Company {\n  public abstract List\u003cJob\u003e jobs();\n  ...\n}\n@AutoValue public abstract Job {\n  public abstract Map\u003cString, Person\u003e people();\n  ...\n}\n@AutoValue public abstract Person {\n  public abstract int age();\n  ...\n}\n```\n\nAnd you wanted to update the Person \"Sue\"'s age for job at index 1.\n\nWithout any extensions, you'd probably want to use builders:\n\n```java\nJob job = company.jobs().get(1);\nPerson person = job.people().get(\"Sue\");\nPerson newPerson = person.newBuilder()\n  .age(person.age() + 1)\n  .build();\nJob newJob = job.newBuilder()\n  .people(updateMap(job.people(), \"Sue\", newPerson))\n  .build();\nCompany newCompany = company.newBuilder()\n  .jobs(updateList(company.jobs(), 1, newJob))\n  .build();\n```\n\nThe actual logic is `person.age() + 1` but its' lost in the boilerplate!\n\nThere is an [auto-value-with](https://github.com/gabrielittner/auto-value-with) which gives you with\nmethods that does make this a little nicer, but it's still a lot. And more importantly, your update\nlogic is still lost in the middle of it.\n\n```java\nJob job = company.jobs().get(1);\nPerson person = job.people().get(\"Sue\");\nPerson newPerson = person.withAge(person.age() + 1);\nJob newJob = job.withPeople(updateMap(job.people(), \"Sue\", newPerson));\nCompany newCompany = company.withJobs(newJob);\n```\n\nWith lenses, you can separate your update logic from where it's applied. You build up a 'lens' into\nyour data, then you can directly manipulate it.\n\n```java\nIntLens\u003cCompany\u003e lens = Company.lenses().jobs()\n  .andThen(Lenses.listIndex(1))\n  .andThen(Job.lenses().people())\n  .andThen(Lenses.mapKey(\"Sue\"))\n  .andThen(Person.lenses().age());\n\nCompany newCompany = lens.updateAsInt(company, age -\u003e age + 1);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevant%2Fauto-value-lens","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevant%2Fauto-value-lens","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevant%2Fauto-value-lens/lists"}