<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brooklin Myers</title>
    <description>The latest articles on DEV Community by Brooklin Myers (@brooklinmyers).</description>
    <link>https://dev.to/brooklinmyers</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F209303%2Fb78bd084-0ccd-426f-aa9c-545386fbb483.jpg</url>
      <title>DEV Community: Brooklin Myers</title>
      <link>https://dev.to/brooklinmyers</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brooklinmyers"/>
    <language>en</language>
    <item>
      <title>The 20% of Elixir syntax you need to read 80% of Elixir code.</title>
      <dc:creator>Brooklin Myers</dc:creator>
      <pubDate>Mon, 01 Nov 2021 04:01:48 +0000</pubDate>
      <link>https://dev.to/brooklinmyers/the-20-of-elixir-syntax-you-need-to-read-80-of-elixir-code-40p3</link>
      <guid>https://dev.to/brooklinmyers/the-20-of-elixir-syntax-you-need-to-read-80-of-elixir-code-40p3</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;A quick cheat sheet of the most common elixir syntax.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is a brief guide using the Pareto Principle (80/20 rule) to the most common Elixir syntax you’re going to encounter. If you want a crash course or a quick refresher on common Elixir concepts, then this article is for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Elixir
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Elixir is a dynamic, functional language for building scalable and maintainable applications.&lt;br&gt;
 Elixir leverages the Erlang VM, known for running low-latency, distributed, and fault-tolerant systems. Elixir is successfully used in web development, embedded software, data ingestion, and multimedia processing, across a wide range of industries.&lt;br&gt;
 &lt;a href="https://elixir-lang.org/" rel="noopener noreferrer"&gt;- https://elixir-lang.org/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Getting started with Elixir
&lt;/h2&gt;

&lt;p&gt;Skip this section and move on to data types if you already know how to run elixir code.&lt;/p&gt;

&lt;p&gt;You can choose to run elixir using a Repl (an online code editor) by executing .ex files on your computer or in the Interactive Elixir (iex) environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using a Repl
&lt;/h3&gt;

&lt;p&gt;If you’d like to get started with Elixir quickly, you can use a website to run elixir code in a web-based code editor.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open the &lt;a href="https://replit.com/languages/elixir" rel="noopener noreferrer"&gt;Elixir Repl&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure it works by typing the following in the editor and press Run.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;puts&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="no"&gt;Hello&lt;/span&gt; &lt;span class="no"&gt;World&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AsG1nT2Pr8oauym_DaexqVw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AsG1nT2Pr8oauym_DaexqVw.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Running Elixir on your computer
&lt;/h3&gt;

&lt;p&gt;You can also install Elixir onto your computer and then run elixir files (.ex) directly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://elixir-lang.org/install.html" rel="noopener noreferrer"&gt;Install Elixir&lt;/a&gt; if you don’t have it already&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make a new file called test.ex&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Write the following in the file:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;puts&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="no"&gt;Hello&lt;/span&gt; &lt;span class="no"&gt;World&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In your Terminal In the folder with your file, run&lt;/p&gt;

&lt;p&gt;elixir test.ex&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may be using a different editor, but it should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2ARCbhALGOsvR6nKDl8KnjHw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2ARCbhALGOsvR6nKDl8KnjHw.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Using the Interactive Elixir (iex) environment.
&lt;/h3&gt;

&lt;p&gt;You can open the Interactive Elixir environment to experiment with Elixir code. You must already have &lt;a href="https://elixir-lang.org/install.html" rel="noopener noreferrer"&gt;Installed Elixir&lt;/a&gt; on your machine.&lt;/p&gt;

&lt;p&gt;On Mac &amp;amp; Linux run:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# On Mac and Linux run:&lt;/span&gt;
&lt;span class="n"&gt;iex&lt;/span&gt;
&lt;span class="c1"&gt;# On Windows run:&lt;/span&gt;
&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bat&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Data Types
&lt;/h2&gt;

