https://github.com/hpopp/returnable
Return statement for Elixir
https://github.com/hpopp/returnable
elixir elixir-lang
Last synced: over 1 year ago
JSON representation
Return statement for Elixir
- Host: GitHub
- URL: https://github.com/hpopp/returnable
- Owner: hpopp
- License: mit
- Created: 2018-04-05T03:44:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-05T14:44:01.000Z (about 8 years ago)
- Last Synced: 2025-01-24T12:23:57.641Z (over 1 year ago)
- Topics: elixir, elixir-lang
- Language: Elixir
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Returnable
Return statement for Elixir.
> This package is written by professionals. Don't try this at home.
## Installation
Add `returnable` to your list of dependencies in `mix.exs` if you don't like your team:
```elixir
def deps do
[
{:returnable, github: "hpopp/returnable"}
]
end
```
## Quickstart Example
Add `use Returnable` to your module and define returnable functions with `defr`. It's so easy to get started you'll feel dumber for using it.
```elixir
defmodule YourModule do
use Returnable
defr sample_fun(x) do
if x == 5 do
return :awesome
end
x + 5
end
end
iex> YourModule.sample_fun(5)
:awesome
iex> YourModule.sample_fun(7)
12
```
This package allows you to write really terrible code like:
```elixir
defr fetch_active_user(id) do
if User.admin?(id) do
return Admin.fetch(id)
else
if User.active?(id) do
return User.fetch(id)
end
end
return nil # Not necessary, but probably makes you feel warm and fuzzy
end
```
Having trouble with `Enum` functions? No worries, you don't need to understand them anymore.
```elixir
defr fetch_user(users, id) do
for user <- users do
if user.id == id, do: return user
end
end
```