{"id":15919921,"url":"https://github.com/jaredly/ppx_guard","last_synced_at":"2025-03-20T16:49:36.653Z","repository":{"id":66952833,"uuid":"101022223","full_name":"jaredly/ppx_guard","owner":"jaredly","description":"early returns for ocaml/reason","archived":false,"fork":false,"pushed_at":"2017-11-15T06:03:46.000Z","size":6,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-19T13:11:58.851Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-22T04:48:49.000Z","updated_at":"2018-07-03T16:31:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"4bc8db63-71fe-4019-9bf1-04172f33eff6","html_url":"https://github.com/jaredly/ppx_guard","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"1ebd0a14513a29bf805ea695a08950291a5843a9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2Fppx_guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2Fppx_guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2Fppx_guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2Fppx_guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredly","download_url":"https://codeload.github.com/jaredly/ppx_guard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244656678,"owners_count":20488638,"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-10-06T19:06:44.850Z","updated_at":"2025-03-20T16:49:36.631Z","avatar_url":"https://github.com/jaredly.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ppx_guard\n\n`guard let` for reason/ocaml!\n\n## What?\nA shortcut for early returns when you know it's going south :P\n\n```reason\nlet doit something =\u003e {\n  [%guard let Ok value = doAnAction something][@else None];\n  /* etc */\n  Some 10\n}\n/* becomes */\nlet doit something =\u003e {\n  switch (doAnAction something) {\n    | Ok value =\u003e Some 10\n    | _ =\u003e None\n  }\n}\n\n\nlet multiple x y =\u003e {\n  [%guard let Some x = x][@else None];\n  let awesome = 10;\n  [%guard let Some y = y][@else None];\n  Some (x + y)\n}\n/* becomes */\nlet multiple x y =\u003e {\n  switch x {\n    | Some x =\u003e {\n      let awesome = 10;\n      switch y {\n        | Some y =\u003e Some (x + y)\n        | _ =\u003e None\n      }\n    }\n    | _ =\u003e None\n  }\n}\n```\n\n\n## Related work / inspiration\n\nInspired by swift's [`guard let`](https://thatthinginswift.com/guard-statement-swift/), [`if let`, `if case`, `guard case`](http://alisoftware.github.io/swift/pattern-matching/2016/05/16/pattern-matching-4/), etc. It currently acts similar to swift's `guard case`.\n\nIt's also inspired by rust's [`try!` macro](https://doc.rust-lang.org/std/macro.try.html) (which is now deprecated in favor of a bit of syntax sugar, the `?` postfix operator, which does the same thing).\n\nIt might be interesting to add a `[%try` function, which would have the same\neffect as rust's try macro. If we start to use `result` a lot, it could be\nworth it.\n\n## FAQ\n\n#### Why not have it act only on `option` (as swift does with `guard let`)?\nI considered that, but I think it might\nnot be as common as in swift. An alternative would be to have a `guard_case`\nthat does what this currently does, and then `guard` would be for unwrapping\noptionals.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredly%2Fppx_guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredly%2Fppx_guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredly%2Fppx_guard/lists"}