{"id":16318528,"url":"https://github.com/vic/happy_with","last_synced_at":"2025-03-16T14:30:56.345Z","repository":{"id":57504362,"uuid":"69149987","full_name":"vic/happy_with","owner":"vic","description":"Avoid commas on Elixir's with special form.","archived":false,"fork":false,"pushed_at":"2024-01-05T13:30:29.000Z","size":16,"stargazers_count":29,"open_issues_count":1,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T20:54:56.620Z","etag":null,"topics":["elixir","error-handling","macros","monad","with"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vic.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":"2016-09-25T07:30:35.000Z","updated_at":"2024-03-02T15:26:53.000Z","dependencies_parsed_at":"2024-10-27T10:54:28.240Z","dependency_job_id":"daba19ee-c5c2-4e49-aa74-75484fe8a088","html_url":"https://github.com/vic/happy_with","commit_stats":{"total_commits":15,"total_committers":4,"mean_commits":3.75,"dds":0.4666666666666667,"last_synced_commit":"6578030d3e164820e7c3ed0822a79b933683ac08"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vic%2Fhappy_with","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vic%2Fhappy_with/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vic%2Fhappy_with/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vic%2Fhappy_with/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vic","download_url":"https://codeload.github.com/vic/happy_with/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243882305,"owners_count":20363114,"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":["elixir","error-handling","macros","monad","with"],"created_at":"2024-10-10T22:23:48.634Z","updated_at":"2025-03-16T14:30:55.946Z","avatar_url":"https://github.com/vic.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HappyWith\n\n[![Travis](https://img.shields.io/travis/vic/happy_with.svg)](https://travis-ci.org/vic/happy_with)\n[![Hex.pm](https://img.shields.io/hexpm/v/happy_with.svg?style=flat-square)](https://hexdocs.pm/happy_with)\n\nTiny syntax sugar around Elixir's `with` special form.\n\n#### Why ?\n\nBecause I'm happy on how Elixir's `with` special form works, \nand can get used to the `\u003c-` arrow but I still dont like to\nplace commas between all the with expressions. \n\nBack then before elixir 1.2 release, I implemented [happy](http://github.com/vic/happy) using case\nexpressions, it leaked variables as normal case expressions would do, and _overriding_ the standard\n`=` operator turned out to have some [unexpected](https://github.com/vic/happy/issues/7) [issues](https://github.com/vic/happy/issues/8). Also, after using standard `with` a bit, I\nreally got to like it, except for the fact of having to place commas after expressions, so I wrote\n`happy_with` which is a [*very* tiny macro](https://github.com/vic/happy_with/blob/master/lib/happy_with.ex#L42) that just rewrites to Elixir's standard `with` special form.\n\nThis package implements the *tags* feature originally found in `happy_path`.\n\nFor more examples see [docs](https://hexdocs.pm/happy_with/HappyWith.html#happy_with/1)\n\n## Installation\n\n[Available in Hex](https://hex.pm/packages/happy_with), the package can be installed as:\n\n  1. Add happy_with to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:happy_with, \"~\u003e 1.0\"}]\nend\n```\n        \n## Usage\n\n```elixir\nimport HappyWith\n```\n\n#### `happy_with` macro\n\n```elixir\nhappy_with do\n  {:ok, friend} \u003c- retrieve_friend\n  String.downcase(friend)\nelse\n  _ -\u003e \"nobody\"\nend\n```\n\nrewrites into standard `with` form.\nOnly the last expression in the happy_with block is given to with's do.\n\n```elixir\nwith({:ok, friend} \u003c- retrieve_friend)\ndo\n  name = String.downcase(friend)\nelse\n  _ -\u003e \"nobody\"\nend\n```\n\nIMHO the first one reads better.\n\n\n## Examples\n\nRewrites the given block and else clauses into Elixir's standard `with` form.\n\n```elixir\niex\u003e import HappyWith\niex\u003e happy_with do\n...\u003e   {:ok, name} \u003c- {:ok, \"joSE\"}\n...\u003e   lower = String.downcase(name)\n...\u003e   lower\n...\u003e end\n\"jose\"\n```\n\nYou can also provide else clauses to the `with` form.\n\n```elixir\niex\u003e import HappyWith\niex\u003e happy_with do\n...\u003e   {:ok, name} \u003c- {:error, :nobody}\n...\u003e   _never_reached = String.downcase(name)\n...\u003e else\n...\u003e   {:error, _} -\u003e \"luis\"\n...\u003e end\n\"luis\"\n```\n\nYou can also use tags a feature from the [happy](http://github.com/vic/happy) project.\n\n```elixir\niex\u003e import HappyWith\niex\u003e happy_with do\n...\u003e   @something {:ok, name} when is_binary(name) and length(name) \u003e 3 \u003c- {:error, :nobody}\n...\u003e   _never_reached = String.downcase(name)\n...\u003e else\n...\u003e   {:something, {:error, _}} -\u003e \"could not fetch name\"\n...\u003e end\n\"could not fetch name\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvic%2Fhappy_with","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvic%2Fhappy_with","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvic%2Fhappy_with/lists"}