{"id":17115736,"url":"https://github.com/pathikrit/sauron","last_synced_at":"2025-04-13T02:32:08.888Z","repository":{"id":139970262,"uuid":"31583468","full_name":"pathikrit/sauron","owner":"pathikrit","description":"Yet another Scala lens macro","archived":false,"fork":false,"pushed_at":"2015-03-22T20:11:28.000Z","size":351,"stargazers_count":167,"open_issues_count":2,"forks_count":9,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-26T20:21:20.134Z","etag":null,"topics":["lenses","scala","scala-macros"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/pathikrit.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}},"created_at":"2015-03-03T06:41:37.000Z","updated_at":"2024-12-10T21:24:39.000Z","dependencies_parsed_at":"2023-03-12T20:21:52.109Z","dependency_job_id":null,"html_url":"https://github.com/pathikrit/sauron","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pathikrit%2Fsauron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pathikrit%2Fsauron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pathikrit%2Fsauron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pathikrit%2Fsauron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pathikrit","download_url":"https://codeload.github.com/pathikrit/sauron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657793,"owners_count":21140842,"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":["lenses","scala","scala-macros"],"created_at":"2024-10-14T17:46:20.051Z","updated_at":"2025-04-13T02:32:08.588Z","avatar_url":"https://github.com/pathikrit.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"Sauron [![Circle CI](https://img.shields.io/circleci/project/pathikrit/sauron.svg)](https://circleci.com/gh/pathikrit/sauron) [![Download](https://api.bintray.com/packages/pathikrit/maven/sauron/images/download.svg)](https://bintray.com/pathikrit/maven/sauron/_latestVersion)\n--------\n\nLightweight [lens library](http://stackoverflow.com/questions/3900307/cleaner-way-to-update-nested-structures) in less than [50-lines of Scala](src/main/scala/com/github/pathikrit/sauron/package.scala):\n\n```scala\ncase class Person(address: Address)\ncase class Address(street: Street)\ncase class Street(name: String)\nval person = Person(Address(Street(\"1 Functional Rd.\")))\n\nimport com.github.pathikrit.sauron._\n\nlens(person)(_.address.street.name)(_.toUpperCase)\n```\n\nThere is zero overhead; the `lens` macro simply expands to this during compilation:\n```scala\nperson.copy(address = person.address.copy(\n  street = person.address.street.copy(\n    name = (person.address.street.name).toUpperCase)\n  )\n)\n```\n\n**Simple setters**:\n```scala\nlens(person)(_.address.street.name).setTo(\"1 Objective Rd.\")\n```\n\n**Reusable lenses**:\n```scala\nval f1 = lens(person)(_.address.street.name)\n\nval p1: Person = f1(_.toLowerCase)\nval p2: Person = f1(_.toUpperCase)\n```\n\n**Lens factories**: The above lens only updates a particular person. You can make even more generic lenses that can update any `Person`:\n```scala\nval f = lens(_: Person)(_.address.street.name)\n\nval p3: Person = f(p1)(_.toUpperCase)\nval p4: Person = f(p2)(_.toLowerCase)\n```\n\n**Lens composition**:\n```scala\nval lens1: Person ~~\u003e Address = lens(_: Person)(_.address)\nval lens2: Address ~~\u003e String = lens(_: Address)(_.street.name)\n\nval lens3: Person ~~\u003e String = lens1 andThenLens lens2 // or lens2 composeLens lens1\nval p5: Person = lens3(person)(_.toLowerCase)\n```\n\n**sbt**: In your `build.sbt`, add the following entries:\n\n```scala\nresolvers += Resolver.bintrayRepo(\"pathikrit\", \"maven\")\n\nlibraryDependencies += \"com.github.pathikrit\" %% \"sauron\" % \"1.1.0\"\n\naddCompilerPlugin(\"org.scalamacros\" % \"paradise\" % \"2.1.0-M5\" cross CrossVersion.full)\n```\n\nThis library is inspired by the clever work done by @adamw in his [quicklens](https://github.com/adamw/quicklens) library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpathikrit%2Fsauron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpathikrit%2Fsauron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpathikrit%2Fsauron/lists"}