&lt;p&gt;In Elixir will commonly encounter the following data types:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;Variables allow you to store data to be referenced throughout your application. In Elixir, you can define a variable as such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;my_integer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="n"&gt;my_float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;4.0&lt;/span&gt;
&lt;span class="n"&gt;my_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hello"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Variables in Elixir use snake_case. A variable can store any data type; it is not restricted to the examples above.&lt;/p&gt;
&lt;h2&gt;
  
  
  Comments
&lt;/h2&gt;

&lt;p&gt;Comments in elixir use #. There is no multi-line comment for Elixir.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# comments can be on their own line&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# or after your code on the same line.&lt;/span&gt;
&lt;span class="c1"&gt;# but not before, because everything after the # is a comment 5 + 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  String
&lt;/h2&gt;

&lt;p&gt;Strings in elixir are series of Unicode Characters written between double quotes “”.&lt;/p&gt;
&lt;h3&gt;
  
  
  Writing double-quotes inside of a string
&lt;/h3&gt;

&lt;p&gt;you can put double-quotes inside of a string using backslash \&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="s2"&gt;"a string with &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;double quotes&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  String concatenation (adding strings)
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="s2"&gt;"Brooklin"&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Myers"&lt;/span&gt; &lt;span class="c1"&gt;# "Brooklin Myers"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  String interpolation
&lt;/h3&gt;

&lt;p&gt;Elixir code can execute inside of a string using #{}.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Brooklin"&lt;/span&gt;
&lt;span class="s2"&gt;"Hi &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;# Hi Brooklin&lt;/span&gt;
&lt;span class="s2"&gt;"What is 5 + 4? &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;."&lt;/span&gt; &lt;span class="c1"&gt;# What is 5 + 4? 9.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://hexdocs.pm/elixir/1.12/String.html#content" rel="noopener noreferrer"&gt;The String module&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;You can access string-related functionality with the built-in &lt;a href="https://hexdocs.pm/elixir/1.12/String.html#content" rel="noopener noreferrer"&gt;String&lt;/a&gt; module.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  Integer and Float
&lt;/h2&gt;

&lt;p&gt;Elixir provides a variety of mechanisms to operate on integers and floats.&lt;/p&gt;

&lt;h3&gt;
  
  
  Arithmetic operators
&lt;/h3&gt;

&lt;p&gt;Arithmetic operators allow you to manipulate numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# plus (+)&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# 10&lt;/span&gt;
&lt;span class="c1"&gt;# minus (-)&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# 0&lt;/span&gt;
&lt;span class="c1"&gt;# multiply (*)&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# 25&lt;/span&gt;
&lt;span class="c1"&gt;# divide (/)&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Integer Functions
&lt;/h3&gt;

&lt;p&gt;Elixir provides functions rem and div for working with integer division and remainder.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;rem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 1&lt;/span&gt;
&lt;span class="n"&gt;rem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 4&lt;/span&gt;
&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 1 (normally 1.5 with divide /)&lt;/span&gt;
&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 0 (normally 0.5 with divide /)&lt;/span&gt;
&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 2 (normally 2.6666 with divide /)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Booleans
&lt;/h2&gt;

&lt;p&gt;Booleans are true/false values.&lt;/p&gt;
&lt;h3&gt;
  
  
  and, or, not
&lt;/h3&gt;

&lt;p&gt;Used to compare booleans only:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Comparison Operators
&lt;/h2&gt;

&lt;p&gt;Comparison operators are used to compare values. They are commonly used to compare integers and floats but can also be used to compare other data types for sorting purposes.&lt;/p&gt;
&lt;h3&gt;
  
  
  exactly equals ===
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;   &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mf"&gt;5.0&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;   &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"4"&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  equals ==
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;   &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;5.0&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"4"&lt;/span&gt; &lt;span class="c1"&gt;# false, equals still checks type unlike some languages.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  not exactly equals !==
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;   &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mf"&gt;5.0&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;   &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  not equals !=
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;   &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mf"&gt;5.0&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;   &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  greater than &amp;gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  less than &amp;lt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  greater than or equal (&amp;gt;=)
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  less than or equal ≤
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Value Comparison: or (||), and (&amp;amp;&amp;amp;), not (!)
&lt;/h3&gt;

