ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - DevL/guardsafe: Macros expanding into code that can be safely used in guard clauses.
Macros expanding into code that can be safely used in guard clauses. - DevL/guardsafe
Visit Site

GitHub - DevL/guardsafe: Macros expanding into code that can be safely used in guard clauses.

GitHub - DevL/guardsafe: Macros expanding into code that can be safely used in guard clauses.

Guardsafe

Build Status Inline docs Hex.pm Documentation

Macros expanding into code that can be safely used in guard clauses.

Usage

Update your mix.exs file and run mix deps.get.

defp deps do
  [{:guardsafe, "~> 0.5.0"}]
end

Import all the macros...

defmodule MyModule do
  import Guardsafe

...or just the ones you need.

defmodule MyOtherModule do
  import Guardsafe, only: [divisible_by?: 2, integer?: 1]

Now go forth and make your guard clauses more readable!

def leap_year?(year) when not integer?(year), do: raise "That's not a proper year!"
def leap_year?(year) when divisible_by?(year, 400), do: true
def leap_year?(year) when divisible_by?(year, 100), do: false
def leap_year?(year), do: divisible_by?(year, 4)

Documentation for each macro is of course available in iex.

iex(1)> h Guardsafe.divisible_by?

                    defmacro divisible_by?(number, divisor)

Expands divisible_by?(number, divisor) into rem(number, divisor) == 0

Available macros

NB: If a macro is translated into a function residing in another module than Kernel you need to require it before use, e.g. require Integer.

Macros for checking types

  • atom?/1 - translates into Kernel.is_atom/1
  • binary?/1 - translates into Kernel.is_binary/1
  • bitstring?/1 - translates into Kernel.is_bitstring/1
  • boolean?/1 - translates into Kernel.is_boolean/1
  • float?/1 - translates into Kernel.is_float/1
  • function?/1 - translates into Kernel.is_function/1
  • function?/2 - translates into Kernel.is_function/2
  • integer?/1 - translates into Kernel.is_integer/1
  • list?/1 - translates into Kernel.is_list/1
  • map?/1 - translates into Kernel.is_map/1
  • nil?/1 - translates into Kernel.is_nil/1
  • number?/1 - translates into Kernel.is_number/1
  • pid?/1 - translates into Kernel.is_pid/1
  • port?/1 - translates into Kernel.is_port/1
  • reference?/1 - translates into Kernel.is_reference/1
  • tuple?/1 - translates into Kernel.is_tuple/1

Macros for checking values

  • divisible_by?/2 - checks whether two integers are evenly divisible.
  • even?/1 - returns true for even integers.
  • odd?/1 - returns true for odd integers.
  • within?/3 - checks whether a value is in the range of the last two arguments.

Macros for dates and times

  • date?/1 - checks if the term is an Erlang-style date tuple.
  • datetime?/1 - checks if the term is an Erlang-style datetime tuple.
  • time?/1 - checks if the term is an Erlang-style time tuple.

These can come in handy when working with a library such as GoodTimes.

Why nil? and float? instead of is_nil and is_float

While the Elixir core team thinks that nil? compared to is_nil is an inconcistency, others, especially Rubyists, might be more comfortable with the nil? notation. Honestly though, this is mostly intended as a display of how Elixir's metaprogramming capabilities can be used to shape the look and feel of the language itself.

Online documentation

For more information, see the full documentation.

Contributing

  1. Fork this repository
  2. Create your feature branch (git checkout -b quis-custodiet-ipsos-custodes)
  3. Commit your changes (git commit -am 'Guards! Guards!')
  4. Push to the branch (git push origin quis-custodiet-ipsos-custodes)
  5. Create a new Pull Request

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory