<?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: bbronek</title>
    <description>The latest articles on DEV Community by bbronek (@bbronek).</description>
    <link>https://dev.to/bbronek</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%2F572447%2F4fe33dd2-1e54-4772-ae1c-f9c25bd22f91.jpg</url>
      <title>DEV Community: bbronek</title>
      <link>https://dev.to/bbronek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bbronek"/>
    <language>en</language>
    <item>
      <title>Beginning my journey with elixir Part III. Time, Mix Tasks, IEx, Errors, Executables.</title>
      <dc:creator>bbronek</dc:creator>
      <pubDate>Sat, 20 Feb 2021 03:42:50 +0000</pubDate>
      <link>https://dev.to/bbronek/beginning-my-journey-with-elixir-part-iii-mc1</link>
      <guid>https://dev.to/bbronek/beginning-my-journey-with-elixir-part-iii-mc1</guid>
      <description>&lt;p&gt;As I wrote in the last part, this article will be about dates and times, custom mix tasks, more about iex, error handling, and executable files. In the next part, I will focus on the practical use of basic knowledge, but for now, I encourage you to familiarize yourself with the problems contained in my presentation 😉&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SoQvPDo2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4mtxl60i8y51wlcadln4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SoQvPDo2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4mtxl60i8y51wlcadln4.jpg" alt="Alt Text" width="626" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  1.Dates and times
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;-Time&lt;/strong&gt;&lt;br&gt;
Examples of how to use the module :&lt;/p&gt;

&lt;p&gt;Get a current time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; Time.utc_now
~T[00:57:02.826573]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take a look, that ~T is a sigil which I explained in Part II.&lt;/p&gt;

&lt;p&gt;So maybe let's use our knowledge about sigils and create a Time struct.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; time = ~T[20:34:23.754335]
~T[20:34:23.754335]
iex&amp;gt; time.hour
20
iex&amp;gt; time.second
23
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;-Date&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Get actual date:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; Date.utc_today
~D[2021-02-20]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So let's create a date structure and use it in practice&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; {:ok, date} = Date.new(1023,5,24)
{:ok, ~D[1023-05-24]}
iex &amp;gt; Date.leap_year? date
false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;-NaiveDateTime&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The NaiveDateTime struct contains the fields year, month, day, hour, minute, second, microsecond and calendar. You can read more about this &lt;a href="https://hexdocs.pm/elixir/master/NaiveDateTime.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Examples :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; NaiveDateTime.utc_now
~N[2021-02-20 01:18:10.218303]
iex&amp;gt; NaiveDateTime.diff(~N[2018-04-17 14:00:00], ~N[1970-01-01 00:00:00])
1523973600 &amp;lt;- result in seconds

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;-DateTime&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The module supports date and timezones.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; DateTime.from_naive(~N[2013-04-21 11:25:02.0034], "Etc/UTC")
{:ok, ~U[2013-04-21 11:25:02.0034Z]}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More: &lt;a href="https://elixirschool.com/en/lessons/basics/date-time/#naivedatetime"&gt;link1&lt;/a&gt;, &lt;a href="https://hexdocs.pm/elixir/master/DateTime.html"&gt;link2&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2.Custom Mix Tasks
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1.Create a new app by - 'mix new app'&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2.Create a new directory newTask/lib/mix/tasks/task.ex&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;3.In task.ex create &lt;a href="https://elixirschool.com/en/lessons/basics/mix-tasks/"&gt;module&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;4.Use it by 'mix task'&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  3.IEx
&lt;/h4&gt;

&lt;p&gt;You can by h before the module gets documentation about it, by i information about data type, r - recompile a particular module, t- information about types available in a given module.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; h Enum
Provides a set of algorithms to work with enumerables.

In Elixir, an enumerable is any data type that implements the Enumerable
protocol. Lists ([1, 2, 3]), Maps (%{foo: 1, bar: 2}) and Ranges (1..3) are
common data types used as enumerables: ...
iex&amp;gt; i Map
Term
  Map
Data type
  Atom ...
iex&amp;gt; t Map
@type key() :: any()
@type value() :: any()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4.Error Handling
&lt;/h4&gt;

&lt;p&gt;When an error occurs Elixir returns the tuple {: error, reason}. The simplest way to make an error is by use raise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; raise "Error"
** (RuntimeError) Error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is set by default to raise a RuntimeError but if you want to change it you can by the simple way: &lt;code&gt;raise typeoferror, message: "lorem ipsum"&lt;/code&gt;, example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;raise ArithmeticError, message: "bad argument in arithmetic expression"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;try-rescue-after&lt;/strong&gt;&lt;br&gt;
It is simple construction to handling errors, I hope that you understand it by reading this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; try do
...&amp;gt;   raise "err"
...&amp;gt; rescue
...&amp;gt;   e in RunTimeError -&amp;gt; IO.puts("Msg:" &amp;lt;&amp;gt; e.message)
...&amp;gt; after
...&amp;gt;   IO.puts "End"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create own Error&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defmodule NewError do
  defexception message: "an error has occurred"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5.Executable Files
