{"id":13726323,"url":"https://github.com/jaredly/let-anything","last_synced_at":"2025-08-03T03:36:47.701Z","repository":{"id":57290015,"uuid":"147468899","full_name":"jaredly/let-anything","owner":"jaredly","description":"Deprecated, use the reasonml-community one","archived":false,"fork":false,"pushed_at":"2019-11-20T16:36:18.000Z","size":47,"stargazers_count":98,"open_issues_count":4,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T09:51:34.597Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/reasonml-community/let-anything","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredly.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-05T06:14:54.000Z","updated_at":"2024-06-04T21:30:06.000Z","dependencies_parsed_at":"2022-08-25T05:20:32.156Z","dependency_job_id":null,"html_url":"https://github.com/jaredly/let-anything","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2Flet-anything","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2Flet-anything/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2Flet-anything/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2Flet-anything/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredly","download_url":"https://codeload.github.com/jaredly/let-anything/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248967101,"owners_count":21190896,"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-08-03T01:02:59.235Z","updated_at":"2025-04-14T21:46:31.179Z","avatar_url":"https://github.com/jaredly.png","language":"OCaml","funding_links":[],"categories":["PPXs","OCaml"],"sub_categories":[],"readme":"# Deprecated, use the [reasonml-community](https://github.com/reasonml-community/let-anything) one\n\n# let%Anything\n\nThis is a ppx that looks for `let%Anything`, where Anything is a valid module identifier (e.g. captialized), and turns it into `Anything.let_(value, pattern =\u003e continuation)`.\n\nIt's an exploration of [this PR to the reason repo](https://github.com/facebook/reason/pull/2140).\n\nHere's an example of using it ([source](https://github.com/notablemind/renm/blob/949e1583d4df5e6d61ea066767a52828f8f8069b/src/core/Store.re#L116\n))\n```re\nlet%Opt node = get(store, id);\nlet%Opt parent = get(store, node.parent);\nSome((\n  [NodeChildren(parent.id, parent.children |. List.keep((!=)(node.id))), DeleteNode(node.id),\n  View({...store.view, active: nextId})\n  ],\n  [Event.Node(parent.id), Event.View(Node(nextId))]\n))\n```\n\n### try%Anything\n\nLet's make a `try_` function for the `result` type that does a *bind* over the error case:\n```\nmodule Res = {\n  let try_ = (result, handler) =\u003e switch result {\n    | Ok(v) =\u003e Ok(v)\n    | Error(e) =\u003e handler(e)\n  }\n}\n```\nThis will come in handy for the case where we want to transform the error side of a result -- either turning it into a different error type, or turning it into a successful value. For example:\n```\nlet v = Error(\"bad\")\ntry%Res v {\n  | \"invalid username/password\" =\u003e Error(UserError)\n  | \"no user - use default\" =\u003e Ok(defaultUser)\n  | message =\u003e Error(ServerError)\n}\n```\n\n#### In the general case\n\nIf you have a data type that has a \"failure\" case (like promises, or the `result` type), the `try%Anything` syntax can be helpful.\nHere's the transform:\n\n```\ntry%Blah someExpr {\n  | Something(x) =\u003e y\n}\n```\nbecomes\n```\nBlah.try_(someExpr, result =\u003e switch result {\n  | Something(x) =\u003e y\n})\n```\n\n## Addendum\n\nAnd here are the modules used ([source](https://github.com/notablemind/renm/blob/949e1583d4df5e6d61ea066767a52828f8f8069b/src/utils/Lets.re))\n```re\nmodule Opt = {\n  let let_ = (a, b) =\u003e switch (a) {\n    | None =\u003e None\n    | Some(x) =\u003e b(x)\n  }\n};\n\nmodule Result = {\n  let let_ = (value, fn) =\u003e switch value {\n    | Ok(v) =\u003e fn(v)\n    | Error(_) =\u003e value\n  };\n  let try_ = (value, fn) =\u003e switch value {\n    | Ok(_) =\u003e value\n    | Error(err) =\u003e fn(err)\n  };\n}\n```\n\n# Usage\n\n1. Install the NPM package `let-anything` through your favorite `npm` package manager (npm itself or yarn for example)\n2. Add the following path to the `ppx-flags` defined in your `bsconfig.json` file (see bucklescript.github.io/bucklescript/docson/#build-schema.json): `let-anything/lib/bs/native/let_anything.native`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredly%2Flet-anything","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredly%2Flet-anything","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredly%2Flet-anything/lists"}