{"id":13726690,"url":"https://github.com/Astrocoders/lenses-ppx","last_synced_at":"2025-05-07T22:30:28.786Z","repository":{"id":53509579,"uuid":"163108025","full_name":"Astrocoders/lenses-ppx","owner":"Astrocoders","description":"GADT lenses","archived":false,"fork":false,"pushed_at":"2021-10-16T17:05:25.000Z","size":232,"stargazers_count":104,"open_issues_count":8,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-30T07:08:58.711Z","etag":null,"topics":["ocaml","ppx","reasonml"],"latest_commit_sha":null,"homepage":"","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/Astrocoders.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":"2018-12-25T19:53:33.000Z","updated_at":"2024-11-05T00:40:45.000Z","dependencies_parsed_at":"2022-09-20T17:51:43.604Z","dependency_job_id":null,"html_url":"https://github.com/Astrocoders/lenses-ppx","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Astrocoders%2Flenses-ppx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Astrocoders%2Flenses-ppx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Astrocoders%2Flenses-ppx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Astrocoders%2Flenses-ppx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Astrocoders","download_url":"https://codeload.github.com/Astrocoders/lenses-ppx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252965069,"owners_count":21832817,"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":["ocaml","ppx","reasonml"],"created_at":"2024-08-03T01:03:16.784Z","updated_at":"2025-05-07T22:30:28.284Z","avatar_url":"https://github.com/Astrocoders.png","language":"Reason","funding_links":[],"categories":["PPXs","Reason"],"sub_categories":[],"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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAstrocoders%2Flenses-ppx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAstrocoders%2Flenses-ppx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAstrocoders%2Flenses-ppx/lists"}