&lt;/h4&gt;

&lt;p&gt;You can make a file executable in Elixir by &lt;code&gt;_File.chmod(pat_file,0o755)&lt;/code&gt; (755 is a permission for a file)_.&lt;/p&gt;

&lt;p&gt;If you want to build executables projects, you can use &lt;a href="https://elixirschool.com/en/lessons/advanced/escripts/"&gt;escript&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;See you 👋&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Beginning my journey with elixir Part II. Modules, Enum, Loops, Strings, Recursion, Tests.</title>
      <dc:creator>bbronek</dc:creator>
      <pubDate>Fri, 19 Feb 2021 00:00:26 +0000</pubDate>
      <link>https://dev.to/bbronek/beginning-my-journey-with-elixir-part-ii-newly-learned-things-some-easy-programs-written-by-me-l87</link>
      <guid>https://dev.to/bbronek/beginning-my-journey-with-elixir-part-ii-newly-learned-things-some-easy-programs-written-by-me-l87</guid>
      <description>&lt;p&gt;So it's time for the second part of my journey with elixir.&lt;br&gt;
I will try to explain in a clear way things I have lastly learned and also show you how to use the newly acquired knowledge to write some simple programs.&lt;br&gt;
That being said, I encourage you to read and learn something really interesting 😃&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bIxlccdz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hj6dtix5xjv0y98996w7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bIxlccdz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hj6dtix5xjv0y98996w7.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  1.Modules
&lt;/h4&gt;

