<?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>Forem: franzejr</title>
    <description>The latest articles on Forem by franzejr (@franzejr).</description>
    <link>https://forem.com/franzejr</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%2F1489%2FbNkn4LqL.jpg</url>
      <title>Forem: franzejr</title>
      <link>https://forem.com/franzejr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/franzejr"/>
    <language>en</language>
    <item>
      <title>The Power of Elm in JavaScript</title>
      <dc:creator>franzejr</dc:creator>
      <pubDate>Sun, 29 Dec 2019 11:45:30 +0000</pubDate>
      <link>https://forem.com/franzejr/the-power-of-elm-in-javascript-3ge5</link>
      <guid>https://forem.com/franzejr/the-power-of-elm-in-javascript-3ge5</guid>
      <description>&lt;p&gt;Since first learning of Elm, I’ve only heard good things. I’m convinced Elm could become the future of front-end development in the coming years. Here are some blog posts in the Elm community that have particularly stuck out to me:&lt;/p&gt;


&lt;center&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ST1nvBcL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/800/1%2ANJWmSiT1OdEyS1yKKH-rPA.gif" alt=""&gt;&lt;/center&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hackernoon.com/why-elm-is-going-to-change-the-world-f5a6c693b2ca"&gt;Why Elm is Going to Change the World&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@rgoomar/why-i-think-elm-is-the-future-of-front-end-development-21e9b091fa05"&gt;Why I think Elm is the Future of Front End Development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/elmlightments/why-elm-is-a-future-of-frontend-interview-with-preethi-kasireddy-92d6bc6a5018"&gt;Why Elm is a future of Frontend? Interview with Preethi Kasireddy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/martincerny/what-elm-and-rust-teach-us-about-the-future"&gt;What Elm and Rust Teach us About the Future&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the moment, I'm not involved in any Elm project. However, I’ve been messing around with Elm a bit. I want to work with Elm more, and I know Elm can bring some incredible things to front-end development. &lt;/p&gt;

&lt;p&gt;How can I bring these things to JavaScript, since I am just working with JavaScript presently?&lt;/p&gt;

&lt;p&gt;Let's see first what Elm can do for us, as developers.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Should I care about Elm ?
&lt;/h2&gt;

&lt;p&gt;This is a common question people ask themselves, and there is a book called &lt;a href="http://www.oreilly.com/web-platform/free/files/why-elm.pdf"&gt;Why Elm&lt;/a&gt; from O’Reilly.&lt;/p&gt;

&lt;p&gt;In this book, they say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Many of the common issues that front-end developers have to deal with just&lt;br&gt;
don't exist in Elm.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;YES! You read it well. They simply &lt;strong&gt;don't exist&lt;/strong&gt;. Imagine yourself not dealing&lt;br&gt;
with &lt;code&gt;undefined is not a function&lt;/code&gt; or odd things like: &lt;code&gt;NaN === NaN&lt;/code&gt;. Some of these weird things have an explanation, but they are still weird. &lt;/p&gt;
&lt;h3&gt;
  
  
  Elm compiler
&lt;/h3&gt;

&lt;p&gt;Elm has an awesome compiler. Imagine you have a &lt;a href="http://elm-lang.org/blog/compilers-as-assistants"&gt;compiler as an assistant&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Elm ensures that errors will happen at compile time, in front of a developer,&lt;br&gt;
instead of runtime, in front of a user. " - Why Elm&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The Elm compiler is awesome Let’s look at one example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KjnKOwDN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/45po3pnnv4phxq7hmb6s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KjnKOwDN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/45po3pnnv4phxq7hmb6s.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, we were trying to return a String and a number in our if/else. The compiler makes your life easier, explaining to you exactly what the error was and what you can do.&lt;/p&gt;

&lt;p&gt;Now, imagine you made a typo. Rather than typing &lt;code&gt;map&lt;/code&gt; you typed &lt;code&gt;nap&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---HS-p8DA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/32iwliv72qt4u06slt36.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---HS-p8DA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/32iwliv72qt4u06slt36.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The compiler explains to you what you did and gives you a few options.&lt;/p&gt;
&lt;h3&gt;
  
  
  Total immutability
