Description
Bang simply adds dynamic bang(!) functions to your existing module functions with after-callback.
Bang alternatives and similar packages
Based on the "Macros" category.
Alternatively, view Bang 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. -
shorter_maps
Elixir ~M sigil for map shorthand. `~M{id, name} ~> %{id: id, name: name}` -
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 -
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.
Learn any GitHub repo in 59 seconds
Do you think we are missing an alternative of Bang or a related project?
Popular Comparisons
README
Bang
Bang simply adds dynamic bang(!) functions to your existing module functions with after-callback.
Installation
If available in Hex, the package can be installed as:
- Add
bang
to your list of dependencies inmix.exs
:
def deps do
[{:bang, "~> 0.1.0"}]
end
- Ensure
bang
is started before your application:
def application do
[applications: [:bang]]
end
Usage
Bang uses accumulated approach by definition. So, you can define several bangs inside your module and can use different callback for each @bang function.
defmodule SampleModule do
use Bang
# @bang {[list_of_func_name_arg_count_tuples], {CallbackModule, :callback_fn}}
@bang {[welcome: 1, welcome: 2], {SampleModule, :titleize}}
def welcome(name), do: "Welcome #{name}!"
def welcome(prefix, name), do: "Welcome #{prefix}. #{name}!"
@bang {[good_bye: 1, good_bye: 2], {SampleModule, :titleize}}
def good_bye(name), do: "Good bye #{name}!"
def good_bye(prefix, name), do: "Good bye #{prefix}. #{name}!"
def titleize(str) do
str
|> String.split(" ")
|> Enum.map(fn(word) -> String.capitalize(word) end)
|> Enum.join(" ")
end
end
SampleModule.welcome("john doe") |> SampleModule.titleize == SampleModule.welcome!("john doe")
The code above will add welcome!: 1, welcome!:2, good_bye!: 1, good_bye!: 2
functions to the SampleModule
How to add bang function to existing public functions list of the module?
Open your iex console with iex -S mix
command and run for
iex> SomeModule.__info__(:functions)
# will result with list of tuples
And then add bang function as usual using the output list.
defmodule SomeModule
use Bang
...
@bang {[list_of_tuples], {SomeOtherModule, :func_name}}
...
end
Contributing
Issues, Bugs, Documentation, Enhancements
1) Fork the project
2) Make your improvements and write your tests.
3) Make a pull request.