{"id":13508538,"url":"https://github.com/mgwidmann/named_args","last_synced_at":"2025-07-03T22:05:24.871Z","repository":{"id":62429976,"uuid":"59262104","full_name":"mgwidmann/named_args","owner":"mgwidmann","description":"Allows named arg style arguments in Elixir","archived":false,"fork":false,"pushed_at":"2018-01-31T02:17:33.000Z","size":11,"stargazers_count":28,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-03T22:04:38.685Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/mgwidmann.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":"2016-05-20T03:29:45.000Z","updated_at":"2023-10-18T20:38:20.000Z","dependencies_parsed_at":"2022-11-01T20:07:36.087Z","dependency_job_id":null,"html_url":"https://github.com/mgwidmann/named_args","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mgwidmann/named_args","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fnamed_args","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fnamed_args/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fnamed_args/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fnamed_args/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgwidmann","download_url":"https://codeload.github.com/mgwidmann/named_args/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fnamed_args/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263410762,"owners_count":23462297,"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-01T02:00:54.521Z","updated_at":"2025-07-03T22:05:24.772Z","avatar_url":"https://github.com/mgwidmann.png","language":"Elixir","funding_links":[],"categories":["Macros"],"sub_categories":[],"readme":"# NamedArgs\n\nInspired by [Named Arguments with Elixir](https://blog.praveenperera.com/named-arugments-with-default-values-in-elixir/)\n\nAllows you to use named arguments similar to Ruby's named arguments. For example, in Ruby\n\n```ruby\ndef introduction(name: 'Sarah', birthday: \"1985-12-30\")  \n  puts \"Hi my name is #{name} and I was born on #{birthday}\"\nend\n```\n\nHowever in Elixir, using a default argument ends up dropping the other values.\n\n```elixir\ndefmodule Talk do  \n  def introduction(opts \\\\ [name: \"Sarah\", birthday: \"1985-12-30\"]) do\n    IO.puts \"Hi my name is #{opts[:name]} and I was born on #{opts[:birthday]}\"\n  end\nend\n# Drops the birthday\nTalk.introduction(name: \"Joe\") # =\u003e Hi my name is Joe and I was born on\n# Drops the name\nTalk.introduction(birthday: \"1985-12-30\") # =\u003e Hi my name is  and I was born on 1985-12-30\n```\n\nWith `NamedArgs` you can instead do the following:\n\n```elixir\ndefmodule Talk do\n  use NamedArgs\n  def introduction(opts \\\\ [name: \"Sarah\", birthday: \"1985-12-30\"]) do\n    IO.puts \"Hi my name is #{opts[:name]} and I was born on #{opts[:birthday]}\"\n  end\nend\n# No params!\nTalk.introduction # =\u003e Hi my name is Sarah and my birthday is 1985-12-30\n# Keeps the birthday\nTalk.introduction(name: \"Joe\") # =\u003e Hi my name is Joe and I was born on 1985-12-30\n# Keeps the name\nTalk.introduction(birthday: \"1986-01-01\") # =\u003e Hi my name is Sarah and I was born on 1986-01-01\n# Order does not matter!\nTalk.introduction(birthday: \"1986-01-01\", name: \"Joe\") # =\u003e Hi my name is Joe and I was born on 1986-01-01\n```\n\n## Installation\n\nThis package is [available in Hex](https://hex.pm/packages/named_args), to install:\n\n  1. Add named_args to your list of dependencies in `mix.exs`:\n\n  ```elixir\n    def deps do\n      [\n        {:named_args, \"~\u003e 0.1.0\"}\n      ]\n    end\n  ```\n\n## But it doesn't create a variable with the same name?\n\nYup, I'm still not sure if thats a desired feature or not. Because it would implicitly create a variable that you may or may not decide to use, it goes against a lot of the philosophies that Elixir follows in regard to explicit coding. And the compiler would warn you about it (and it couldn't be fixed either).\n\nIf possible to remove the compiler warning this feature may become more attractive. Please let me know if you have ideas about this!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgwidmann%2Fnamed_args","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgwidmann%2Fnamed_args","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgwidmann%2Fnamed_args/lists"}