{"id":18019281,"url":"https://github.com/andytill/ohmyguard","last_synced_at":"2025-03-26T20:31:19.944Z","repository":{"id":25662069,"uuid":"29097707","full_name":"andytill/ohmyguard","owner":"andytill","description":"Binary patten matching style syntax for erlang function guards","archived":false,"fork":false,"pushed_at":"2015-02-10T23:08:33.000Z","size":212,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T10:24:59.516Z","etag":null,"topics":["parse-transform","syntax"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andytill.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":"2015-01-11T16:25:13.000Z","updated_at":"2020-12-30T18:17:19.000Z","dependencies_parsed_at":"2022-08-24T06:40:21.828Z","dependency_job_id":null,"html_url":"https://github.com/andytill/ohmyguard","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/andytill%2Fohmyguard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andytill%2Fohmyguard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andytill%2Fohmyguard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andytill%2Fohmyguard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andytill","download_url":"https://codeload.github.com/andytill/ohmyguard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245731392,"owners_count":20663169,"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":["parse-transform","syntax"],"created_at":"2024-10-30T05:09:41.705Z","updated_at":"2025-03-26T20:31:19.222Z","avatar_url":"https://github.com/andytill.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ohmyguard\n\nParse transform for converting `my_func(X) when is_binary(X) -\u003e X` to `my_func(X/binary) -\u003e X.`.\n\n## Why?\n\nErlang binary pattern matching is one of its best features and its most succinct syntax, so why not apply it to function guards as well?  Given this function:\n\n```erlang\nmy_func(Value) when is_binary(Value) -\u003e\n    Value.\n```\n\nIt can be reduced to this:\n\n```erlang\nmy_func(Value/binary) -\u003e\n    Value.\n```\n\n**ohmyguard** supports all erlang types:\n\n```erlang\nomg_atom(X/atom) -\u003e X.\nomg_binary(X/binary) -\u003e X.\nomg_bitstring(X/bitstring) -\u003e X.\nomg_float(X/float) -\u003e X.\nomg_function(X/function) -\u003e X.\nomg_integer(X/integer) -\u003e X.\nomg_list(X/list) -\u003e X.\nomg_map(X/map) -\u003e X.\nomg_number(X/number) -\u003e X.\nomg_pid(X/pid) -\u003e X.\nomg_port(X/port) -\u003e X.\nomg_reference(X/reference) -\u003e X.\nomg_ref(X/ref) -\u003e X.\nomg_tuple(X/tuple) -\u003e X.\n```\n\nThe syntax proves even more concise when a function has multiple arguments that need to be checked:\n\n```erlang\nomg_pid_atom(X/pid, Y/atom) -\u003e {X, Y}.\n```\n\nThe `andalso` and `orelse` keywords and confusing commas and semi colons are gone and the function is more readable.  All type guards must be met or a `function_clause` error is thrown.\n\nRecords are also supported, although the syntax is still being worked on:\n\n```erlang\n-record(myrec, {field = value}).\n\nomg_record(Rec/#myrec{}) -\u003e Rec.\n```\n\nIt would be better if record guards looked like `f(Rec/#myrec) -\u003e Rec.` but this throws a parse error before it can be given to the **ohmyguard** parse transform.  Suggestions welcome!\n\n**ohmyguard** will not completely replace traditional guards, it is just for type checking.\n\n## Syntax that still needs to be implemented...\n\n##### Case statements\n\n```erlang\ncase V of\n\t{ok, A/binary} -\u003e A\nend\n```\n\n##### Assignments\n\n```erlang\n{ok, V/binary} = application:get_env(my_prop)\n```\n\n##### And much more...\n\nIt would be nice if **ohmyguard** had integration with the [recless](http://code.google.com/p/recless/) parse transform, to allow syntax like:\n\n```erlang\naddress_street(Address/#address) -\u003e \n\tAddress.street.\n```\n\nAlso funs, list comprehensions, the mind boggles.\n\n## Should I use it?\n\nNo way!  It is just a proof of concept at the moment.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandytill%2Fohmyguard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandytill%2Fohmyguard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandytill%2Fohmyguard/lists"}