&lt;p&gt;You can use this to compare any data types. Anything other than false and nil will evaluate as true. This means even 0 will be evaluated as true. It’s important to remember the returned value is not a boolean. The returned value is the actual value evaluated.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;           &lt;span class="c1"&gt;# 1&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;       &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;       &lt;span class="c1"&gt;# 1&lt;/span&gt;
&lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;     &lt;span class="c1"&gt;# false&lt;/span&gt;
&lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;!nil&lt;/span&gt;    &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="s2"&gt;"hey"&lt;/span&gt;       &lt;span class="c1"&gt;# "hey"&lt;/span&gt;
&lt;span class="s2"&gt;"hey"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;       &lt;span class="c1"&gt;# 1&lt;/span&gt;
&lt;span class="s2"&gt;"hey"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;"hello"&lt;/span&gt; &lt;span class="c1"&gt;# "hey"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Atom
&lt;/h2&gt;

&lt;p&gt;Atoms are constants whose value is their own name. They are often used to represent distinct values important to your application. They are often used for handling the state of an operation such as :ok and :error.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;    &lt;span class="ss"&gt;:ok&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;true, false, and nil are all atoms which Elixir allows you to skip the leading colon (:).&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="ss"&gt;:true&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;   &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="ss"&gt;:false&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;span class="ss"&gt;:nil&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;     &lt;span class="c1"&gt;# true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  List
&lt;/h2&gt;

&lt;p&gt;Lists in Elixir are implemented as linked lists. Linked lists hold zero, one, or more elements in the chosen order.&lt;/p&gt;
&lt;h3&gt;
  
  
  Add and Subtract lists with ++ and --
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a href="https://hexdocs.pm/elixir/1.12/List.html#content" rel="noopener noreferrer"&gt;The List Module&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;You can access list-related functionality with the built-in &lt;a href="https://hexdocs.pm/elixir/1.12/List.html#content" rel="noopener noreferrer"&gt;List&lt;/a&gt; module.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Elixir lists are linked lists, so you can access the head (first element of the list) and the tail (the rest of the list)&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Tuple
&lt;/h2&gt;

&lt;p&gt;Use tuples when you want to store a fixed number of elements. Do not use Tuples when you want to iterate through elements as it does not support Enum operations.&lt;/p&gt;

&lt;p&gt;A common use of Tuples would be to store known values in an expected order. For example, you might have a tuple for a user with {name, age, city}&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Brooklin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Montreal"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://hexdocs.pm/elixir/1.12/Tuple.html#content" rel="noopener noreferrer"&gt;The Tuple module&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;You can access tuple-related functionality with the built-in &lt;a href="https://hexdocs.pm/elixir/1.12/Tuple.html#content" rel="noopener noreferrer"&gt;Tuple&lt;/a&gt; module.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  Map
&lt;/h2&gt;

&lt;p&gt;Maps are a key-value data structure in Elixir. The keys in a map must be unique, unlike with key-value lists.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dot notation
&lt;/h3&gt;