&lt;p&gt;Modules are used to organize functions in their own namespace, it is useful to allocate functions to modules in relation to their functionality.&lt;br&gt;
Example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defmodule Greetings do
 @moduledoc """
  Provides a function `greet/1` to greet a human
  """
  @doc """
  Prints a hello message

  ## Parameters

    - name: String 

  ## Examples

      iex&amp;gt; Greeter.greet("user324")
      "Good morning! user324"

      iex&amp;gt; Greeter.greet("Peter")
      "Good morning! Peter"

  """
  @greeting "Good morning!"

  def greet(name) do
    ~s(#{@greeting} #{name}.)
  end
end

defmodule Greetings2 do
  alias Greetings, as: Hi

  def main do
    Hi.greet("John")
  end
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see I used the @greeting attribute to use it as a greeting in the greet function. The ~s is a sigil. What is it? Here is an answer: Sigils are special syntax to working with literals, you can read more about this &lt;a href="https://elixirschool.com/en/lessons/basics/sigils/"&gt;here&lt;/a&gt;. I also used the alias to use functions from another module in a different one.&lt;/p&gt;

&lt;h4&gt;
  
  
  2.Enum
&lt;/h4&gt;

&lt;p&gt;The Enum is a module to work with enumerables. &lt;br&gt;
I will only show a few functions from this module because it contains over 70 functions. It will be &lt;strong&gt;all?, any?, chunk_every, chunk_by, each, map, min, filter, reduce, sort and uniq&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;-all?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt;Enum.all?(["one","two","three"], fn(x) -&amp;gt; String.length(x) == 4 end)
false
Enum.all?(["one","two","thre"], fn(x) -&amp;gt; String.length(x) == 3 end)
true

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-any?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt;Enum.any?(["one","two","three"], fn(x) -&amp;gt; String.length(x) == 4 end)
true
Enum.any?(["one","two","thre"], fn(x) -&amp;gt; String.length(x) == 5 end)
false

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-chunk_every&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt;Enum.chunk_every(["one","two","three"], 2) 
[["one", "two"], ["three"]]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-chunk_by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt;Enum.chunk_by(["world","universe","hi"], fn(x) -&amp;gt; String.length(x) end) 
[["world"], ["universe"], ["hi"]]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-each&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt;Enum.each(["How","are","you","?"], fn(x) -&amp;gt; IO.puts(x) end) 
How
are
you
?
:ok


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-map&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; Enum.map([0, 1, 2, 3], fn(x) -&amp;gt; x * x end)
[0, 1, 4, 9]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-min&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; Enum.min([1, 32, 42, -10])
-10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-filter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; Enum.filter([1, 2, 3, 4], fn(x) -&amp;gt; rem(x, 2) == 0 end)
[2, 4]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-reduce&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; Enum.reduce(["a","b","c"], fn(x,acc)-&amp;gt; x &amp;lt;&amp;gt; acc end)
"cba"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation: acc is the first element of the list.&lt;br&gt;
This how it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. x = 'b' acc = 'a' -&amp;gt; out: "ba"
2. x = 'c' acc = "ba" -&amp;gt; out: "cba"
"cba"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-sort&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; Enum.sort([%{:val =&amp;gt; 4}, %{:val =&amp;gt; 1}], fn(x, y) -&amp;gt; x[:val] &amp;gt; y[:val] end)
[%{val: 4}, %{val: 1}]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-uniq&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt;  Enum.uniq([1, 2, 3, 2, 1, 1, 1, 1, 1])
[1, 2, 3]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3.Loops
&lt;/h4&gt;

&lt;p&gt;-for loop&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
iex&amp;gt;for {_key, val} &amp;lt;- [one: 1, two: 2, three: 3], do: IO.puts _key

one
two
three

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; import Integer
Integer
iex&amp;gt; for x &amp;lt;- 1..20, is_even(x), do: IO.puts x
2
4
6
8
10
12
14
16
18
20

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-functional approach &lt;a href="https://www.tutorialspoint.com/elixir/elixir_loops.htm"&gt;source&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
defmodule Loop do
   def print_multiple_times(msg, n) when n &amp;lt;= 1 do
      IO.puts msg
   end

   def print_multiple_times(msg, n) do
      IO.puts msg
      print_multiple_times(msg, n - 1)
   end
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Results :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; c("file.ex")
[Loop]
iex&amp;gt; Loop.print_multiple_times("HI",3)
HI
HI
HI
:ok
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4.Strings
&lt;/h4&gt;

&lt;p&gt;-You can use ASCII to assign a string value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; string = &amp;lt;&amp;lt;104,101,108,108,111&amp;gt;&amp;gt;
"Hello"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-Easy for returning an ASCII value of a char :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt;?a
97

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Anagram"&gt;Anagram&lt;/a&gt; program :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defmodule Anagram do
  def anagrams?(a, b) when is_binary(a) and is_binary(b) do
    sort_string(a) == sort_string(b)
  end

  def sort_string(string) do
    string
    |&amp;gt; String.downcase()
    |&amp;gt; String.graphemes()
    |&amp;gt; Enum.sort()
  end
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Useful link  &lt;a href="https://en.wikipedia.org/wiki/Grapheme"&gt;grapheme&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  5.Short view of recursion.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defmodule Rec do
  def rec(a,b) do
    if a&amp;lt;=b do
      IO.puts "Hi #{a}"
      a = a + 1
      rec(a,b)
    end
  end
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Rec]
iex&amp;gt; Rec.rec(2,7)
Hi 2
Hi 3
Hi 4
Hi 5
Hi 6
Hi 7
nil

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Tests
&lt;/h4&gt;

&lt;p&gt;I wrote a simple program and I hope that  it will be useful in understanding the methods of testing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defmodule App do

    def get_name do
      IO.gets("What is yout name? ")
      |&amp;gt;String.trim
    end

    def get_number do
      IO.getn("Give a number: [0-9] ",1)
    end

    def main() do
      name = get_name()
      IO.puts("Hello #{name}")
      number = get_number()
      name
    end

end

ExUnit.start

defmodule Tests do
  alias App
  use ExUnit.Case

  test "check if name is valid" do
    refute String.match?(App.main,~r/[0-9]/)
  end
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation: IO.getn(string,size) , ~r/[0-9]/ (regex);&lt;/p&gt;

&lt;p&gt;Before testing, you have to launch it by ExUnit.start, &lt;br&gt;
to use the test condition I had to write before it &lt;em&gt;use ExUnit.Case&lt;/em&gt;. ' &lt;em&gt;refute String.match?(App.main,~r/[0-9]/)&lt;/em&gt; '&lt;br&gt;
refute it is the same as unless, you can also use assert in testing which means 'should' or 'expect to be' .&lt;/p&gt;

&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What is your name? qwer45
Hello qwer45
Give a number: [0-9] 5

1) test check if name is valid (Tests)
     tests.exs:27
     Expected false or nil, got true
     code: refute String.match?(App.main, ~r"[0-9]")
     arguments:

         # 1
         "qwer45"

         # 2
         ~r/[0-9]/

     stacktrace:
       tests.exs:28: (test)