&lt;/h3&gt;

&lt;p&gt;Imagine you don't need to worry about mutable state in your application. Everything is immutable.&lt;/p&gt;
&lt;h3&gt;
  
  
  Purely Functional
&lt;/h3&gt;

&lt;p&gt;Elm is a purely functional language. This means you can use all the power of Functional Programming in your code.&lt;/p&gt;

&lt;p&gt;Here are some &lt;a href="https://www.johndcook.com/blog/2011/07/19/you-wanted-banana/"&gt;good articles talking about&lt;br&gt;
FP&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Reactive Programming
&lt;/h3&gt;

&lt;p&gt;In imperative programming languages, we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If we change the value of &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt; will not be updated.  Elm helps us to have that by computing values from the state. &lt;/p&gt;

&lt;h3&gt;
  
  
  Strong Static Types
&lt;/h3&gt;

&lt;p&gt;The use of types is one of the main points of using Elm. With strong static types, Elm can infer the types of each variable or function. It prevents a series of mistakes you can make.lso, we don't need to worry about &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt;. &lt;a href="http://rundis.github.io/blog/2016/elm_maybe.html"&gt;Elm has a solution for this.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bringing these things to JS
&lt;/h2&gt;

&lt;p&gt;We saw what Elm is best used for. Let's see how we can bring these things to JavaScript, if it's possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Static Types
&lt;/h2&gt;

&lt;p&gt;There are a few ways you can bring something like static typing to JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flow
&lt;/h3&gt;

&lt;p&gt;We are using Flow in the Formulae project.&lt;/p&gt;

