A list of self experienced

10 Killer Elixir Tips #1

Code forward & Be forward thinking

Blackode
Blackode
Feb 17, 2017 · 2 min read
Image for post
Photo by Form on Unsplash

No interest in reading, go for watching…

YouTube Video on this Article.

1. Multiple [ OR ]

This is just the other way of writing Multiple OR conditions. This is not the recommended approach because in regular approach when the condition evaluates to true , it stops executing the remaining conditions which saves time of evaluation unlike this approach which evaluates all conditions first in a list. This is just good for discoveries.

2. i( term)

It prints the information about a data type of given term. Try that in iex and see the magic.

iex> i(1..5)

3. iex Custom Configuration

Save the following file as .iex.exs in your ~ home directory and see the magic.

iex configuration file
Image for post
iex custom configuration

4. Custom Sigils

Each x sigil calls its respective sigil_x definition

Defining your own sigils

5. Custom Error Definitions

Defining Custom Error

Usage

$ iex bug_error.ex
iex> raise BugError
** (BugError) BUG BUG ..
iex> raise BugError, message: "I am Bug.."
** (BugError) I am Bug..

6. Get a Value from Nested Maps

Getting a Value from Nested Maps

7. with statement

The special form with is used to chain a sequence of matches in order and finally return the result of do: if all the clauses match. However, if one of the clauses does not match, its result of the miss matched expression is immediately returned.

iex> with 1 <- 1+0,
2 <- 1+1,
do: IO.puts "all matched"
"all matched"
iex> with 1 <- 1+0,
2 <- 3+1,
do: IO.puts "all matched"
4
## since 2 <- 3+1 is not matched so the result of 3+1 is returned.

8. Writing Protocols

Defining protocols

9. Ternary Operator

There is no ternary operator like true ? "yes" : "no" . So, the following is suggested.

"no" = if 1 == 0, do: "yes", else: "no"

10.????

Purposely I did not write the 10 tip. If you have one, share in the comment section below..
to be continued … in 10 Killer Elixir Tips #2

Thanks 4 UR Tm.. Read all parts of Killer Elixir Tips and download README.MD file at GitHub .
Click on link All Killer Elixir Parts. Contribute with a ★

Join Our Telegram Channel

Image for post
https://t.me/blackoders

blackode

Coding, thoughts, and ideas.

Blackode

Written by

Blackode

Wrong CODE takes U to the right BUG 🐞 coding, thoughts & ideas

blackode

blackode

Coding, thoughts, and ideas.

Blackode

Written by

Blackode

Wrong CODE takes U to the right BUG 🐞 coding, thoughts & ideas

blackode

blackode

Coding, thoughts, and ideas.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store