named_args alternatives and similar packages
Based on the "Macros" category.
Alternatively, view named_args alternatives based on common mentions on social networks and blogs.
-
typed_struct
An Elixir library for defining structs with a type without writing boilerplate code. -
pipes
Macros for more flexible composition with the Elixir Pipe operator -
shorter_maps
Elixir ~M sigil for map shorthand. `~M{id, name} ~> %{id: id, name: name}` -
eventsourced
Functional domain models with event sourcing in Elixir -
ok_jose
Pipe elixir functions that match ok/error tuples or custom patterns. -
crudry
Elixir library for DRYing CRUD in Phoenix Contexts and Absinthe Resolvers. -
pipe_to
The enhanced elixir pipe operator which can specify the target position -
pattern_tap
Macro for tapping into a pattern match while using the pipe operator -
pipe_here
An Elixir macro for easily piping arguments at any position. -
pit
Elixir macro for extracting or transforming values inside a pipe flow. -
rulex
This tiny library (2 macros only) allows you to define very simple rule handler using Elixir pattern matching. -
guardsafe
Macros expanding into code that can be safely used in guard clauses. -
apix
Simple convention and DSL for transformation of elixir functions to an API for later documentation and or validation. -
Bang
Bang simply adds dynamic bang! functions to your existing module functions with after-callback. -
backports
Ensure backwards compatibility even if newer functions are used
Clean code begins in your IDE with SonarLint
Do you think we are missing an alternative of named_args or a related project?
Popular Comparisons
README
NamedArgs
Inspired by Named Arguments with Elixir
Allows you to use named arguments similar to Ruby's named arguments. For example, in Ruby
def introduction(name: 'Sarah', birthday: "1985-12-30")
puts "Hi my name is #{name} and I was born on #{birthday}"
end
However in Elixir, using a default argument ends up dropping the other values.
defmodule Talk do
def introduction(opts \\ [name: "Sarah", birthday: "1985-12-30"]) do
IO.puts "Hi my name is #{opts[:name]} and I was born on #{opts[:birthday]}"
end
end
# Drops the birthday
Talk.introduction(name: "Joe") # => Hi my name is Joe and I was born on
# Drops the name
Talk.introduction(birthday: "1985-12-30") # => Hi my name is and I was born on 1985-12-30
With NamedArgs
you can instead do the following:
defmodule Talk do
use NamedArgs
def introduction(opts \\ [name: "Sarah", birthday: "1985-12-30"]) do
IO.puts "Hi my name is #{opts[:name]} and I was born on #{opts[:birthday]}"
end
end
# No params!
Talk.introduction # => Hi my name is Sarah and my birthday is 1985-12-30
# Keeps the birthday
Talk.introduction(name: "Joe") # => Hi my name is Joe and I was born on 1985-12-30
# Keeps the name
Talk.introduction(birthday: "1986-01-01") # => Hi my name is Sarah and I was born on 1986-01-01
# Order does not matter!
Talk.introduction(birthday: "1986-01-01", name: "Joe") # => Hi my name is Joe and I was born on 1986-01-01
Installation
This package is available in Hex, to install:
- Add named_args to your list of dependencies in
mix.exs
:
def deps do
[
{:named_args, "~> 0.1.0"}
]
end
But it doesn't create a variable with the same name?
Yup, 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).
If possible to remove the compiler warning this feature may become more attractive. Please let me know if you have ideas about this!