&lt;p&gt;Imagine you have a function, and you have used an undeclared variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Flow will explain that you have used an undeclared variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  formulae_react git:&lt;span class="o"&gt;(&lt;/span&gt;master&lt;span class="o"&gt;)&lt;/span&gt; ✗ flow status
src/output_lib/decoders.js:199
199:   &lt;span class="nb"&gt;let &lt;/span&gt;a &lt;span class="o"&gt;=&lt;/span&gt; b&lt;span class="p"&gt;;&lt;/span&gt;
            ^ identifier &lt;span class="sb"&gt;`&lt;/span&gt;b&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; Could not resolve name
Found 1 error
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now imagine you have a function that receives only a number, what if you pass a string to it?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;timesTwo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;timesTwo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Flow says the type is incompatible with the expected parameter we created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  formulae_react git:&lt;span class="o"&gt;(&lt;/span&gt;master&lt;span class="o"&gt;)&lt;/span&gt; ✗ flow status
src/output_lib/decoders.js:203
203:   timesTwo&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hello"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
^^^^^^^ string. This &lt;span class="nb"&gt;type &lt;/span&gt;is incompatible with the expected
param &lt;span class="nb"&gt;type &lt;/span&gt;of
198: &lt;span class="k"&gt;function &lt;/span&gt;timesTwo&lt;span class="o"&gt;(&lt;/span&gt;x: number&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    ^^^^^^ number

Found 1 error
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These little things can help you a lot in your development phase.&lt;/p&gt;

&lt;h3&gt;
  
  
  TypeScript
&lt;/h3&gt;

&lt;p&gt;TypeScript has a lot of interesting features. &lt;a href="https://www.futurehosting.com/blog/why-you-should-take-a-serious-look-at-typescript/"&gt;We find people all over the web talking highly about it.&lt;/a&gt; Personally, I prefer using Flow, so I'm just mentioning TypeScript here. If you think it's good, go for it!&lt;/p&gt;

&lt;h3&gt;
  
  
  Redux
&lt;/h3&gt;

&lt;p&gt;For those who work with React, Redux is based on the Elm architecture. So, if you are already using Redux, you are using something Elm-based, and you never thought about it.&lt;/p&gt;

&lt;p&gt;We are using Redux and we like it!&lt;/p&gt;

&lt;p&gt;If you check a simple structure of a program in Elm, you can see we have a Model,&lt;br&gt;
a function to update and the view. &lt;a href="http://redux.js.org/docs/introduction/PriorArt.html"&gt;This is very&lt;br&gt;
similar&lt;/a&gt; to redux.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;Html&lt;/span&gt; &lt;span class="k"&gt;exposing&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="c1"&gt;-- MODEL&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="k"&gt;alias&lt;/span&gt; &lt;span class="kt"&gt;Model&lt;/span&gt; &lt;span class="o"&gt;=&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="c1"&gt;-- UPDATE&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="kt"&gt;Msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Reset&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="n"&gt;update&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Msg&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Model&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Model&lt;/span&gt;
&lt;span class="n"&gt;update&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt;
    &lt;span class="kt"&gt;Reset&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;


&lt;span class="c1"&gt;-- VIEW&lt;/span&gt;

&lt;span class="n"&gt;view&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Model&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Html&lt;/span&gt; &lt;span class="kt"&gt;Msg&lt;/span&gt;
    &lt;span class="n"&gt;view&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Redux First Router
&lt;/h2&gt;

&lt;p&gt;Another thing we think is good is Redux First Router. We are not using it on the project I mentioned earlier, but we liked the idea of having routing state being just another part of the application state.&lt;/p&gt;

&lt;p&gt;In our store, we can define all the routes we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;routesMap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;HOME&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// action &amp;lt;-&amp;gt; url path&lt;/span&gt;
  &lt;span class="na"&gt;PRODUCT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/product/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// :id is a dynamic segment&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These actions will be used in the Reducer, we can change the state once we change the route.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;productsReducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HOME&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;PRODUCT&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;...&lt;/span&gt;
      &lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Handling routing in elm via &lt;a href="http://package.elm-lang.org/packages/elm-lang/navigation/latest"&gt;navigation&lt;/a&gt; is basically the same thing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decoders
&lt;/h3&gt;

&lt;p&gt;Elm uses a layer called Decoders, it is a boundary between your front-end and your back-end. We can see this in other languages, but Elm does this very explicitly. In our JavaScript code we created Decoders from the data we received and we created Encoders to the data we send.&lt;/p&gt;

&lt;p&gt;As we are using ImmutableJS, we convert the JSON we receive into our own app types. With this, our app now recognizes weird JSON structures easily, and we also add a new validation phase in getting data from our API.&lt;/p&gt;

&lt;p&gt;Let's imagine we have an API for &lt;code&gt;Person&lt;/code&gt;. Once we receive the data from our server, we call the decode function and its responsibility is to return a &lt;code&gt;PersonType&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;PersonType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;decodePersonType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In our case, our &lt;code&gt;PersonType&lt;/code&gt; is an immutable Record.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Record&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;immutable&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;PersonType&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Record&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;github&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
  &lt;span class="nx"&gt;github&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In our code, we have an &lt;code&gt;ApiPerson&lt;/code&gt; type.his maps exactly to the JSON we will receive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ApiPerson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;github&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;decodePersonType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ApiPerson&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PersonType&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;PersonType&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;github&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;github&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our &lt;code&gt;decode&lt;/code&gt; function converts the Api type, &lt;code&gt;ApiPerson&lt;/code&gt; to our &lt;code&gt;PersonType&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Now you know what are the the good things Elm can bring us. If you can only work in a JavaScript project, you can probably bring some of these Elm feature for your JavaScript code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.oreilly.com/web-platform/free/files/why-elm.pdf"&gt;Why Elm&lt;/a&gt; from Oreilly.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hackernoon.com/why-elm-is-going-to-change-the-world-f5a6c693b2ca"&gt;Why Elm is Going to Change the World&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@rgoomar/why-i-think-elm-is-the-future-of-front-end-development-21e9b091fa05"&gt;Why I think Elm is the Future of Front End Development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/elmlightments/why-elm-is-a-future-of-frontend-interview-with-preethi-kasireddy-92d6bc6a5018"&gt;Why Elm is a future of Frontend? Interview with Preethi Kasireddy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/martincerny/what-elm-and-rust-teach-us-about-the-future"&gt;What Elm and Rust Teach us About the Future&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://elm-lang.org/blog/compilers-as-assistants"&gt;Compiler as Assistant&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://rundis.github.io/blog/2016/elm_maybe.html"&gt;The Elm Maybe&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>elm</category>
      <category>javascript</category>
      <category>compilers</category>
    </item>
    <item>
      <title>gRPC and Protocol Buffers as an alternative to JSON REST APIs</title>
      <dc:creator>franzejr</dc:creator>
      <pubDate>Tue, 05 Feb 2019 12:23:19 +0000</pubDate>
      <link>https://forem.com/franzejr/grpc-and-protocol-buffers-as-an-alternative-to-json-rest-apis-3cg3</link>
      <guid>https://forem.com/franzejr/grpc-and-protocol-buffers-as-an-alternative-to-json-rest-apis-3cg3</guid>
      <description>&lt;p&gt;gRPC is an open-source remote procedure call framework and Protocol Buffers is a mechanism for serializing structured data. Both were developed by Google and are used in their internal and public APIs. Other big players such as Cisco and Netflix already benefit from this technology for mission critical applications.&lt;/p&gt;

&lt;p&gt;In this post, we will learn the core features of gRPC and Protobuf, and compare to JSON REST APIs.&lt;/p&gt;

&lt;p&gt;Read more on: &lt;a href="https://www.smoothterminal.com/articles/grpc-and-protocol-buffers-as-an-alternative-to-json-rest-apis"&gt;https://www.smoothterminal.com/articles/grpc-and-protocol-buffers-as-an-alternative-to-json-rest-apis&lt;/a&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>distributed</category>
    </item>
    <item>
      <title>A free introduction to Elixir, OTP, Ecto, and Phoenix</title>
      <dc:creator>franzejr</dc:creator>
      <pubDate>Fri, 12 May 2017 21:19:01 +0000</pubDate>
      <link>https://forem.com/franzejr/a-free-introduction-to-elixir-otp-ecto-and-phoenix</link>
      <guid>https://forem.com/franzejr/a-free-introduction-to-elixir-otp-ecto-and-phoenix</guid>
      <description>&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%2F800%2F0%2ALkS0h-J96A7w6Ajr." 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%2F800%2F0%2ALkS0h-J96A7w6Ajr."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today, DailyDrip is releasing five weeks of free content to introduce people to the Elixir programming language and prepare them for building web applications using Ecto and Phoenix. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@dailydrip/a-free-introduction-to-elixir-otp-ecto-and-phoenix-228d0e994fc1" rel="noopener noreferrer"&gt;Check out the entire post!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>programming</category>
    </item>
    <item>
      <title>Elm for Javascript Developers - General Aspects</title>
      <dc:creator>franzejr</dc:creator>
      <pubDate>Tue, 09 May 2017 18:17:34 +0000</pubDate>
      <link>https://forem.com/franzejr/elm-for-javascript-developers---general-aspects</link>
      <guid>https://forem.com/franzejr/elm-for-javascript-developers---general-aspects</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdailydrip-assets.s3.amazonaws.com%2FDailyDrip%2Fblog_posts%2Felm-for-js-developers-ep-1%2FelmJS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdailydrip-assets.s3.amazonaws.com%2FDailyDrip%2Fblog_posts%2Felm-for-js-developers-ep-1%2FelmJS.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is Part 1 in a series about Elm for JavaScript Developers. I've been programming in JavaScript for a while, and hearing people speak so highly about Elm inspired me to give it a try! Studying Elm has raised several questions about this language. The idea of this text is to introduce Elm to JavaScript developers like myself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.dailydrip.com/blog/general-aspects-between-elm-and-js" rel="noopener noreferrer"&gt;Read the entire blog post&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>elm</category>
    </item>
  </channel>
</rss>
