{"id":13709589,"url":"https://github.com/sigma-andex/purescript-barlow-lens","last_synced_at":"2026-02-09T23:02:10.086Z","repository":{"id":41969553,"uuid":"347410721","full_name":"sigma-andex/purescript-barlow-lens","owner":"sigma-andex","description":"Increase your magnification 🔭 and zoom deep into a record.","archived":false,"fork":false,"pushed_at":"2024-03-14T10:06:16.000Z","size":159,"stargazers_count":39,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-21T19:02:58.724Z","etag":null,"topics":["lenses","profunctor-optics","profunctors"],"latest_commit_sha":null,"homepage":"","language":"PureScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit-0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sigma-andex.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-03-13T15:45:53.000Z","updated_at":"2024-02-16T10:46:17.000Z","dependencies_parsed_at":"2024-05-08T00:46:14.710Z","dependency_job_id":null,"html_url":"https://github.com/sigma-andex/purescript-barlow-lens","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/sigma-andex/purescript-barlow-lens","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigma-andex%2Fpurescript-barlow-lens","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigma-andex%2Fpurescript-barlow-lens/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigma-andex%2Fpurescript-barlow-lens/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigma-andex%2Fpurescript-barlow-lens/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sigma-andex","download_url":"https://codeload.github.com/sigma-andex/purescript-barlow-lens/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigma-andex%2Fpurescript-barlow-lens/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29284740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T21:57:15.303Z","status":"ssl_error","status_checked_at":"2026-02-09T21:57:11.537Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["lenses","profunctor-optics","profunctors"],"created_at":"2024-08-02T23:00:42.121Z","updated_at":"2026-02-09T23:02:05.069Z","avatar_url":"https://github.com/sigma-andex.png","language":"PureScript","funding_links":[],"categories":["Lenses"],"sub_categories":[],"readme":"# purescript-barlow-lens 🔭\n\nBarlow lens increases your magnification and let's you see the stars ✨\n\n*In other words,* barlow lens makes creating complex lenses such as record lenses super simple.\n\n## Installation\n\n**Note:** Version `v1.0.0` requires Purescript \u003e `v0.15.10`. If you are on an older version, use [`v0.9.0`](https://github.com/sigma-andex/purescript-barlow-lens/tree/v0.9.0) instead or upgrade your Purescript version.\n\n```bash\nspago install barlow-lens\n```\n\n## tl;dr \n\n```purescript\nimport Data.Lens \nimport Data.Lens.Barlow\nimport Data.String (toUpper)\n\nsky = { zodiac: { virgo: { alpha: \"Spica\" } } }\n\nspica = view (barlow @\"zodiac.virgo.alpha\") sky\n-- \"Spica\"\nupped = over (barlow @\"zodiac.virgo.alpha\") toUpper sky\n-- { zodiac: { virgo: { alpha: \"SPICA\" } } }\n    \n-- alfa = view (barlow @\"zodiac.virgo.alfa\") sky \n-- doesn't compile\n```\n\nor use the barlow helpers to make it even shorter:\n\n```purescript\nimport Data.Lens.Barlow\nimport Data.Lens.Barlow.Helpers\nimport Data.String (toUpper)\n\nsky = { zodiac: { virgo: { alpha: \"Spica\" } } }\n\nspica = view @\"zodiac.virgo.alpha\" sky\n-- \"Spica\"\nupped = over @\"zodiac.virgo.alpha\" toUpper sky\n-- { zodiac: { virgo: { alpha: \"SPICA\" } } }\n```\n\n### Features \nBarlow supports lens creation for the following types:\n- 🥇 [`Records`](#tldr)\n- 📦🐈 [`Maybe`](#Maybe)\n- 🤷🏽‍♀️ [`Either`](#Either)\n- 📜 [`Array`](#Array-and-other-Traversables) (and other `Traversable`s)\n- 🎁 [`Newtype`](#Newtype)\n- 🤖 [`Data types`](#Data-types)\n\n### Deep sky 🌌\n\n#### Maybe \nUse `?` to zoom into a `Maybe`.\n\n```purescript \nimport Data.Maybe (Maybe(..))\nimport Data.Lens.Barlow\nimport Data.Lens.Barlow.Helpers\n\nsky =\n  { zodiac:\n      Just\n        { virgo:\n            Just\n              { alpha: Just \"Spica\"\n              }\n        }\n  }\n\nspica = preview @\"zodiac?.virgo?.alpha?\" sky\n```\n\n#### Either\nUse `\u003c` for `Left` and `\u003e` for `Right` to zoom into an `Either`.\n\n```purescript \nimport Data.Either (Either(..))\nimport Data.Maybe (Maybe(..))\nimport Data.Lens.Barlow\nimport Data.Lens.Barlow.Helpers\nimport Data.String (toUpper)\n\nsky =\n  { zodiac:\n      Right\n        { virgo:\n            Just\n              { alpha: Left \"Spica\"\n              }\n        }\n  }\n\nspica = preview @\"zodiac\u003e.virgo?.alpha\u003c\" sky\n```\n\n\n#### Array and other Traversables\nUse `+` to zoom into `Traversable`s like `Array`.\n\n```purescript \nimport Data.Maybe (Maybe(..))\nimport Data.Lens.Barlow\nimport Data.Lens.Barlow.Helpers\nimport Data.String (toUpper)\n\nsky =\n  { zodiac:\n      [ { virgo:\n            Just\n              { star: \"Spica\"\n              }\n        }\n      , { virgo:\n            Just\n              { star: \"Serpentis\"\n              }\n        }\n      ]\n  }\n\nupped = over @\"zodiac+.virgo?.star\" toUpper sky\n```\n\n#### Newtype\nUse `!` to zoom into a `Newtype`.\n\n```purescript\nimport Data.Lens.Barlow\nimport Data.Lens.Barlow.Helpers\nimport Data.Maybe (Maybe(..))\nimport Data.Newtype (class Newtype)\n\nnewtype Alpha = Alpha { alpha :: String }\ninstance Newtype Alpha { alpha :: String }\n\nsky =\n  { zodiac:\n      Just\n        { virgo:\n            Alpha { alpha: \"Spica\"\n            }\n        }\n  }\n\nspica = preview @\"zodiac?.virgo!.alpha\" sky\n```\n\n#### Data types\n\nBarlow supports zooming into arbitrary sum and product types as long as there is a `Generic` instance. \n\nUse `%\u003cNAME\u003e` to zoom into sum types, where `\u003cNAME\u003e` is the name of your data constructor. E.g. `%Virgo` for the data constructor `Virgo`. \n\nUse `%\u003cINDEX\u003e` to zoom into product types, where `\u003cINDEX\u003e` is an integer between 1 and 9. Note that counting for product types and tuples usually starts with 1 and not 0. So the first element of a product is `%1`.\n\nIt is more readable if you separate your sum lens from your product lens with a `.` dot. \n\n```purescript \nimport Data.Lens.Barlow\nimport Data.Lens.Barlow.Helpers\nimport Data.Generic.Rep (class Generic)\nimport Data.Show.Generic (genericShow)\nimport Data.String.Common (toUpper)\n\ndata Zodiac\n  = Carina { alpha :: String } \n  | Virgo { alpha :: String } { beta :: String } { gamma :: String } { delta :: String } \n  | CanisMaior String \n\nderive instance Generic Zodiac _\n\n-- Optionally derive a show instance\ninstance Show Zodiac where\n  show = genericShow\n\nsky =\n  { zodiac:\n      Virgo { alpha : \"Spica\"} { beta: \"β Vir\"} { gamma: \"γ Vir B\"} { delta: \"δ Vir\"}\n  }\n\nupped = over @\"zodiac.%Virgo.%4.delta\" toUpper sky\n-- { zodiac: Virgo { alpha : \"Spica\"} { beta: \"β Vir\"} { gamma: \"γ Vir B\"} { delta: \"Δ VIR\"} }\n```\n\n## Credits\n\nThis lib was heavily inspired by this incredible [blog post](https://blog.csongor.co.uk/purescript-safe-printf/#The%20problem). Thanks also to @i-am-the-slime for pushing me to go further and for reviewing my PRs. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigma-andex%2Fpurescript-barlow-lens","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigma-andex%2Fpurescript-barlow-lens","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigma-andex%2Fpurescript-barlow-lens/lists"}