{"id":17892408,"url":"https://github.com/toastal/select-prism","last_synced_at":"2025-03-23T00:32:34.734Z","repository":{"id":62419613,"uuid":"78899332","full_name":"toastal/select-prism","owner":"toastal","description":"Use a Monocle Prism to handle \u003cselect\u003e conflict between ADTs and Strings","archived":false,"fork":false,"pushed_at":"2021-07-04T10:17:38.000Z","size":19,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-18T15:54:36.903Z","etag":null,"topics":["adt","elm","optics","select","sum-types","union-types"],"latest_commit_sha":null,"homepage":"http://package.elm-lang.org/packages/toastal/select-prism/latest/Html-SelectPrism","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toastal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-14T00:55:26.000Z","updated_at":"2021-09-19T21:02:24.000Z","dependencies_parsed_at":"2022-11-01T17:00:35.465Z","dependency_job_id":null,"html_url":"https://github.com/toastal/select-prism","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toastal%2Fselect-prism","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toastal%2Fselect-prism/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toastal%2Fselect-prism/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toastal%2Fselect-prism/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toastal","download_url":"https://codeload.github.com/toastal/select-prism/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245040235,"owners_count":20551297,"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":["adt","elm","optics","select","sum-types","union-types"],"created_at":"2024-10-28T14:36:13.837Z","updated_at":"2025-03-23T00:32:34.478Z","avatar_url":"https://github.com/toastal.png","language":"Elm","funding_links":["https://liberapay.com/toastal/"],"categories":[],"sub_categories":[],"readme":"# select-prism\n\nA `\u003cselect\u003e` is basically the \u003cabbr title=\"user interface\"\u003eUI\u003c/abbr\u003e representation of a [union type](http://elm-lang.org/docs/syntax#union-types) or \u003cabbr title=\"algebraic data type\"\u003eADT\u003c/abbr\u003e.Using a `Prism` and it’s data structure for a data transformation that’s not quite isomorphic, we can use go from an \u003cabbr title=\"algebraic data type\"\u003eADT\u003c/abbr\u003e to a `String` and back like we’d prefer to do.\n\n\n```elm\nimport Html exposing (..)\nimport Html.SelectPrism exposing (selectp)\n\n\nview : Model -\u003e Html Msg\nview { selectedColor } =\n    -- Right Here ↓\n    selectp colorp ChangeColor selectedColor [] colorOptions\n\n\ncolorOptions : List ( String, Color )\ncolorOptions =\n    [ ( \"❤️  Red\", Red )\n    , ( \"💙 Blue\", Blue )\n    , ( \"💚 Green\", Green )\n    ]\n\n\ntype alias Model =\n    { selectedColor : Color }\n\n\ntype Msg\n    = ChangeColor (Result String Color)\n\n\ntype Color\n    = Red\n    | Blue\n    | Green\n\n\n{-| You the developer are responsible for this `Prism`s correctness\n-}\ncolorp : Prism String Color\ncolorp =\n    let\n        colorFromString : String -\u003e Maybe Color\n        colorFromString s =\n            case s of\n                \"red\" -\u003e\n                    Just Red\n\n                \"green\" -\u003e\n                    Just Green\n\n                \"blue\" -\u003e\n                    Just Blue\n\n                _ -\u003e\n                    Nothing\n\n        colorToString : Color -\u003e String\n        colorToString c =\n            case c of\n                Red -\u003e\n                    \"red\"\n\n                Green -\u003e\n                    \"green\"\n\n                Blue -\u003e\n                    \"blue\"\n    in\n        -- Using `Prism` as a constructor\n        Prism colorFromString colorToString\n```\n\nDo check out [the example](https://github.com/toastal/select-prism/blob/master/examples/HeartColors.elm) and/or read [my blog entry](https://toast.al/posts/2017-01-13-playing-with-prisms-for-the-not-so-isomorphic.html) which goes into more depth.\n\n---\n\n## Project \u0026 Community Notes\n\nThis project is regrettably available on [GitHub](https://github.com/toastal/select-prism). The Elm community has tied itself to the closed-source, Microsoft-owned code forge of GitHub for package registry and identity. This does not protect the privacy or freedom of its community members.\n\n---\n\n## License\n\nThis project is licensed under Apache License 2.0 - [LICENSE](./LICENSE) file for details.\n\n## Funding\n\nIf you want to make a small contribution to the maintanence of this \u0026 other projects\n\n- [Liberapay](https://liberapay.com/toastal/)\n- [Bitcoin: `39nLVxrXPnD772dEqWFwfZZbfTv5BvV89y`](bitcoin://39nLVxrXPnD772dEqWFwfZZbfTv5BvV89y?message=Funding%20toastal%E2%80%99s%20Elm%20select-prism%20development\n) (verified on [Keybase](https://keybase.io/toastal/sigchain#690220ca450a3e73ff800c3e059de111d9c1cd2fcdaf3d17578ad312093fff2c0f))\n- [Zcash: `t1a9pD1D2SDTTd7dbc15KnKsyYXtGcjHuZZ`](zcash://t1a9pD1D2SDTTd7dbc15KnKsyYXtGcjHuZZ?message=Funding%20toastal%E2%80%99s%20Elm%20select-prism%20development) (verified on [Keybase](https://keybase.io/toastal/sigchain#65c0114a3c8ffb46e39e4d8b5ee0c06c9eb97a02c4f6c42a2b157ca83b8c47c70f))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoastal%2Fselect-prism","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoastal%2Fselect-prism","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoastal%2Fselect-prism/lists"}