{"id":19842874,"url":"https://github.com/deemp/haskell-barlow-lens","last_synced_at":"2025-02-28T19:41:41.660Z","repository":{"id":180734672,"uuid":"665625273","full_name":"deemp/haskell-barlow-lens","owner":"deemp","description":"lens via string literals","archived":false,"fork":false,"pushed_at":"2024-01-28T01:16:22.000Z","size":72,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-11T21:49:05.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deemp.png","metadata":{"files":{"readme":"README.hs","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":"2023-07-12T16:05:19.000Z","updated_at":"2023-08-31T10:23:45.000Z","dependencies_parsed_at":"2023-09-24T04:10:34.045Z","dependency_job_id":"306b0603-7cb7-49c9-a205-596c47dbdb14","html_url":"https://github.com/deemp/haskell-barlow-lens","commit_stats":null,"previous_names":["deemp/haskell-barlow-lens"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deemp%2Fhaskell-barlow-lens","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deemp%2Fhaskell-barlow-lens/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deemp%2Fhaskell-barlow-lens/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deemp%2Fhaskell-barlow-lens/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deemp","download_url":"https://codeload.github.com/deemp/haskell-barlow-lens/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241214016,"owners_count":19928226,"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-12T12:35:54.986Z","updated_at":"2025-02-28T19:41:41.634Z","avatar_url":"https://github.com/deemp.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"{-\n# barlow-lens\n\nBarlow lens increases your magnification and lets you see star sparkles.\n\nIn other words, `barlow-lens` simplifies creating complex lenses such as record lenses.\n\nThis package is a port of [purescript-barlow-lens](https://github.com/sigma-andex/purescript-barlow-lens) based on [generic-lens](https://hackage.haskell.org/package/generic-lens).\n\n## tl;dr\n-}\n\n{- FOURMOLU_DISABLE -}\n{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE DeriveGeneric #-}\n{-# LANGUAGE TypeApplications #-}\n{-# LANGUAGE DuplicateRecordFields #-}\n\n{- D -}\n{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}\n{-# HLINT ignore \"Use newtype instead of data\" #-}\n\n{- E -}\n{- FOURMOLU_ENABLE -}\n\nimport Control.Lens ((%~), (\u0026), (^.), (^..), (^?))\nimport Data.Char (toUpper)\nimport Data.Lens.Barlow\nimport GHC.Generics\n\n{- D -}\n\nmain :: IO ()\nmain = putStrLn \"hello\"\n\n{- E -}\n\n{-\n## Features\n\nBarlow creates optics for the following types:\n\n- 🥇 [`Records`](#tldr)\n- 📦🐈 [`Maybe`](#maybe)\n- 🤷🏽‍♀️ [`Either`](#either)\n- 📜 [`Traversables`](#traversables)\n- 🎁 [`Newtype`](#newtype)\n- 🤖 [`Data types`](#data-types)\n\n### Records\n\n`zodiac` ~ field @\"zodiac\"\n-}\n\ndata AlphaRecord = AlphaRecord {alpha :: String} deriving (Generic, Show)\ndata VirgoRecord = VirgoRecord {virgo :: AlphaRecord} deriving (Generic, Show)\ndata ZodiacRecord = ZodiacRecord {zodiac :: VirgoRecord} deriving (Generic, Show)\n\nsky :: ZodiacRecord\nsky = ZodiacRecord{zodiac = VirgoRecord{virgo = AlphaRecord{alpha = \"Spica\"}}}\n\nspica :: String\nspica = sky ^. (bw @\"zodiac.virgo.alpha\")\n\n-- \u003e\u003e\u003e spica\n-- \"Spica\"\n\n-- \u003e\u003e\u003e alfa = sky ^. barlow @\"zodiac.virgo.alfa\"\n-- The type AlphaRecord does not contain a field named 'alfa'.\n-- In the second argument of `(^.)', namely\n--   `barlow @\"zodiac.virgo.alfa\"'\n-- In the expression: sky ^. barlow @\"zodiac.virgo.alfa\"\n-- In an equation for `alfa':\n--     alfa = sky ^. barlow @\"zodiac.virgo.alfa\"\n\n{-\n### Maybe\n\nUse `?` to zoom into a `Maybe`.\n\n- `?` ~ `_Just :: Prism (Maybe a) (Maybe b) a b`\n-}\n\nnewtype AlphaMaybe = AlphaMaybe {alpha :: Maybe String} deriving (Generic, Show)\nnewtype VirgoMaybe = VirgoMaybe {virgo :: Maybe AlphaMaybe} deriving (Generic, Show)\nnewtype ZodiacMaybe = ZodiacMaybe {zodiac :: Maybe VirgoMaybe} deriving (Generic, Show)\n\nskyMaybe :: ZodiacMaybe\nskyMaybe = ZodiacMaybe{zodiac = Just VirgoMaybe{virgo = Just AlphaMaybe{alpha = Just \"Spica\"}}}\n\nspicaMaybe :: Maybe String\nspicaMaybe = skyMaybe ^? bw @\"zodiac?.virgo?.alpha?\"\n\n-- \u003e\u003e\u003e spicaMaybe\n-- Just \"Spica\"\n\n{-\n### Either\n\nUse `\u003c` for `Left` and `\u003e` for `Right` to zoom into an `Either`.\n\n- `\u003c` ~ `_Left :: Prism (Either a c) (Either b c) a b`\n- `\u003e` ~ `_Right :: Prism (Either c a) (Either c b) a b`\n-}\n\nnewtype AlphaLeft = AlphaLeft {alpha :: Either String ()} deriving (Generic, Show)\nnewtype VirgoRight = VirgoRight {virgo :: Either () AlphaLeft} deriving (Generic, Show)\nnewtype ZodiacEither = ZodiacEither {zodiac :: Either VirgoRight VirgoRight} deriving (Generic, Show)\n\nskyLeft :: ZodiacEither\nskyLeft = ZodiacEither{zodiac = Left VirgoRight{virgo = Right AlphaLeft{alpha = Left \"Spica\"}}}\n\nstarLeftRightLeft :: Maybe String\nstarLeftRightLeft = skyLeft ^? bw @\"zodiac\u003cvirgo\u003ealpha\u003c\"\n\n-- \u003e\u003e\u003e starLeftRightLeft\n-- Just \"Spica\"\n\nstarLeftLeft :: Maybe VirgoRight\nstarLeftLeft = skyLeft ^? bw @\"zodiac\u003e\"\n\n-- \u003e\u003e\u003e starLeftLeft\n-- Nothing\n\n{-\n### Traversables\n\nUse `+` to zoom into `Traversable`s.\n\n- `+` ~ `traversed :: Traversable f =\u003e IndexedTraversal Int (f a) (f b) a b`\n-}\n\nnewtype AlphaLeftRight = AlphaLeftRight {alpha :: Either String String} deriving (Generic, Show)\nnewtype VirgoLeftRight = VirgoLeftRight {virgo :: Either AlphaLeftRight AlphaLeftRight} deriving (Generic, Show)\nnewtype ZodiacList = ZodiacList {zodiac :: [VirgoLeftRight]} deriving (Generic, Show)\n\nskyList :: ZodiacList\nskyList =\n  ZodiacList\n    { zodiac =\n        [ VirgoLeftRight{virgo = Right AlphaLeftRight{alpha = Left \"Spica1\"}}\n        , VirgoLeftRight{virgo = Right AlphaLeftRight{alpha = Right \"Spica2\"}}\n        , VirgoLeftRight{virgo = Left AlphaLeftRight{alpha = Right \"Spica3\"}}\n        , VirgoLeftRight{virgo = Left AlphaLeftRight{alpha = Left \"Spica4\"}}\n        ]\n    }\n\nstarList :: [String]\nstarList = skyList ^.. bw @\"zodiac+virgo\u003ealpha\u003e\" \u0026 bw @\"++\" %~ toUpper\n\n-- \u003e\u003e\u003e starList\n-- [\"SPICA2\"]\n\nalphaRight :: [AlphaLeftRight]\nalphaRight = skyList ^.. bw @\"zodiac+virgo\u003e\"\n\n-- \u003e\u003e\u003e alphaRight\n-- [AlphaLeftRight {alpha = Left \"Spica1\"},AlphaLeftRight {alpha = Right \"Spica2\"}]\n\n{-\n### Newtype\n\nUse `!` to zoom into a `newtype`.\n\n- `!` ~ `wrappedIso :: Iso s t a b`\n-}\n\nnewtype AlphaNewtype = AlphaNewtype {alpha :: String} deriving (Generic)\nnewtype VirgoNewtype = VirgoNewtype {virgo :: AlphaNewtype} deriving (Generic)\nnewtype ZodiacNewtype = ZodiacNewtype {zodiac :: VirgoNewtype} deriving (Generic)\n\nskyNewtype :: ZodiacNewtype\nskyNewtype = ZodiacNewtype (VirgoNewtype (AlphaNewtype \"Spica\"))\n\nstarNewtype :: [Char]\nstarNewtype = skyNewtype ^. bw @\"zodiac!!\"\n\n-- \u003e\u003e\u003e starNewtype\n-- \"Spica\"\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. `%VirgoData` for the data constructor `VirgoData`.\n\nUse `%\u003cINDEX\u003e` to zoom into product types, where `\u003cINDEX\u003e` is a natural number.\nNote that counting for product types and tuples usually starts with 1 and not 0.\nSo 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- `%\u003cNAME\u003e` ~ `_Ctor :: AsConstructor ctor s t a b =\u003e Prism s t a b`\n- `%\u003cINDEX\u003e` ~ `position :: HasPosition i s t a b =\u003e Lens s t a b`\n-}\n\ndata ZodiacData\n  = CarinaData {alpha :: String}\n  | VirgoData {alpha :: String, beta :: String, gamma :: String, delta :: String}\n  | CanisMaiorData String\n  deriving (Generic)\n\nskyData :: ZodiacData\nskyData = VirgoData{alpha = \"Spica\", beta = \"Beta Vir\", gamma = \"Gamma Vir\", delta = \"Del Vir\"}\n\nstarData :: [Char]\nstarData = skyData ^. bw @\"%VirgoData%3\"\n\n-- \u003e\u003e\u003e starData\n-- \"Gamma Vir\"\n\n{-\n\n## Prerequisites\n\n\u003cdetails\u003e\n\n  \u003csummary\u003eSpoiler\u003c/summary\u003e\n\n- [flake.nix](./flake.nix) - code in this flake is extensively commented.\n- [codium-haskell](https://github.com/deemp/flakes/tree/main/templates/codium/haskell#readme) - this flake.\n- [codium-haskell-simple](https://github.com/deemp/flakes/tree/main/templates/codium/haskell-simple#readme) - a simplified version of this flake.\n- [language-tools/haskell](https://github.com/deemp/flakes/blob/main/language-tools/haskell/flake.nix) - a flake that conveniently provides `Haskell` tools.\n- [Conventions](https://github.com/deemp/flakes/blob/main/README/Conventions.md#dev-tools)\n- [codium-generic](https://github.com/deemp/flakes/tree/main/templates/codium/generic#readme) - info just about `VSCodium` with extensions.\n- [Haskell](https://github.com/deemp/flakes/blob/main/README/Haskell.md) - general info about `Haskell` tools.\n- [Troubleshooting](https://github.com/deemp/flakes/blob/main/README/Troubleshooting.md)\n- [Prerequisites](https://github.com/deemp/flakes#prerequisites)\n- [Nixpkgs support for incremental Haskell builds](https://www.haskellforall.com/2022/12/nixpkgs-support-for-incremental-haskell.html)\n- [flakes](https://github.com/deemp/flakes#readme) - my Nix flakes that may be useful for you.\n\n\u003c/details\u003e\n\n## Quick start\n\n1. Install Nix - see [how](https://github.com/deemp/flakes/blob/main/README/InstallNix.md).\n\n1. In a new terminal, start a devshell, build and test the app.\n\n    ```console\n    nix develop\n    cabal build\n    cabal test\n    ```\n\n1. Write `settings.json` and start `VSCodium`.\n\n    ```console\n    nix run .#writeSettings\n    nix run .#codium .\n    ```\n\n1. Open a `Haskell` file `app/Main.hs` and hover over a function.\n\n1. Wait until `Haskell Language Server` (`HLS`) starts giving you type info.\n\n1. Sometimes, `cabal` doesn't use the `Nix`-supplied packages ([issue](https://github.com/NixOS/nixpkgs/issues/130556#issuecomment-1114239002)). In this case, use `cabal v1-*` - commands.\n\n## Configs\n\n- [package.yaml](./package.yaml) - used by `stack` or `hpack` to generate a `.cabal`\n- [.markdownlint.jsonc](./.markdownlint.jsonc) - for `markdownlint` from the extension `davidanson.vscode-markdownlint`\n- [.ghcid](./.ghcid) - for [ghcid](https://github.com/ndmitchell/ghcid)\n- [.envrc](./.envrc) - for [direnv](https://github.com/direnv/direnv)\n- [fourmolu.yaml](./fourmolu.yaml) - for [fourmolu](https://github.com/fourmolu/fourmolu#configuration)\n- [ci.yaml](.github/workflows/ci.yaml) - a generated `GitHub Actions` workflow. See [workflows](https://github.com/deemp/flakes/tree/main/workflows). Generate a workflow via `nix run .#writeWorkflows`.\n- [hie.yaml](./hie.yaml) - a config for [hie-bios](https://github.com/haskell/hie-bios). Can be generated via [implicit-hie](https://github.com/Avi-D-coder/implicit-hie) to check the `Haskell Language Server` setup.\n-}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeemp%2Fhaskell-barlow-lens","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeemp%2Fhaskell-barlow-lens","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeemp%2Fhaskell-barlow-lens/lists"}