{"id":18828612,"url":"https://github.com/bizzabo/lens","last_synced_at":"2025-04-14T03:15:16.612Z","repository":{"id":57714907,"uuid":"53078232","full_name":"bizzabo/lens","owner":"bizzabo","description":"User-friendly lens syntax for mortals. Update values inside of nested case class instances without .copy .","archived":false,"fork":false,"pushed_at":"2018-12-18T14:37:50.000Z","size":12,"stargazers_count":31,"open_issues_count":1,"forks_count":1,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-04-14T03:15:05.915Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Scala","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/bizzabo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-03T19:46:02.000Z","updated_at":"2024-12-09T19:53:14.000Z","dependencies_parsed_at":"2022-09-26T21:31:10.961Z","dependency_job_id":null,"html_url":"https://github.com/bizzabo/lens","commit_stats":null,"previous_names":["xdotai/lens"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bizzabo%2Flens","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bizzabo%2Flens/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bizzabo%2Flens/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bizzabo%2Flens/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bizzabo","download_url":"https://codeload.github.com/bizzabo/lens/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813803,"owners_count":21165634,"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-08T01:33:44.589Z","updated_at":"2025-04-14T03:15:16.592Z","avatar_url":"https://github.com/bizzabo.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"## lens\n\n[![Join the chat at https://gitter.im/xdotai/lens](https://badges.gitter.im/xdotai/lens.svg)](https://gitter.im/xdotai/lens?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nUser-friendly lens syntax for mortals. Update values inside of nested case class instances without .copy .\n\nBased on [Monocle](https://github.com/julien-truffaut/Monocle).\nAlso see https://github.com/julien-truffaut/Monocle/pull/208 and https://github.com/julien-truffaut/Monocle/pull/204 .\n\n**Use with caution.** `.copy` and likewise `.lens` can make code hard to read.\nThey are conceptually creating patched versions of existing objects.\nIt can be hard for readers to reason about the patching, similar to how it is hard to reason about mutation.\nIf you can write your code in a way that does not need patching objects, prefer that.\nIf you can't, `.lens` is a nice alternative to `.copy`.\n\n\n### SBT Dependency\n\n#### Scala 2.11\n\n`\"ai.x\" %% \"lens\" % \"1.0.0\"`\n\n#### Scala 2.12\n\n`\"ai.x\" %% \"lens\" % \"2.0.0\"`\n\n### Usage\n\n```scala\ncase class C( d: Int )\ncase class B( c: C )\ncase class A( b: B )\nval a = A(B(C(3)))\n```\n\n#### Easy updates using `.lens`\n```scala\nimport ai.x.lens.ImplicitBoundLens\nA(B(C(5))) == a.lens(_.b.c.d).set( 5 )\nA(B(C(6))) == a.lens(_.b.c.d).modify( _ + 3 )\n```\n\n#### Verbose updates using `.copy`\n```scala\nA(B(C(5))) == a.copy(\n  b = a.b.copy(\n    c = a.b.c.copy(\n      d = 5\n)))\n\nA(B(C(6))) == a.copy(\n  b = a.b.copy(\n    c = a.b.c.copy(\n      d = a.b.c.d + 3\n)))\n```\n\n### Related Work\n\nai.x.lens is very similar to [quicklens](https://github.com/adamw/quicklens),\nwhich implements more features to slightly reduce code size. But this also mean more learning and remembering.\nIt's fair to make the trade-off in either direction. Check out quicklens if you want more features.\nUse ai.x.lens if you want something simpler.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbizzabo%2Flens","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbizzabo%2Flens","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbizzabo%2Flens/lists"}