Finished in 4.8 seconds (0.07s on load, 4.7s on tests)
1 test, 1 failure


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This all for part II in the next part I plan to write about using dates and times, custom mix tasks, more about iex, error handling, and executable files. Have a nice day ✋&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Beginning my journey with elixir Part I - problem with mix and 5 most interesting things I learned so far.</title>
      <dc:creator>bbronek</dc:creator>
      <pubDate>Wed, 03 Feb 2021 01:33:01 +0000</pubDate>
      <link>https://dev.to/bbronek/beginning-my-journey-with-elixir-part-i-problem-with-mix-and-5-most-interesting-things-i-learned-so-far-3223</link>
      <guid>https://dev.to/bbronek/beginning-my-journey-with-elixir-part-i-problem-with-mix-and-5-most-interesting-things-i-learned-so-far-3223</guid>
      <description>&lt;p&gt;Currently, I am a student of computer science and I am dedicated to programming, I tried different technologies such as node, python but elixir excites me the most and with this technology I bind my professional future. In this series, I would like to share my adventure, successes, and problems I encountered. Hope you will enjoy this series 😀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uuNaiEug--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x2jl8l1uu6psczgvynu6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uuNaiEug--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x2jl8l1uu6psczgvynu6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I started from learning basics from &lt;a href="https://elixirschool.com"&gt;Elixir school&lt;/a&gt; and &lt;a href="https://elixir-lang.org"&gt;Elixir webpage&lt;/a&gt;. Everything was going well with learning until I got an error when I had to use &lt;a href="https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html"&gt;mix&lt;/a&gt;. I installed elixir with &lt;a href="https://elixir-lang.org/install.html"&gt;instructions&lt;/a&gt;. I am using Linux Mint and the error I got when trying to create a new app was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╰─❯ mix new app
** (Mix) Application name must start with a letter and have only lowercase letters, numbers, and underscore, got: "app". The application name is inferred from the path, if you'd like to explicitly name the application then use the "--app APP" option.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I couldn't find an answer on StackOverflow so I decided to ask on the &lt;code&gt;elixir&lt;/code&gt; channel on discord and good people advised me to install elixir via &lt;code&gt;asdf&lt;/code&gt;. It is an extendable version manager that can be used to install elixir properly &lt;a href="https://asdf-vm.com/#/core-manage-asdf"&gt;link&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I removed elixir and erlang then installed the latest versions of them  using &lt;code&gt;asdf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) asdf plugin add erlang &amp;amp;&amp;amp; asdf plugin add the elixir
2) asdf install erlang latest
3) asdf global erlang &amp;lt;version&amp;gt;
4) asdf install elixir latest
5) asdf global elixir &amp;lt;version&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thankfully, I can now enjoy the functionality of the &lt;code&gt;mix&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I will now move on to the most interesting things I learned.&lt;/p&gt;

&lt;p&gt;1.&lt;code&gt;Pin operator&lt;/code&gt; it makes assignment when the left side if the match includes variables. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; x = 42
42
iex&amp;gt; ^x = 44
** (MatchError) no match of right-hand side value: 44
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see when I tried to match &lt;code&gt;x&lt;/code&gt; with &lt;code&gt;44&lt;/code&gt; I got an error above.&lt;/p&gt;

&lt;p&gt;2.&lt;code&gt;Cond&lt;/code&gt; is used to match conditions similar to &lt;code&gt;if-else&lt;/code&gt; or &lt;code&gt;else&lt;/code&gt; in other languages. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; cond do
...&amp;gt;   "apple" == "banana" -&amp;gt; "Incorrect"
...&amp;gt;   true -&amp;gt; "Catched all"
...&amp;gt; end
"Catched all"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.&lt;code&gt;Pipe operator&lt;/code&gt; it takes the result of one function and passes it on as the first parameter of another expressions. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt; "HEllo WoRld" |&amp;gt; String.downcase() |&amp;gt; String.split()
["hello", "world"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.&lt;code&gt;Documentation of Modules and functions&lt;/code&gt; Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defmodule Calculator do
  @moduledoc """
Provides a function `add/2` to add two numbers and print them out
  """

  def add(x,y) do
   IO.puts x+y
  end
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can access Calculator documentation by using the &lt;code&gt;h&lt;/code&gt; helper function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iex&amp;gt;c("file.ex") 
[Module]
...&amp;gt; Calculator.function(5,4)
9
:ok

iex&amp;gt; h Calculator

                Calculator

Provides a function add/2 to add two numbers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5.&lt;code&gt;Start new project using mix&lt;/code&gt; Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mix new app

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/app.ex
* creating test
* creating test/test_helper.exselse
* creating test/app_test.exs

Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:

    cd app
    mix test

Run "mix help" for more commands.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  This is all that I wanted you to present in Part I. Have a nice day and stay tuned for the next update. Bye 👋.
&lt;/h4&gt;

</description>
      <category>beginners</category>
      <category>elixir</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
