{"id":16965031,"url":"https://github.com/propensive/panopticon","last_synced_at":"2026-02-14T04:51:40.777Z","repository":{"id":164678493,"uuid":"615053314","full_name":"propensive/panopticon","owner":"propensive","description":"Versatile and composable lenses for Scala","archived":false,"fork":false,"pushed_at":"2025-01-26T12:14:13.000Z","size":2159,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T07:46:36.802Z","etag":null,"topics":["lens","lenses","lenses-library","optics","scala"],"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/propensive.png","metadata":{"files":{"readme":".github/readme.md","changelog":null,"contributing":".github/contributing.md","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":"2023-03-16T21:23:05.000Z","updated_at":"2025-01-26T12:14:17.000Z","dependencies_parsed_at":"2023-10-16T18:54:28.413Z","dependency_job_id":"4399235b-ede1-4f7f-8c30-029e94261513","html_url":"https://github.com/propensive/panopticon","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/propensive%2Fpanopticon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fpanopticon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fpanopticon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fpanopticon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/propensive","download_url":"https://codeload.github.com/propensive/panopticon/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492875,"owners_count":21113162,"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":["lens","lenses","lenses-library","optics","scala"],"created_at":"2024-10-13T23:44:52.357Z","updated_at":"2026-02-14T04:51:35.752Z","avatar_url":"https://github.com/propensive.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[\u003cimg alt=\"GitHub Workflow\" src=\"https://img.shields.io/github/actions/workflow/status/propensive/panopticon/main.yml?style=for-the-badge\" height=\"24\"\u003e](https://github.com/propensive/panopticon/actions)\n[\u003cimg src=\"https://img.shields.io/discord/633198088311537684?color=8899f7\u0026label=DISCORD\u0026style=for-the-badge\" height=\"24\"\u003e](https://discord.com/invite/MBUrkTgMnA)\n\u003cimg src=\"/doc/images/github.png\" valign=\"middle\"\u003e\n\n# Panopticon\n\n__Versatile and composable lenses for Scala__\n\nA _lens_ is an object which is able to access and modify specific parts of a\n(potentially) complex immutable data structure. It consists of a _getter_ for\naccess, and a _setter_ for modification. For example, a lens could focus on the\n`id` field of a `User` case class; its getter would take an instance of `User`\nand return its `id`, while the setter would take an existing `User` instance\nand a new `id` value, and return a new instance of `User` with the new `id`,\nand all other fields unchanged.\n\nLenses are notable for their composability. A single lens can focus on a field\ninside a case class nested inside another case class, or more deeply nested\nfields. In such an example, a single lens, composed from simpler lenses, could\ncreate a new instance of the outermost case class with just one of its\ninnermost field modified, in a single operation, avoiding potentially very\ncomplex syntax involving making copies of each intermediate case class.\n\nPanopticon provides concise and elegant syntax for working with lenses.\n\n## Features\n\n- create lenses for accessing and modifying deeply-nested fields in case classes\n- no performance penalty at runtime over handwritten modification code\n- compose lenses with the `++` operator\n\n\n## Availability\n\n\n\n\n\n\n\n## Getting Started\n\nAll terms and types are defined in the `panopticon` package, which can be imported with,\n```scala\nimport panopticon.*\n```\n\n### Creating a Lens\n\nImagine we have two case classes,\n```scala\nimport anticipation.*\n\ncase class User(id: Int, name: Text, birthday: Date)\ncase class Date(day: Int, month: Int, year: Int)\n```\ndescribing users of a hypothetical system, and numerical calendar dates.\n\nWe can construct a `Lens` for modifying a user's name with:\n```scala\nval userName = Lens[User](_.name)\n```\n\nStep-by-step, the expression is a reference to the `Lens` factory object, the\ntype upon which the lens will operate (`User`), and a lambda from that type to\nthe field the lens will focus on. The `User` type cannot be inferred, but the\ntype of `name`, which is `Text`, will be inferred.\n\nSimilarly, we could construct a lens which accesses the month field of a `Date`\nwith `Lens[Date](_.month)`. Or we could construct a lens which directly access\nthe year of birth of a user, like so:\n```scala\nval userBirthYear = Lens[User](_.birthday.year)\n```\n\n### Applying Lenses\n\nIf we construct an instance of a `User` with,\n```scala\nval user = User(38295, t\"Bob Mason\", Date(12, 7, 1997))\n```\nthen we can always access the user's birth year with `user.birthday.year`, but\nwe can also use the lens created above, `userBirthYear`, like so:\n```scala\nval birthYear: Int = userBirthYear.get(user)\n```\n\nThis is unspectacular. But it becomes more useful for updating a user.\n\nWe can change that user's birth year with,\n```scala\nval user2: User = userBirthYear.set(user, 1995)\n```\nwhich compares favorably with the equivalent code written using the case\nclasses' `copy` methods:\n```scala\nval user2: User = user.copy(birthday = user.birthday.copy(year = 1995))\n```\n\nWe can also specify the lens inline in the expression, like so:\n```scala\nval user2: User = Lens[User](_.birthday.year).set(user, 1995)\n```\n\nThe saving on syntactic verbosity improves the deeper the nesting.\n\n### Composing Lenses\n\nAlthough the `userBirthYear` lens above was created in a single expression, it\nis also possible to construct it by composing a lens for `User#birthday` and a\nlens for `Date#year`, using the `++` operator:\n```scala\nval userBirthday = Lens[User](_.birthday)\nval dateYear = Lens[Date](_.year)\nval userBirthYear = userBirthday ++ dateYear\n```\n\n\n\n\n\n\n## Status\n\nPanopticon is classified as __embryotic__. For reference, Soundness projects are\ncategorized into one of the following five stability levels:\n\n- _embryonic_: for experimental or demonstrative purposes only, without any guarantees of longevity\n- _fledgling_: of proven utility, seeking contributions, but liable to significant redesigns\n- _maturescent_: major design decisions broady settled, seeking probatory adoption and refinement\n- _dependable_: production-ready, subject to controlled ongoing maintenance and enhancement; tagged as version `1.0.0` or later\n- _adamantine_: proven, reliable and production-ready, with no further breaking changes ever anticipated\n\nProjects at any stability level, even _embryonic_ projects, can still be used,\nas long as caution is taken to avoid a mismatch between the project's stability\nlevel and the required stability and maintainability of your own project.\n\nPanopticon is designed to be _small_. Its entire source code currently consists\nof 185 lines of code.\n\n## Building\n\nPanopticon will ultimately be built by Fury, when it is published. In the\nmeantime, two possibilities are offered, however they are acknowledged to be\nfragile, inadequately tested, and unsuitable for anything more than\nexperimentation. They are provided only for the necessity of providing _some_\nanswer to the question, \"how can I try Panopticon?\".\n\n1. *Copy the sources into your own project*\n   \n   Read the `fury` file in the repository root to understand Panopticon's build\n   structure, dependencies and source location; the file format should be short\n   and quite intuitive. Copy the sources into a source directory in your own\n   project, then repeat (recursively) for each of the dependencies.\n\n   The sources are compiled against the latest nightly release of Scala 3.\n   There should be no problem to compile the project together with all of its\n   dependencies in a single compilation.\n\n2. *Build with [Wrath](https://github.com/propensive/wrath/)*\n\n   Wrath is a bootstrapping script for building Panopticon and other projects in\n   the absence of a fully-featured build tool. It is designed to read the `fury`\n   file in the project directory, and produce a collection of JAR files which can\n   be added to a classpath, by compiling the project and all of its dependencies,\n   including the Scala compiler itself.\n   \n   Download the latest version of\n   [`wrath`](https://github.com/propensive/wrath/releases/latest), make it\n   executable, and add it to your path, for example by copying it to\n   `/usr/local/bin/`.\n\n   Clone this repository inside an empty directory, so that the build can\n   safely make clones of repositories it depends on as _peers_ of `panopticon`.\n   Run `wrath -F` in the repository root. This will download and compile the\n   latest version of Scala, as well as all of Panopticon's dependencies.\n\n   If the build was successful, the compiled JAR files can be found in the\n   `.wrath/dist` directory.\n\n## Contributing\n\nContributors to Panopticon are welcome and encouraged. New contributors may like\nto look for issues marked\n[beginner](https://github.com/propensive/panopticon/labels/beginner).\n\nWe suggest that all contributors read the [Contributing\nGuide](/contributing.md) to make the process of contributing to Panopticon\neasier.\n\nPlease __do not__ contact project maintainers privately with questions unless\nthere is a good reason to keep them private. While it can be tempting to\nrepsond to such questions, private answers cannot be shared with a wider\naudience, and it can result in duplication of effort.\n\n## Author\n\nPanopticon was designed and developed by Jon Pretty, and commercial support and\ntraining on all aspects of Scala 3 is available from [Propensive\nO\u0026Uuml;](https://propensive.com/).\n\n\n\n## Name\n\nThe _Panopticon_, meaning \"all-seeing\", was a concept for the design of\nprisons, created by Jeremy Bentham, a philosopher and social reformer. Its name\nis given to this library for the _seeing_ capabilities of lenses.\n\nIn general, Soundness project names are always chosen with some rationale,\nhowever it is usually frivolous. Each name is chosen for more for its\n_uniqueness_ and _intrigue_ than its concision or catchiness, and there is no\nbias towards names with positive or \"nice\" meanings—since many of the libraries\nperform some quite unpleasant tasks.\n\nNames should be English words, though many are obscure or archaic, and it\nshould be noted how willingly English adopts foreign words. Names are generally\nof Greek or Latin origin, and have often arrived in English via a romance\nlanguage.\n\n## Logo\n\nThe logo shows an optical lens.\n\n## License\n\nPanopticon is copyright \u0026copy; 2025 Jon Pretty \u0026 Propensive O\u0026Uuml;, and\nis made available under the [Apache 2.0 License](/license.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fpanopticon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpropensive%2Fpanopticon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fpanopticon/lists"}