&lt;p&gt;You can access map values using dot notation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;my_map&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;%{&lt;/span&gt;&lt;span class="s2"&gt;"key"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;my_map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="c1"&gt;# value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Dot notation can throw non_existing_key errors&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;map.non_existing_key **** (KeyError) key :non_existing_key not found in: %{"key" =&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="k"&gt;**&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://hexdocs.pm/elixir/1.12/Map.html#content" rel="noopener noreferrer"&gt;The Map module&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;You can access map-related functionality with the built-in &lt;a href="https://hexdocs.pm/elixir/1.12/Map.html#content" rel="noopener noreferrer"&gt;Map&lt;/a&gt; module.&lt;/p&gt;

&lt;p&gt;For example, you can avoid the non_existing_key error above by using Map.get:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  Map update syntax
&lt;/h3&gt;

&lt;p&gt;You can use a special syntax to update map keys. You can only update existing keys.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  &lt;a href="https://hexdocs.pm/elixir/1.12/Enum.html#content" rel="noopener noreferrer"&gt;The Enum module&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;When iterating over data, usually a list, you can use the &lt;a href="https://hexdocs.pm/elixir/1.12/Enum.html#content" rel="noopener noreferrer"&gt;Enum module&lt;/a&gt; provided by Elixir. lists, ranges, and maps all work with the &lt;a href="https://hexdocs.pm/elixir/1.12/Enum.html#content" rel="noopener noreferrer"&gt;Enum module&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Conditional statements
&lt;/h2&gt;

&lt;p&gt;Conditional statements are used for branching logic in your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  if/else
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  unless/else
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Ternary
&lt;/h3&gt;

&lt;p&gt;Ternary is a handy shorthand for if/else statements.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  case
&lt;/h3&gt;

&lt;p&gt;case takes in a value and executes a different path in the case statement depending on the value. It may be helpful to relate case to switch-case statements found in other languages.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Variables in a case statement
&lt;/h3&gt;

&lt;p&gt;You can use variables to represent values in the case argument. See n in this example:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  cond
&lt;/h3&gt;

&lt;p&gt;cond executes the code for the first true condition. It is a lot like case, except instead of evaluating a single value and executing the path that matches the value, you can define various conditions, making this conditional statement much more versatile at the possible expense of clarity.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Modules and functions
&lt;/h2&gt;

&lt;p&gt;Modules provide a way to organize the behavior of your program. For example, you might have a Greeting module with a say_hello function to return “Hello”.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to create a module and function
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
You’ll notice that modules are CapitalCase and functions are snake_case.
&lt;h3&gt;
  
  
  Calling a function
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="no"&gt;Greeting&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# Hello&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Calling a function from inside the same module
&lt;/h3&gt;

&lt;p&gt;You do not have to reference the Module when calling a function from inside the same module. So Greeting.say_hello becomes say_hello.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Functions with different parameters
&lt;/h3&gt;

&lt;p&gt;One really cool feature of Elixir is to treat two functions with the same name but different parameters as two different functions. For example, the Greeting.say_hello function can be referred to as say_hello/0. 0 because it didn’t take any parameters.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  A function that returns a boolean should end with a question mark (?)
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Default Arguments
&lt;/h3&gt;

&lt;p&gt;Elixir supports default arguments using \&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Brackets are optional
&lt;/h3&gt;

&lt;p&gt;Use brackets when you think it adds to the clarity of the code, or don’t!&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Handling functions with context using when
&lt;/h3&gt;

&lt;p&gt;You can use when syntax to say what should happen under a specific condition.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
The order of your functions matters, as the first function to be true always runs first. Here’s an example of when used with the wrong function order.&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Reusing Modules
&lt;/h2&gt;

&lt;p&gt;Elixir provides directives for reusing modules in your project.&lt;/p&gt;

&lt;p&gt;It’s important to note that Elixir is a compiled language. It is usually compiled using a tool called &lt;a href="https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html" rel="noopener noreferrer"&gt;mix&lt;/a&gt;. So unlike a language like Javascript or Ruby, you do not import one file into another. Instead, modules are compiled together and can be accessed from any .ex files in the project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Alias
&lt;/h3&gt;

&lt;p&gt;alias allows you to import a module into another module and access it using a different name. This is commonly used to access nested modules more conveniently.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  import
&lt;/h3&gt;

&lt;p&gt;import is used to conveniently access functions from other modules.&lt;/p&gt;

&lt;p&gt;For example, here is how you would access the puts/1 function from the IO module.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  use
&lt;/h3&gt;

&lt;p&gt;use allows you to inject functionality from one module into another.&lt;/p&gt;

&lt;p&gt;Initially, you will most often use…use… 😅 with modules from third parties. For example, to write tests with the ExUnit framework, you will use the ExUnit.Case module&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
use is a reasonably complicated topic, and it’s good enough if you understand it at a surface level early on. For further reading, see an &lt;a href="https://elixirschool.com/en/lessons/basics/modules/#use" rel="noopener noreferrer"&gt;elixirschool tutorial on use&lt;/a&gt; or &lt;a href="https://elixir-lang.org/getting-started/alias-require-and-import.html#use" rel="noopener noreferrer"&gt;read the documentation&lt;/a&gt;.
&lt;h2&gt;
  
  
  Pipe
&lt;/h2&gt;

&lt;p&gt;Elixir allows you to pass the return value of a function into another using pipe syntax (|&amp;gt;)&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Pattern Matching
&lt;/h2&gt;

&lt;p&gt;In Elixir, the = symbol is called the match operator. It is useful for assigning simple values, or it can also destructure more complex data types.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Brooklin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Montreal"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;# using a tuple&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;# using a list&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;# you saw this before with lists&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  MatchError
&lt;/h3&gt;

&lt;p&gt;If your destructuring doesn’t match the right-hand side value, you will get a MatchError&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;**=**&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"world"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;******&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MatchError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt; &lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt; &lt;span class="n"&gt;hand&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="ss"&gt;value:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"world"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hopefully, this article helps you rapidly get familiar with some of the most important bits of Elixir.&lt;/p&gt;

&lt;p&gt;I left out a lot to keep the article concise. To learn more, the &lt;a href="https://elixir-lang.org/getting-started/introduction.html" rel="noopener noreferrer"&gt;Elixir Documentation&lt;/a&gt; is a great place to start.&lt;/p&gt;

&lt;p&gt;Please comment if you notice any inaccuracies or if you think there’s some other Elixir syntax I should have covered. You’ll be helping me and everyone else reading this!&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>programming</category>
    </item>
    <item>
      <title>React Native: Understanding Threads.</title>
      <dc:creator>Brooklin Myers</dc:creator>
      <pubDate>Sun, 17 Oct 2021 23:01:15 +0000</pubDate>
      <link>https://dev.to/brooklinmyers/react-native-understanding-threads-1j0m</link>
      <guid>https://dev.to/brooklinmyers/react-native-understanding-threads-1j0m</guid>
      <description>&lt;p&gt;This post is an accumulation of what I’ve learned researching threads in React Native. Hopefully, it should help you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Understand threads and processes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand the main threads and processes that React Native uses to run your program.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Debug common issues with threads that result in performance issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clarify how React Native uses the terms thread and process interchangeably&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is a thread?
&lt;/h3&gt;

&lt;p&gt;A thread is short for a thread of execution. You can think of a thread as a set of instructions to be executed by the CPU. A thread is a component of a process.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a process?
&lt;/h3&gt;

&lt;p&gt;A process is a program that is running. For example, the browser (perhaps Google Chrome, Safari, or Firefox) you are using to view this article is a process. In fact, If you want to see all of the processes that are running on your computer, you can open up the Task Manager on Windows or the Activity Monitor on mac. You should see all of the processes running on your computer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KIJECnUz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A4ZQEMZ8BvoPlKruHOC6JXw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KIJECnUz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A4ZQEMZ8BvoPlKruHOC6JXw.png" alt="" width="880" height="680"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every process has one or more threads. And a program can actually be made up of many processes. In the example above, you’ll notice that it says Google Chrome (44). This means that Google Chrome is actually running 44 different processes. Processes in a single program are referred to as &lt;strong&gt;child processes&lt;/strong&gt;. A program that uses multiple processes is referred to as &lt;strong&gt;multi-processed.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Single-threaded
&lt;/h3&gt;

&lt;p&gt;Single-threaded means that a process is designed to have only one thread of execution. This means only one set of instructions executes at once.&lt;/p&gt;

&lt;p&gt;For example, imagine you have a simple program. It’s designed to calculate the result of a series of mathematical equations. In this case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="err"&gt;–&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a single-threaded program, the program can only run one instruction at a time. A single instruction is one addition or subtraction statement. From start to finish, the evaluation of this program by the CPU would look like:&lt;/p&gt;

&lt;p&gt;step 0: (5+5)-(10–4)&lt;br&gt;
step 1: (10)-(10–4)&lt;br&gt;
step 2: 10-(6)&lt;br&gt;
step 3: 4&lt;/p&gt;

&lt;h3&gt;
  
  
  Multi-threaded
&lt;/h3&gt;

&lt;p&gt;Multi-threaded means that a process has two or more threads. So it can execute multiple instructions simultaneously.&lt;/p&gt;

&lt;p&gt;As a multi-threaded program, several instructions can run at a time. Let’s pretend this program has two threads. So, the program can run two instructions at a time. From start to finish, the evaluation of this program by the CPU would look like:&lt;/p&gt;

&lt;p&gt;step 0: (5+5)-(10–4)&lt;br&gt;
step 1: (10)-(6) // Notice that both steps 5+5 and 10–4 were accomplished during the same step.&lt;br&gt;
step 2: 4&lt;/p&gt;

&lt;h3&gt;
  
  
  React Native is single-threaded
&lt;/h3&gt;

&lt;p&gt;This means that for each process, there is only a single thread. Now in the example above, you might wonder why React Native would be single-threaded instead of multi-threaded. After all, multi-threading accomplished the calculation in fewer steps (i.e., faster), so it must be better, right? Well, not necessarily. The purpose of this article isn’t to do a deep dive on multi-threading vs. single-threading but suffice it to say that that multi-threading has some disadvantages, including &lt;a href="https://en.wikipedia.org/wiki/Thread_(computing)#Single-threaded_vs_multithreaded_programs"&gt;increased complexity, difficulty in testing, and performance costs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Because React Native is single-threaded, if you have a process that has many responsibilities, you can have performance problems. Imagine you have a process responsible for rendering a video on the screen and a live feed of comments on the video. The video rendering could block the live feed from updating correctly, or the live feed could cause stuttering in the video.&lt;/p&gt;

&lt;h3&gt;
  
  
  React Native is multi-processed.
&lt;/h3&gt;

&lt;p&gt;Instead of running multiple threads, React Native runs multiple processes. 3 main processes run in React Native and 1 process that only runs on Android L (5.0). If you want to create more processes, you can also use the library &lt;a href="https://github.com/joltup/react-native-threads"&gt;react-native-threads&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;UI Thread&lt;/strong&gt;. This process is used for handling rendering android and ios views.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JS Thread&lt;/strong&gt;. This process is used for handling all of the logic of your react native application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;React Native Modules Thread&lt;/strong&gt;. This happens when an app needs to access a platform API. For example, if you’re working with animations, you may use the native driver to handle your animations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;React Native Render Thread&lt;/strong&gt;. Android L (5.0) only uses this to draw the UI with OpenGL. Because this is only used in specific situations, I will ignore this process moving forward and only write about the main 3.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In React Native, every process has only one thread. Unfortunately, because of this, people often use the terms interchangeably. You’ll notice UI Thread, JS Thread, and React Native Modules Thread are actually all processes, and &lt;a href="https://github.com/joltup/react-native-threads"&gt;react-native-threads&lt;/a&gt; actually implements multi-processing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Debugging Processes and Threads in React Native
&lt;/h3&gt;

&lt;p&gt;By understanding these three main processes in React Native (JS Thread, UI Thread, and React Native Modules Thread), you can better understand why you experience performance issues in React Native. Common issues include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Animations blocking the JS Thread.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Slow navigation transitions during timeouts or animations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expensive computations or large data causing the slowness.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stuttering during a components mounting logic.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can solve many animation issues by using the React Native Modules Thread instead of the JS Thread. the React Native &lt;a href="https://reactnative.dev/docs/animated#using-the-native-driver"&gt;Animated&lt;/a&gt; API allows you to configure your animations with useNativeDriver: true so the animation does not block the main JS Thread.&lt;/p&gt;

&lt;p&gt;You can also use the React Native &lt;a href="https://reactnative.dev/docs/interactionmanager"&gt;Interaction Manager&lt;/a&gt; to fix competing actions (animation and navigation, for example) from causing performance issues by scheduling one action to only start after the other has finished.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;You should now better understand how React Native uses threads and processes to run your application and how to use that knowledge to fix common performance issues that can happen in React Native.&lt;/p&gt;

</description>
      <category>reactnative</category>
    </item>
  </channel>
</rss>
