{"id":20935532,"url":"https://github.com/rescriptbr/lenses-ppx","last_synced_at":"2026-03-15T19:39:14.851Z","repository":{"id":114862911,"uuid":"577422915","full_name":"rescriptbr/lenses-ppx","owner":"rescriptbr","description":"GADT setters/getters ","archived":false,"fork":false,"pushed_at":"2022-12-12T17:48:53.000Z","size":229,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-26T08:34:52.939Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Reason","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rescriptbr.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-12T17:48:04.000Z","updated_at":"2023-02-23T16:23:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"f64274a1-6fa0-4a29-bccb-286c6bf4b102","html_url":"https://github.com/rescriptbr/lenses-ppx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rescriptbr/lenses-ppx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rescriptbr%2Flenses-ppx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rescriptbr%2Flenses-ppx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rescriptbr%2Flenses-ppx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rescriptbr%2Flenses-ppx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rescriptbr","download_url":"https://codeload.github.com/rescriptbr/lenses-ppx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rescriptbr%2Flenses-ppx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30550479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-15T15:03:43.933Z","status":"ssl_error","status_checked_at":"2026-03-15T15:03:37.630Z","response_time":61,"last_error":"SSL_read: 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":[],"created_at":"2024-11-18T22:15:26.557Z","updated_at":"2026-03-15T19:39:14.832Z","avatar_url":"https://github.com/rescriptbr.png","language":"Reason","readme":"# What are GADTs?\n[GADTs: A primer](https://sketch.sh/s/yH0MJiujNSiofDWOU85loX/)\n\n# Why\nDifferently from normal lenses/optics the following approach allows for composing \"lenses\" into lists/arrays which is them useful for things like https://github.com/rescriptbr/reschema\n\n# Install\nInstall the last stable version\n\nFor ReScript\n```\nnpm install --save-dev lenses-ppx@latest\nor\nyarn add lenses-ppx@latest -D\n```\n\nFor BuckleScript \u003c 6\n```\nnpm install --save-dev lenses-ppx@4.0.0\nor\nyarn add lenses-ppx@4.0.0 -D\n```\n\n# Build\n```\nnpm run build\n```\n\n# Watch\n\n```\nnpm run watch\n```\n\nIn\n```rescript\nmodule StateLenses = %lenses(\n  type state = {\n    email: string,\n    age: int,\n  }\n)\n```\n\nOut\n\n```rescript\nmodule StateLenses = {\n  type state = {\n    email: string,\n    age: int,\n  }\n  type rec field\u003c_\u003e =\n    | Email: field\u003cstring\u003e\n    | Age: field\u003cint\u003e\n  let get:\n    type value. (state, field\u003cvalue\u003e) =\u003e value =\n    (state, field) =\u003e\n      switch field {\n      | Email =\u003e state.email\n      | Age =\u003e state.age\n      }\n  let set:\n    type value. (state, field\u003cvalue\u003e, value) =\u003e state =\n    (state, field, value) =\u003e\n      switch field {\n      | Email =\u003e {...state, email: value}\n      | Age =\u003e {...state, age: value}\n      }\n}\n```\nUsing\n```rescript\nopen StateLenses\n\nlet state = {email: \"fakenickels@gov.br\", age: 969}\n\nJs.log(state-\u003eget(Email))\nJs.log(state-\u003eget(Age))\n```\n\n\nAlternatively you can also use it like\n```rescript\n@lenses @decco\ntype bartux = {\n  color: string,\n  top: int,\n}\n\nlet bartux = {color: \"red\", top: 10}\n\nJs.log(bartux-\u003ebartux_get(Color))\nJs.log(bartux-\u003ebartux_set(Top, 20))\nJs.log(bartux_encode(bartux))\n```\n\n\nAlternatives\n\n- https://github.com/scoville/re-optic/blob/master/docs/lenses-ppx.md which is more strict and follows more closely Optics standards\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frescriptbr%2Flenses-ppx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frescriptbr%2Flenses-ppx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frescriptbr%2Flenses-ppx/lists"}