<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by BANDANA PANDEY on Medium]]></title>
        <description><![CDATA[Stories by BANDANA PANDEY on Medium]]></description>
        <link>https://medium.com/@bandanapandey11?source=rss-c0abc0611bf4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*e8MMY2n8HIuOZlYLj3UF6w.jpeg</url>
            <title>Stories by BANDANA PANDEY on Medium</title>
            <link>https://medium.com/@bandanapandey11?source=rss-c0abc0611bf4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 21:53:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bandanapandey11/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Retrieving Data fromTextField in Flutter]]></title>
            <link>https://medium.com/@bandanapandey11/retrieving-data-fromtextfield-in-flutter-d33c99142efd?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d33c99142efd</guid>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Mon, 07 Feb 2022 20:28:31 GMT</pubDate>
            <atom:updated>2022-02-07T20:28:31.399Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iW542teb6SOb4AX-v_oSVw.jpeg" /></figure><p>In this blog, we are going to explore different ways of retrieving data from TextField.</p><p>Since TextFields in flutter does not have an ID, we cannot retrieve data on demand using ID. We have to run the callback function every time the text in a text field changes and store that changes in some variable, in case of flutter.</p><p>So, there are two ways to achieve this:</p><ul><li>Using <strong>onChanged</strong> callback</li><li>Using <strong>TextEditingController</strong></li></ul><h3><strong>1. Using onChanged callback</strong></h3><p>Among the above two ways, onChanged is the easiest one. In this case, whenever the text changes in the textfield, onChanged callback is invoked.</p><pre>String value;</pre><pre>TextField(<br> onChanged: (text) {<br>   value = text;<br> },<br>)</pre><h3><strong>2. Using TextEditingController</strong></h3><p>This approach is the more elaborated one, and it involves multiple steps:</p><ul><li>Creating TextEditingController</li><li>Attaching the above created TextEditingController to TextField</li><li>Adding a listener function on this Controller</li><li>This listener function will listen for all the changes we have done on TextField</li></ul><p><strong>Creating TextEditingController:</strong></p><pre>TextEditingController myController<strong> </strong>= TextEditingController();</pre><p><strong>Attaching the created TextEditingController to TextField:</strong></p><pre>TextField(<br>  controller: myController<br>)</pre><p><strong>Adding a listener function on this Controller:</strong></p><pre><strong>myController</strong>.addListener(() {<br>  print(myController.text);<br>})</pre><p>Here, whenever any change happens to textfield, this addListener on <strong>myController</strong> will listen to it.</p><p>To get values using TextEditingController of TextField:</p><pre>myController.text</pre><p>To set values using TextEditingController of TextField:</p><pre>myController.text = &quot;new value&quot;;</pre><p>So, this was it. Hope you liked it, for more such information stay tuned … :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d33c99142efd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing RawSQL in Ecto Phoenix]]></title>
            <link>https://medium.com/@bandanapandey11/writing-rawsql-in-ecto-phoenix-624e1a80fee7?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/624e1a80fee7</guid>
            <category><![CDATA[ecto]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[database-query]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Sun, 24 Jan 2021 13:30:23 GMT</pubDate>
            <atom:updated>2021-01-24T13:30:23.350Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qxCI41tyx03QlhbIklsaJw.jpeg" /></figure><p>I have been using Ecto library for writing most of the database queries in Phoenix application, but there are certain limitations of using this library, as it doesn’t not support few database queries. So, for executing such queries we need to have something that can fulfils our use-case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*axECwrd0-36hiFcpgWT2sw.gif" /></figure><p>I had a scenario where I needed to create view as temporary table, so for this I had to use raw sql as there is no as such support or query api provided for Ecto. So, in order to resolve this I came across <a href="https://hexdocs.pm/ecto/2.2.8/Ecto.Adapters.SQL.html#query!/4"><strong>Ecto.Adapters.SQL.query</strong></a></p><p><strong>Ecto.Adapters.SQL.query!</strong> takes three arguments:</p><ol><li>Repo Module</li><li>Raw sql in string format</li><li>optional list</li></ol><p>And the final statement written for this is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/323e309c5f7329560a4a76aad1b0d87d/href">https://medium.com/media/323e309c5f7329560a4a76aad1b0d87d/href</a></iframe><p><strong>Ecto.Adapters.SQL.query!</strong> returns Struct containing followings:</p><ol><li>columns</li><li>command</li><li>connect_id</li><li>messages</li><li>num_rows</li><li>rows</li></ol><pre>%Postgrex.Result{</pre><pre>   columns: [&quot;id&quot;, &quot;first_name&quot;, &quot;last_name&quot;, &quot;email&quot;, &quot;role_id&quot;],</pre><pre>   command: :select,</pre><pre>   connection_id: 1446,</pre><pre>   messages: [],</pre><pre>   num_rows: 1,</pre><pre>   rows: [[1, &quot;Bandana&quot;, &quot;Pandey&quot;, &quot;test@test.com&quot;, 1]]</pre><pre>}</pre><p>Other example:</p><pre>query = &quot;&quot;&quot; <br>        SELECT * from users;<br>        &quot;&quot;&quot; <br>Ecto.Adapters.SQL.query!(MyApp.Repo, query, [])</pre><p><em>❤️ Like, Share or Leave A Comment!</em></p><p><em>Well, thats all for this blog, Hope you find it informative. If you liked it, please click the 👏🏼 button and share it with others! Feel free to leave any comments.<br>For more such blogs … stay tuned.</em></p><p><em>Happy Coding …</em></p><p><em>Thanks</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=624e1a80fee7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is this Rack?]]></title>
            <link>https://medium.com/@bandanapandey11/what-is-this-rack-64ea5659bca9?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/64ea5659bca9</guid>
            <category><![CDATA[application-server]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Sun, 29 Nov 2020 06:44:37 GMT</pubDate>
            <atom:updated>2020-11-29T06:44:37.721Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PMOOxAFQaGcAGowMDox-5A.jpeg" /></figure><p>We as developers use frameworks like Rails, and while using it everything seems like magic to us because of abstraction. But have you ever thought of how the internal Request/Response cycle works in this Rails framework Or who is the one driving it internally ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*ExJyIXsM9RKPxf8YiStChw.gif" /><figcaption>How??</figcaption></figure><p><strong>RACK is the one which is responsible for handling all these things</strong>.</p><p>But <strong>what is this RACK??</strong></p><p><strong>Rack</strong> is the <strong>middleware</strong> which helps application server to run your rails app. You can think of it as a <strong>common language</strong> that both your <strong>app server</strong> and <strong>rails application understands.</strong> So, our app server interacts to our rails application using rack(translator).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*aRCzDFeRBgsePUh0b5_FdQ.png" /><figcaption>Request Response Flow</figcaption></figure><p><strong>RACK INTERFACE IMPLEMENTATION</strong></p><p>Rack defines a simple interface and it must have these three properties:</p><ol><li>It must respond to <strong>Call</strong> <strong>method</strong></li><li>Call method takes a <strong>single argument</strong>, termed as <strong>env/environment</strong>. This env contains all the data about the request</li><li>Call method returns an <strong>array of three elements</strong> which is <strong>[status, headers, body]</strong> of the response</li></ol><p>Let’s understand the above mentioned points by writing a simple rack complaint application, which returns the text “Hi, I am RACK”</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a0f7011457876ba7543071605f8bd6c/href">https://medium.com/media/6a0f7011457876ba7543071605f8bd6c/href</a></iframe><p>In the above example we can see that RackApp is a class which has one <strong>instance method</strong> termed as <strong>call</strong> which takes <strong>env</strong> as an <strong>argument</strong> and returns an <strong>array containing three elements</strong>:</p><p>This array consists of following three elements:</p><ul><li><strong>Status Code</strong>: 200(HTTP “OK” status)</li><li><strong>Header</strong>: Content-Type(text/plain)</li><li><strong>Body</strong>: [“Hi, I am Rack”]</li></ul><p><strong>Note</strong>: One thing to focus on, is that <strong>Body of the response</strong>([“Hi, I am Rack”]) must respond to each, thats why normal string is enclosed in an array and then returned.</p><p>But in case of some type of IO object this enclosing inside array is not required.</p><p><em>❤️ Like, Share or Leave A Comment!</em></p><p><em>Well, thats all for this blog, Hope you find it informative. If you liked it, please click the 👏🏼 button and share it with others! Feel free to leave any comments.<br>For more such blogs … stay tuned.</em></p><p><em>Happy Coding …</em></p><p><em>Thanks</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64ea5659bca9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Database Migrations: Part II]]></title>
            <link>https://medium.com/@bandanapandey11/database-migrations-part-ii-293411601618?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/293411601618</guid>
            <category><![CDATA[database-migration]]></category>
            <category><![CDATA[activerecord]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ecto]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Fri, 06 Nov 2020 16:58:57 GMT</pubDate>
            <atom:updated>2020-11-06T17:14:01.787Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kK8R0658oUqStgs1Eb2Pog.jpeg" /></figure><p>This is the second part of Database Migrations, after covering the basic terminology about migrations(what, why, how) in <a href="https://medium.com/stackavenue/database-migrations-1d862bbde9ab"><strong>Database Migrations: Part I</strong></a><strong> , </strong>in<strong> </strong>this<strong> </strong>blog we’ll go into deep dives on each of the following things:</p><ul><li>Reversible and Irreversible Migrations</li><li>How to write safe migrations</li></ul><p><strong>Reversible Migrations</strong></p><p>Our migration file specifically contains <strong>change</strong> method, which internally gets mapped to <strong>up</strong> method and <strong>down</strong> method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*09iC8tNaS7GX9FpFJN4Iqw.png" /></figure><p>The up method will be executed when we run migration whereas down method will be executed when we’ll reverse our changes using rollback.</p><p>By using change method, libraries like ActiveRecord and Ecto can by-default figure out how to reverse migrations, without us explicitly specifying up and down methods.</p><p>For example, we are creating a users table by writing migrations like this in Rails</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c05e827c7aefda1470e2fb7a7270d568/href">https://medium.com/media/c05e827c7aefda1470e2fb7a7270d568/href</a></iframe><p>for the above case when we’ll run rake db:migrate, it will create a users table with specified columns, with following <strong>up</strong> method equivalent</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abd179ad647a127711975276a903397f/href">https://medium.com/media/abd179ad647a127711975276a903397f/href</a></iframe><p>and when we’ll run rake db:rollback, ActiveRecord will figure it out that it has to reverse this migrations, with following <strong>down</strong> method equivalent</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa3832b3b7cd427b3dc15b697f47afb6/href">https://medium.com/media/fa3832b3b7cd427b3dc15b697f47afb6/href</a></iframe><p>These type of migrations, where ActiveRecord knows how to revert back(written inside change method), without us explicitly writing up and down methods are termed as <strong>reversible migrations</strong>.</p><p>If we have multiple instructions in the change method, and when we’ll run db:migrate, ActiveRecord will run all the instructions from top to down. Also, when we rollback this(db:rollback) ActiveRecord will run reverse instructions from bottom to top.</p><p>But there is one thing which we should always remember that not <strong>all migrations are reversible migrations</strong>, there are some migrations which ActiveRecord/Ecto does not know how to revert and these types of migrations are called irreversible migrations.</p><p><strong>Irreversible Migrations</strong></p><p>For eg, if we are using <strong>create_table</strong>, <strong>add_index</strong>, <strong>add_column</strong> then ActiveRecord will know that the reverse of this will be <strong>drop_table</strong>, <strong>remove_index</strong>, <strong>remove_column</strong>.</p><p>But let’s be practical not all migrations will be simple like this, there will be use cases where we’ll have to write complex migrations. So, In order to understand this irreversible concept, let’s take an example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0e79b312ef9bdb3f7189089c9a0632f/href">https://medium.com/media/a0e79b312ef9bdb3f7189089c9a0632f/href</a></iframe><p>Here, we want to change the type of column <strong>price</strong> to <strong>float from integer</strong>. So when we’ll run this migration, it’ll change column type of price from integer to float and that is perfect…</p><p><strong>What if I want to revert this migration ?</strong></p><p>According to what we have learnt till now, you all must be thinking that ActiveRecord should revert this migration like how it does in case of create_table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/0*plWtwYwJvKeeWHO-.gif" /></figure><p>So what is this whole drama about ?</p><p>But my friends, we do have some problem here …</p><p>Because, in this case ActiveRecord <strong>will not be able to revert price back to integer from float</strong>, as there is no track maintained by ActiveRecord(or our database schema)regarding price previous state(column_type) which is integer. So our rollback will fail miserably :(</p><p>Now what to do in these type of scenarios?</p><p>In order to avoid these situations, we should always write safe migrations.</p><p><strong>How to write safe migrations ?</strong></p><p>Safe migrations in our case means writing explicitly up and down methods like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbf3c76eccde116f23c668de59e8298f/href">https://medium.com/media/cbf3c76eccde116f23c668de59e8298f/href</a></iframe><p>By writing explicitly down method, we as a developer are making sure that <em>our migrations whenever they’ll be reverted, our database will be moved to it previous stable state without failing or raising any error</em>.</p><p>In this case, when we’ll rollback it’ll change our price column_type to integer thus maintaining previous state of our database.</p><p><strong>How to write safe migrations ?</strong></p><p>In order to write safe migrations, we should always write explicitly up and down method instead of relying on change method and thinking that ActiveRecord/Ecto will handle everything for us.</p><p>ActiveRecord/Ecto libraries are not magic, even-though they solve most of the cases, but there can be use-cases for which they’ll fail. So as a developer, it is our responsibility to think through every scenario and write better code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*bc86FeCxfqV0KJLkriILSg.gif" /><figcaption>Reference Taken from: <a href="https://tenor.com/">https://tenor.com/</a></figcaption></figure><p><em>❤️ Like, Share or Leave A Comment!</em></p><p><em>Well, thats all for this blog, Hope you find it informative. If you liked it, please click the 👏🏼 button and share it with others! Feel free to leave any comments.<br>For more such blogs … stay tuned.</em></p><p><em>Happy Coding …</em></p><p><em>Thanks</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=293411601618" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Database Migrations]]></title>
            <link>https://medium.com/@bandanapandey11/database-migrations-1d862bbde9ab?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d862bbde9ab</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[database-migration]]></category>
            <category><![CDATA[activerecord]]></category>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Sat, 10 Oct 2020 18:48:33 GMT</pubDate>
            <atom:updated>2020-10-11T20:15:39.237Z</atom:updated>
            <content:encoded><![CDATA[<h3>Database Migrations: Part I</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyQK5G98wOaoNKwwyabmVg.jpeg" /></figure><p>In this blog we are going to explore about database migrations, and cover following things:</p><ul><li>What are database Migrations ?</li><li>What is the use of this Migrations ?</li><li>How and where do we maintain this Migration’s Version ?</li><li>Advantages of Migrations</li><li>How to write Migrations ?</li></ul><p><strong>What are database Migrations ?</strong></p><p>Migrations are way to modify database schema using programming language DSL, so that we don’t have to write raw SQL for altering our databases.</p><p>Different programming languages have their respective libraries, to write these migrations.</p><p>For example, In Ruby(ROR) we have <a href="https://edgeguides.rubyonrails.org/active_record_migrations.html"><strong>ActiveRecord library to write migrations</strong></a>, whereas in Elixir(Phoenix) we have <a href="https://hexdocs.pm/ecto_sql/Ecto.Migration.html#:~:text=Migrations%20are%20used%20to%20modify,way%20that%20is%20database%20independent."><strong>Ecto library to write migrations</strong></a><strong>.</strong></p><p>Below are the examples showing migrations in Ruby on Rails(Ruby) and Phoenix(Elixir) frameworks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*lzczrn4Lto5cVd7QBEyBGw.png" /><figcaption><strong>Migration of Users Table Creation in Phoenix using Ecto</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*yLIT2KXcheC66KrZLA6fVg.png" /><figcaption><strong>Migration of Users Table Creation in Rails using ActiveRecord</strong></figcaption></figure><p><strong>What is the use of this Migrations ?</strong></p><p>We know that migrations are used so that we don’t have to write raw SQL to modify database schema. We can think of each and every migrations as being a <strong>new version of database</strong> because in each migration we are doing some changes to our database schema, which in result alter our database’s version.</p><p><strong>What are Migration’s Version ?</strong></p><p>It is nothing, just a timestamp prefixed before the name of migration file. This timestamp is used as unique identifier for identifying migrations individually. This is how a migration file name looks:</p><pre>20200825114400_create_users.rb</pre><p>Above file name, can be divided into following parts:</p><ul><li>20200825114400 : It is timestamp(auto-generated)</li><li>create_users : It is name which you provide when we generate migration file</li><li>.rb : file extension</li></ul><p><strong>How and where do we maintain this Migration’s Version ?</strong></p><p>Library like ActiveRecord maintains a schema file, which keeps <strong>the history of all the database changes</strong>, which are done using migrations. <strong>It also keeps track of the most recent database change(using migration’s recent version)</strong>.</p><p>We can say that schema file is the blueprint of our database.</p><p>This is how schema file looks, in case of Rails’s ActiveRecord:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7QZZLF3UyIAHvnhbwukowQ.png" /><figcaption>schema.rb in RubyOnRails</figcaption></figure><p>Initially this schema file does not have anything, but with each and every migrations, its content gets modified, depicting the changes done to database till now.</p><p><strong>What Advantages does Migration Offers ?</strong></p><ul><li>Migrations are <strong>database -type independent, </strong>as<strong> </strong>they are<strong> </strong>written in respective programming language DSL. So, we don’t have to care about underlying database type whether it is PostgreSQL or MySQL</li><li>Using migrations, <strong>we can create or setup our database from scratch</strong>. This is specially very helpful, when we are setting/moving up our existing project to a new system</li><li>Migrations always make it crystal clear about the <strong>current state of our database</strong></li><li>Using this, we can easily migrate from current version of database to newer one</li></ul><p><strong>How do we write Migrations ?</strong></p><p>In order to understand how to write migrations, let’s take an example of adding users table to database.<br>So, migration file will look like this in Rails Active Record:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb6a5bdcec2a80f222b3e7ac93d570da/href">https://medium.com/media/cb6a5bdcec2a80f222b3e7ac93d570da/href</a></iframe><p>This above migration, adds a table called users with following columns:</p><ul><li><strong>first_name</strong>, of <strong>string</strong> column type</li><li><strong>last_name</strong>, of <strong>string</strong> column type</li><li><strong>email</strong>, of <strong>string</strong> column type</li><li><strong>id</strong>, which is <strong>primary key</strong> will be implicitly added by ActiveRecord</li><li><strong>created_at</strong>(inserted_at in case of Phoenix’s Ecto) and <strong>updated_at</strong>, of <strong>datetime</strong> column type will be added because of timestamps method</li></ul><p>On database which supports transactions, each and every migrations are wrapped inside this database transactions, because of this when we run this migration, the transaction will begin and the changes(users table creation in our case) will be committed. We define this change in our <strong>change</strong> method.<br>We can also rollback this transaction, and make our database move to its previous state(without users table in our case).</p><p>Alternatively we can also use <strong>up</strong> and <strong>down</strong> method, instead of <strong>change</strong> method. Using this approach of writing up and down methods explicitly is specially useful in scenarios , where our written database migrations are not rollback safe. So in those cases, it is always good to explicitly write up and down methods instead of change one.</p><p>In the next blog, we’ll be going to learn about what are reversible and irreversible migrations, as well as how to write safe migrations and precautions which we should take while writing migrations.</p><p><em>❤️ Like, Share or Leave A Comment!</em></p><p><em>Well, thats all for this blog, Hope you find it informative. If you liked it, please click the 👏🏼 button and share it with others! Feel free to leave any comments.<br>For more such blogs … stay tuned.</em></p><p><em>Happy Coding …</em></p><p><em>Thanks</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d862bbde9ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When to Use after_commit in Rails ?]]></title>
            <link>https://medium.com/@bandanapandey11/when-to-use-after-commit-in-rails-f5e53a22bb9?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5e53a22bb9</guid>
            <category><![CDATA[rails-5]]></category>
            <category><![CDATA[callback]]></category>
            <category><![CDATA[activerecord]]></category>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Sat, 22 Aug 2020 18:05:49 GMT</pubDate>
            <atom:updated>2021-12-23T03:31:55.918Z</atom:updated>
            <content:encoded><![CDATA[<h3>When to Use after_commit in Rails?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FEYTHDNN0LQrsvv_hyv31w.png" /></figure><p>after_commit is a type of active record callback.</p><h4>What are Active Record Callback?</h4><p><a href="https://guides.rubyonrails.org/active_record_callbacks.html">Active Record Callbacks</a> helps us to execute code at certain stages of object life-cycle. Read more about it <a href="https://guides.rubyonrails.org/active_record_callbacks.html">here</a>.</p><p>In order to understand where we should use after_commit callback, let’s take a scenario of an organisation where we have to add a member in it. Whenever that is done, we need to notify organisation’s admin through email about the added member.</p><p>To achieve this use-case, many of us would go for active-record’s <a href="https://apidock.com/rails/ActiveRecord/Callbacks/after_save"><strong>after_save callback</strong></a>.</p><p>And why should we not? One would wonder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*msbOIxVRvXwc5bG9-PNcHQ.gif" /><figcaption>why not ??</figcaption></figure><p>Using after_save would fulfils our requirement in this scenario. So there shouldn’t be a problem.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29ece2b26fd4b00a5f3b2cbf809feabc/href">https://medium.com/media/29ece2b26fd4b00a5f3b2cbf809feabc/href</a></iframe><p>But here, my friend, even though code looks perfectly fine, there may be a glitch in it.</p><p>The <strong>after_save</strong> callback will be executed after the user record is saved to database but the transaction is still not complete. We know about the Atomicity principle (ACID Properties), that a database runs everything in a transaction. If somehow due to any other operation the transaction fails to complete, then the database will revert the addition of member.</p><p>In that case, since the email job has already started running in the background, It will raise a <strong>NotFound </strong>exception<strong> </strong>when it runs<strong> </strong><em>self.id.</em></p><p>So, how to overcome this?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*GOwayZdhTb4MwOjlLXMPPg.gif" /><figcaption>How to fix it ?</figcaption></figure><p>In order to solve this, we need to use <strong>after_commit</strong> callback in place of <strong>after_save</strong>.</p><p><a href="https://apidock.com/rails/ActiveRecord/Transactions/ClassMethods/after_commit"><strong>after_commit callback</strong></a> will ensure that the <em>send_email_notifications</em> method is executed only when the commit transaction completes in the database.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9a5fca5721e26ee55a6a2c46a7c6c5e/href">https://medium.com/media/e9a5fca5721e26ee55a6a2c46a7c6c5e/href</a></iframe><p>So, what did we learn here?<br>We should always think before using callbacks, which one of them will satisfy our requirements and then use it.</p><p>Hope you liked this information. For more such information stay tuned.<br>Happy Coding ….. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5e53a22bb9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forms In Flutter]]></title>
            <link>https://medium.com/@bandanapandey11/forms-in-flutter-4dc30c239c26?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dc30c239c26</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[form-validation]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[widget]]></category>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Tue, 11 Aug 2020 12:35:00 GMT</pubDate>
            <atom:updated>2020-08-12T12:16:13.111Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLs2e61vn7BKroGAC_pS2A.png" /></figure><p>Nowadays, almost every mobile applications use forms for different use-cases.</p><p>So, in this blog we are going to explore following things:</p><ul><li>How to implement forms in flutter</li><li>Form Validations</li><li>Form Saving</li></ul><h3><strong>Implementation</strong></h3><p>As we know, <strong>in flutter everything is widget</strong>, just like how everything is Object in Object Oriented Programming Language.</p><p>So, in flutter we have widget for form also, termed as <a href="https://api.flutter.dev/flutter/widgets/Form-class.html"><strong>form</strong></a> widget.</p><p><strong>Form Widget:</strong></p><p>It is container for <strong>grouping</strong> multiple <strong>form fields widgets</strong>, and helps in <strong>validating</strong> all these fields before <strong>saving </strong>the form.</p><p>Before writing actual code, let’s go through a terminology called as GlobalKey which you guys will hear frequently, whenever you implement forms in flutter.</p><p><strong>What is this GlobalKey ?</strong></p><p><a href="https://api.flutter.dev/flutter/widgets/GlobalKey-class.html"><strong>GlobalKey</strong></a> use-case in flutter is similar to that of id of the form in html, which is basically used for unique identification of a respective form. And later with the help of this identifier, we validate our form(which we’ll be seeing in later section of this blog).</p><p>Now, let’s move further and write code.</p><pre>class TaskPage extends StatefulWidget {<br>  <a href="http://twitter.com/override">@override</a><br>  _TaskPageState createState() =&gt; new _TaskPageState();<br>}</pre><pre>class _TaskPageState extends State&lt;TaskPage&gt; {<br>  // Create a global key that uniquely identifies the Form widget<br>  final <strong>_formKey</strong> = <strong>GlobalKey&lt;FormState&gt;()</strong>;<br>  <br>  Widget build(BuildContext context) {<br>   // Build a Form widget using the _formKey created above.<br>   return Form(<br>     <strong>key</strong>: this._formKey,<br>     <strong>child</strong>: new ListView(<br>       <strong>children</strong>: &lt;Widget&gt;[<br>         // Add TextFormFields and RaisedButton here.<br>       ]<br>     )<br>   );<br>  }<br>}</pre><p>Here, we can see we are using form widget(Form()), which consists of following parts:</p><ul><li><strong>key</strong>: this._formKey(which is GlobalKey)</li><li><strong>child</strong>: It will be a ListView of multiple widgets like <a href="https://api.flutter.dev/flutter/material/TextFormField-class.html"><strong>TextFormField</strong></a>, <a href="https://api.flutter.dev/flutter/material/RaisedButton-class.html"><strong>RaisedButton</strong></a></li></ul><p>But, In the form there should be a way by which user can enter text and fill their information. So, that my friend is the job of our <a href="https://api.flutter.dev/flutter/material/TextFormField-class.html"><strong>TextFormField</strong></a><strong> </strong>widget.</p><p><strong>TextFormWidget:</strong></p><p>The <a href="https://api.flutter.dev/flutter/material/TextFormField-class.html">TextFormField</a> in flutter renders a material design text field and can show validations error, whenever the data is invalid.</p><p>Ok, So with this we are moving to our next section of our blog ie,</p><p><strong>Form Validation:</strong></p><p>In all types of form fields widgets(like TextFormField), we have <strong>validator() </strong>function, which is used to validate the user’s input.</p><p>Here, the validator() function, receives the data that the user has entered. It processes the data and if the user’s input is invalid, it returns “error text”, otherwise it returns null.</p><pre><strong>TextFormField</strong>(<br>  // The validator receives the text that the user has entered.<br>  <strong>validator</strong>: (value) {<br>    if (value.isEmpty) {<br>      return &#39;Please enter your data&#39;;<br>    }<br>    return null;  <br>  },<br>  <strong>decoration</strong>: new InputDecoration(labelText: &#39;Task Name&#39;),<br>);</pre><p>You can also provide label text to the TextFormFieldwidget using InputDecoration function as mentioned in the above example.</p><p>So, till now we have seen how to create a form, and how to validate its fields in flutter.</p><p>And here comes the most interesting part, as how to save forms data ?</p><p><strong>Form Saving:</strong></p><p>We already have a form with TextFormField, now ideally we should have a button or something like that, which when clicked will save the form data.</p><p>So, this is how it will look :</p><pre><strong>RaisedButton</strong>(<br>  <strong>onPressed</strong>: () {<br>    final form = _formKey.currentState;<br>    // Validate returns true if the form is valid, otherwise false.<br>    if (form.validate()) {<br>      // If the form is valid, display a snackbar.<br>      // In the real world, you&#39;ll mostly save data in database.<br>      form.save();<br>      Scaffold.of(context)<br>              .showSnackBar(SnackBar(content: Text(&#39;Saving Data&#39;)));<br>    }<br>  },<br>  <strong>child</strong>: Text(&#39;Save&#39;),<br>),</pre><p>Here, whenever user click on Save button(RaisedButton), we are doing following things:</p><ul><li>first, we check whether the form is valid or invalid using <strong>form.validate()</strong></li><li>If the form is valid, then only we show SnackBar or save valid form data to database/server depending on our use-cases.</li></ul><p>To summarise it, this is what happens behind the scenes after button is pressed:</p><ul><li>For form validation we use _formKey(GlobalKey) method formKey.currentState</li><li>_formKey.currentState gives us the <a href="https://api.flutter.dev/flutter/widgets/FormState-class.html"><strong>FormState</strong></a></li><li>This FormState has method called as <a href="https://api.flutter.dev/flutter/widgets/FormState/validate.html"><strong>validate</strong></a><strong>() </strong>and we invoke this method</li><li><a href="https://api.flutter.dev/flutter/widgets/FormState/validate.html"><strong>validate</strong></a><strong>()</strong> method <strong>runs the validator() </strong>function of each and every form fields (like that of TextFormField)</li><li>If any of the form fields contains error(is invalid), validate() method rebuilds the whole form with error message and return false</li><li>Otherwise if form fields doesn’t have any error , validate() returns true and then it successfully executes the code inside condition (in our case showing SnackBar)</li></ul><p>Below is the final code with all the changes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b615003b3f5ea0abea7bf7f290c2d91/href">https://medium.com/media/2b615003b3f5ea0abea7bf7f290c2d91/href</a></iframe><p>Hope you liked the blog, for more such blogs stay tuned … :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dc30c239c26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Listing of Items in Flutter]]></title>
            <link>https://medium.com/@bandanapandey11/listing-of-items-in-flutter-ca7f1b4866b6?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca7f1b4866b6</guid>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Thu, 19 Mar 2020 18:16:01 GMT</pubDate>
            <atom:updated>2020-03-19T18:16:01.583Z</atom:updated>
            <content:encoded><![CDATA[<p>In any mobile application, listing of data is very fundamental need. And, in this blog, we are going to learn how to display list of items in flutter.</p><p>There are usually two types of use-cases regarding listing of data:</p><ul><li>Displaying List having <strong>few number of items</strong></li><li>Displaying List having <strong>large number</strong> <strong>of items</strong></li></ul><p>So, Let’s go through each one of the above mentioned use-cases</p><h3><strong>1. Few Items:</strong></h3><p>Flutter provides us with a widget termed as <a href="https://api.flutter.dev/flutter/widgets/ListView-class.html"><strong>ListView</strong></a> for listing of items.</p><p>If we want to display fixed list of few items , than we can use make use of <strong>ListView constructor</strong> like this:</p><pre><strong>ListView</strong>(<br>  <strong>children</strong>: &lt;Widget&gt;[<br>    <strong>ListTile</strong>(<br>      <strong>leading</strong>: Icon(Icons.home),<br>      <strong>title</strong>: Text(&#39;Home&#39;),<br>    ),<br>    <strong>ListTile</strong>(<br>      <strong>leading</strong>: Icon(Icons.search),<br>      <strong>title</strong>: Text(&#39;Search&#39;),<br>    ),<br>    <strong>ListTile</strong>(<br>      <strong>leading</strong>: Icon(Icons.info),<br>      <strong>title</strong>: Text(&#39;Info&#39;),<br>    ),<br>    <strong>ListTile</strong>(<br>      <strong>leading</strong>: Icon(Icons.exit_to_app),<br>      <strong>title</strong>: Text(&#39;Logout&#39;),<br>    ),<br>  ],<br>);</pre><p>ListView constructor takes list of <strong>ListTile</strong> widgets.</p><p>Here, <a href="https://api.flutter.dev/flutter/material/ListTile-class.html"><strong>ListTile</strong></a> widget is used to provide visual representation to each and every element of list.</p><p>In real life, these kind of listing is mostly used on the drawer screen of mobile application, where there is standard fixed and few number of items are present.</p><p>Below, is the full implementation code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8568cf768955a9ef3edd62554dafb7b/href">https://medium.com/media/f8568cf768955a9ef3edd62554dafb7b/href</a></iframe><h3><strong>2. Large number of items</strong></h3><p>But, what if we want to display a list that contains a large amount of data ?</p><p>In this case, we cannot use ListView constructor as it is useful in case of few items only.</p><p>So, <strong>what should we use ?</strong></p><p>For this purpose only, ListView.builder() is provided by flutter.</p><p><em>Note* : ListView is by default scrollable in flutter</em></p><p>Let’s go through the actual implementation of ListView.builder()</p><pre>// created list of 25 items<br>final data = List&lt;String&gt;.generate(25, (int index) =&gt; &#39;sqRoot ${index * index}&#39;);</pre><pre><strong>ListView.builder</strong>(<br>  <strong>itemCount</strong>: data.length,<br>  <strong>itemBuilder</strong>: (context, index) {<br>    return <strong>ListTile</strong>(<br>      <strong>title</strong>: Text(&#39;${data[index]}&#39;),<br>    );<br>  },<br>);</pre><p>Here, we have generated data of 25 items and then provided it to ListView.builder.</p><p>ListView.builder consists of two parts:</p><ul><li><strong>itemCount</strong>: total number of elements</li><li><strong>itemBuilder</strong>: It takes context and index of data element, and builds ListTile for each and every data element</li></ul><p><em>Note* : ListView.builder() creates items as user scrolls down whereas, ListView() constructor creates all the items at once.</em></p><p>Below is the full implementation of ListView.builder</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d7078364da87b289221134891b4d1f4/href">https://medium.com/media/5d7078364da87b289221134891b4d1f4/href</a></iframe><p>Hope you liked it.</p><p>For more such information, stay tuned…</p><p>Happy Coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca7f1b4866b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why use Safe Navigation Operator (&) instead of try]]></title>
            <link>https://medium.com/@bandanapandey11/why-use-safe-navigation-operator-instead-of-try-88d1b312bb70?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/88d1b312bb70</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[try]]></category>
            <category><![CDATA[safe-navigation-operator]]></category>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Mon, 12 Aug 2019 11:06:42 GMT</pubDate>
            <atom:updated>2019-08-12T11:06:42.351Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7oNeqQvRxdq4go-K.jpg" /></figure><p>While writing Ruby or Rails code, we all must have come across some scenario like where we want to get the Pincode of user’s address.</p><p>In this case, we have a users table and each user has an address stored in the addresses table having a Pincode column. But there may be data related issues where the user doesn’t have an address record present or address is there but Pincode is not. Here, if we fetch Pincode on nil(address), it will crash your application.</p><p>There are two ways in order to be safe and not have nil error in our application:</p><ul><li>Using try</li><li>Using safe navigation operator(&amp;)</li></ul><p><strong>Using try:</strong></p><pre>user.try(:address).try(:pincode)</pre><p><strong>Using safe navigation operator(&amp;)</strong></p><pre>user&amp;.address.&amp;pincode</pre><p>Now, you guys will be thinking both the ways are similar.</p><p>But to be frank they are not.</p><p>Hmmm…. let’s not make any decision before knowing what is actually happening behind the scenes.</p><p><strong>So, What is the difference?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/0*K3N2GVP2_sK-cS48" /><figcaption>what’s the difference?</figcaption></figure><p>Safe Navigation Operator was introduced in <strong>Ruby 2.3,</strong> whereas try is the method implemented on <strong>Rails ActiveSupport</strong>. Thus, making a safe navigation operator(&amp;) comparatively faster than try one and making it available to any ruby application</p><p><strong>What try does behind the scene?</strong></p><ul><li>try will always return nil</li><li><strong>It does not check if the object(address) has an implementation of the called method(pincode) or not.</strong> It will anyways return nil, whether pincode is there or not.</li><li>So here, if by mistake we have written <strong>pincode1 in place of pincode</strong>, we’ll never come to know what is happening, it will be a black box type of thing for us. In such cases, it will be very difficult to debug why we are always getting nil value because try will always return nil</li></ul><pre>user.try(:address).try(:pincode1)<br>&gt; nil</pre><pre>1.try(:demo)<br>&gt; nil</pre><pre>nil.try(:demo)<br>&gt; nil</pre><p>But folk, don’t be afraid, we have another friend known as ‘&amp;’ who will save us from this.</p><p><strong>What Safe Navigation Operator(&amp;) does behind the scene?</strong></p><ul><li>Unlike try, safe navigation operator(&amp;)<strong> checks if the receiver has implemented the called method or not</strong></li><li>If the called method is not implemented it raises an error(NoMethodError: Undefined Method)</li></ul><pre><strong>1</strong>&amp;.(:demo)<br>&gt; NoMethodError: undefined method `call&#39; for 1:Integer</pre><ul><li>But, if the receiver is nil, it makes an exception and not check the called method implementation, thus always returning nil in this case</li></ul><pre><strong>nil</strong>&amp;.demo<br>&gt; nil</pre><ul><li>So, in the above case, if we have mistakenly typed pincode1, we will get an error as <strong>Undefined Method pincode1</strong>, given that user’s address is present</li><li>But, if the address is also nil for a user, and we are calling pincode1, it will return nil</li></ul><p>Hope you like the blog.</p><p>For more such information … stay tuned</p><p>Happy Coding</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88d1b312bb70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shinning Assets of Elixir]]></title>
            <link>https://medium.com/@bandanapandey11/shinning-assets-of-elixir-7620a59e0272?source=rss-c0abc0611bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7620a59e0272</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[pipe-operator]]></category>
            <dc:creator><![CDATA[BANDANA PANDEY]]></dc:creator>
            <pubDate>Sun, 09 Jun 2019 14:12:46 GMT</pubDate>
            <atom:updated>2019-06-09T14:12:46.567Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Image result for elixir image" src="https://cdn-images-1.medium.com/proxy/1*wVcT8A29lBkN0gXFPJUF3w.png" /></figure><p>I have been working in Ruby and ROR applications for almost three years. Recently, I came across a new language, ‘Elixir’. I have started learning and playing with it a few months back.</p><p>And let me tell you guys, as per my experience, it is among one of the most fascinating and interesting languages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*5mB81Y5L2mRm9Pkq.gif" /><figcaption>Elixir is the new Cool</figcaption></figure><p><strong>Elixir is also open-source just like Ruby</strong>. There are multiple companies like <a href="https://bleacherreport.com/">BleacherReport</a>, <a href="https://www.square-enix.com/">SquareEnix</a>, Bet365, Pinterest, WhatsApp and many more who are using Elixir and Erlang in their live production environments.</p><p>There is so much whirring of this language in open-source communities and today markets and why should it not be?</p><p>Let’s begin our journey with our new friend <strong>Elixir. </strong>😉</p><p>As for the beginner, I highly recommend you guys to go through <a href="https://elixir-lang.org/getting-started/introduction.html">Elixir’s official documentation</a> because it is well-maintained and awesome.</p><p>What I find most fascinating about Elixir are followings assets:</p><ul><li><strong>Pipe Operator</strong></li><li><strong>Pattern Matching</strong></li><li><strong>OTP (Open Telecom Platform)</strong></li></ul><p>For the sake of keeping this article short and simple, I will keep its scope limited to the discussion of the Pipe Operator only. Let’s discuss the other two features in the next articles in the series.</p><p><strong>Pipe Operator</strong> :</p><p>In order to understand it, let’s take a simple case, where we have a list of numbers, and we want to manipulate that list by first converting each element to even number (by multiplying it by 2) and then reversing the list.</p><p>Let’s code:</p><p><strong>Implementation in Ruby:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbad3dbc03c7ecd63a40749c17d127e1/href">https://medium.com/media/bbad3dbc03c7ecd63a40749c17d127e1/href</a></iframe><p><strong>Implementation in Elixir without Pipe Operator:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dad6327886514198efd9a965ad6e14f1/href">https://medium.com/media/dad6327886514198efd9a965ad6e14f1/href</a></iframe><p>On the basis of our observation, we can see the following differences between Ruby(OOP) and Elixir(Functional Programming):</p><ul><li>Syntax, not a major difference, it is almost the same</li><li>In Ruby implementation, we are calling methods(map, reverse) on objects(numbers) but in Elixir code, we are passing data(numbers) to functions(map and reverse)</li><li>In Elixir, we don’t have classes that we have in Ruby, it has modules like Enum.</li><li>In Ruby, we are manipulating the list(numbers) but in Elixir, we are not instead we are passing the data to functions. That is due to the <strong>Immutability </strong>of data-structures in Elixir.</li></ul><p><strong>Implementation in Elixir using pipe operator(|&gt;):</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a967ef6d8a6c3ea4bffbf10f539cf24e/href">https://medium.com/media/a967ef6d8a6c3ea4bffbf10f539cf24e/href</a></iframe><p>As we can see here in the above implementation, we are not passing the list of numbers to the functions which we were doing earlier. But why ??</p><p>That is because of our smart kid <strong>Pipe Operator(|&gt;)</strong></p><blockquote>Pipe Operator passes data which we had received from the previous function to the next function as the first argument.</blockquote><p>The first argument in our case is numbers. Therefore, we haven’t specified the first argument in the map and reverse functions of the Enum module.</p><p>As a result pipe operator <strong>makes it easy to read and understand the data transformations and chaining between different functions</strong>(map and reverse in our case). We don’t have to explicitly save the return value of a function to the local variable to just pass it to the next function.</p><p>At the end of the day, the pipe operator provides us the flexibility to write clean code and avoid messy programming.</p><p>So, here we have learned about pipe operator, let’s continue more Elixir’s assets — Pattern matching and OTP in the next blogs.</p><p>Hope you liked it. For more such information stay tuned … 😁</p><p>Happy Coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7620a59e0272" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>