<?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 Leo Benkel on Medium]]></title>
        <description><![CDATA[Stories by Leo Benkel on Medium]]></description>
        <link>https://medium.com/@leo.benkel?source=rss-d62891d58841------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lepUrokeCeEobFYuHeBqMg.jpeg</url>
            <title>Stories by Leo Benkel on Medium</title>
            <link>https://medium.com/@leo.benkel?source=rss-d62891d58841------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 06 Jun 2026 00:38:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leo.benkel/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[SKB — Scala foldLeft]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-foldleft-93c105bc17d5?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/93c105bc17d5</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <category><![CDATA[teaching]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Wed, 23 Sep 2020 17:01:07 GMT</pubDate>
            <atom:updated>2020-10-23T16:02:08.800Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala foldLeft</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*mYbr-kuQO1FXpDgn" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about Scala foldLeft.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about Scala foldLeft !</p><p>Let me introduce <em>accumulators</em> and <em>aggregations</em>.</p><p>foldLeft is the generic concept that is under most of the function programming transformations. You can replace map, flatMap, filter and more by a foldLeft.</p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3DDVHHL3I%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2FDVHHL3I%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/346142d8c3a43565f6903857b393c54c/href">https://medium.com/media/346142d8c3a43565f6903857b393c54c/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/1YO5x72fSE686gtMiAxKzQ">Scastie (1YO5x72fSE686gtMiAxKzQ)</a>.</p><h3>More information about Scala foldLeft</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about Scala foldLeft.</p><p>In this exercise, you can see two use cases of foldLeft. But first let&#39;s explain the syntax:</p><pre>foldLeft(initialValue) { case (accumulator, currentElement) =&gt; <br>    // return the new value of the accumulator<br>}</pre><p>Note that when currentElement is the first element of the List, then accumulator is equal to initialValue. Also, if the the list is empty, then the returned value will be the initialValue.</p><p>The returned value can be anything, for instance:</p><pre>foldLeft(List.empty) { case (accumulator, currentElement) =&gt; <br>    accumulator :+ currentElement <br>}</pre><p>would return a new List with the same content as the input list.</p><p>An other example:</p><pre>foldLeft(0) { case (accumulator, currentElement) =&gt; <br>    accumulator + currentElement <br>}</pre><p>would return the total sum of the item of the List. This is similar to the first example in today&#39;s exercise. And scala provide a shortcut for it: .sum, this would be a special case of the exercise when the initial value is 0.</p><p>In the second use case, there is a bit more going on. It uses <em>pattern matching</em> to implement different behavior based on the current element and create a new list element by element.</p><p>As an extra exercise, try to compute the average of the list by changing the initialized value from startFold to (0, 0) and modify the function to aggregate the values.</p><p>You can also try to implement map, flatMap and, filter using foldLeft. Share your solution with our community on Discord !</p><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for Scala foldLeft.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>Feel free to try on <a href="https://leobenkel.com/2020/09/skb-scala-stream/">the next Scala Knowledege Bit</a>.</p><p>If you are curious about <a href="https://leobenkel.com/2020/09/skb-scala-pattern-matching/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-foldleft/"><em>https://leobenkel.com</em></a><em> on September 23, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93c105bc17d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-foldleft-93c105bc17d5">SKB — Scala foldLeft</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SKB — Scala pattern matching]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-pattern-matching-8529f9a56058?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/8529f9a56058</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Mon, 21 Sep 2020 17:00:55 GMT</pubDate>
            <atom:updated>2020-10-21T16:03:21.461Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala pattern matching</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*t8Myb5f54oSOO5nT" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about Scala pattern matching.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about Scala pattern matching !</p><p>We are going to learn about <em>pattern matching</em> today. At least, an introduction. Pattern matching is one of the key functionality of scala and it contributes to help you write clean and readable code.</p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3DykD0A0R%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2FykD0A0R%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/161d13caf862790cd6277106d3de3192/href">https://medium.com/media/161d13caf862790cd6277106d3de3192/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/5VQri4WFQ6yrPuBJHNIh5A">Scastie (5VQri4WFQ6yrPuBJHNIh5A)</a>.</p><h3>More information about Scala pattern matching</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about Scala pattern matching.</p><p>The main keyword to use <em>pattern matching</em> is match. But as you saw, you can also use it inside map, as well as flatMap and filter and more.</p><p>The overall syntax is:</p><pre>value match {<br>    case holder =&gt; action<br>    case _ =&gt; default case<br>}</pre><p>And similar inside a map or other:</p><pre>list.map {<br>    case holder =&gt; action<br>    case _ =&gt; default case<br>}</pre><p>There are plenty of ways that <em>pattern matching</em> can be used and we only saw a few here, let’s review:</p><ul><li>catch all: case n =&gt; ???</li><li>catch all without the value: case _ =&gt; ???</li><li>With condition: case n if n % 2 == 0 =&gt; ???</li><li>Exact match: case 3 =&gt; ??? or case &quot;abc&quot; =&gt; ???</li><li>List extraction:</li><li>&gt; Empty list: case Nil =&gt; ???</li><li>&gt; Extract head: case head :: tail =&gt; ???</li><li>&gt; One element: case head :: Nil =&gt; ???</li><li>&gt; Two elements: case first :: second :: Nil =&gt; ???</li><li>&gt; One element with condition: case head :: Nil if head % 2 == 0 =&gt; ???</li><li>&gt; Extract value: case 12 :: tail =&gt; ???</li><li>With types: case n: String =&gt; ???</li><li>Case classes: (there will be an SKB about it)</li><li>&gt; Extraction of field: case Person(firstName, lastName) =&gt; ???</li><li>&gt; Extraction of field with condition: case Person(firstName, lastName) if firstName.startsWith(&quot;L&quot;) =&gt; ???</li><li>&gt; Extraction of field with exact match: case Person(&quot;Leo&quot;, lastName) =&gt; ???</li><li>With regex: There will be an SKB about it</li><li>With Scala version of enumeration: There will be an SKB about it</li></ul><p>I might have forgotten some. If so, please let me know in the comment below or on our discord server.</p><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for Scala pattern matching.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>Feel free to try on <a href="https://leobenkel.com/2020/09/skb-scala-foldleft/">the next Scala Knowledege Bit</a>.</p><p>If you are curious about <a href="https://leobenkel.com/2020/09/skb-scala-defined-type/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-pattern-matching/"><em>https://leobenkel.com</em></a><em> on September 21, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8529f9a56058" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-pattern-matching-8529f9a56058">SKB — Scala pattern matching</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SKB — Scala defined type]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-defined-type-a68184d94a10?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/a68184d94a10</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <category><![CDATA[scala]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Fri, 18 Sep 2020 17:00:29 GMT</pubDate>
            <atom:updated>2020-10-19T16:02:19.890Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala defined type</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*Ej_JtzTERIPpqOgi" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about SKB — Scala defined type.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about SKB — Scala defined type !</p><p>Let’s make our own type!</p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3D6UdJ6lc%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2F6UdJ6lc%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e3a844502e30b5370741b69b2a58fb7/href">https://medium.com/media/7e3a844502e30b5370741b69b2a58fb7/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/MBpSt9KLQECIxOPK8Phaeg">Scastie (MBpSt9KLQECIxOPK8Phaeg)</a>.</p><h3>More information about SKB — Scala defined type</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about SKB — Scala defined type.</p><p>You saw how to parameterize the entire code.</p><p>Try change MyType from Int to String.</p><p>This seem simple but it is a building block required to understand generic type later.</p><p>If you want to start now, try to replace MyType by the following code:</p><pre>type SubType = Int type MyType = List[SubType]</pre><p>Do you see how you can combine types together ? Like Lego !</p><p>List can be parameterized, we used it with Int and String in the past, but you can use any type you want.</p><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for SKB — Scala defined type.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>Feel free to try on <a href="https://leobenkel.com/2020/09/skb-scala-pattern-matching/">the next Scala Knowledege Bit</a>.</p><p>If you are curious about <a href="https://leobenkel.com/2020/09/skb-scala-set/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-defined-type/"><em>https://leobenkel.com</em></a><em> on September 18, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a68184d94a10" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-defined-type-a68184d94a10">SKB — Scala defined type</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SKB — Scala Set]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-set-5ec9fc837c75?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ec9fc837c75</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Wed, 16 Sep 2020 17:00:06 GMT</pubDate>
            <atom:updated>2020-10-16T16:03:07.911Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala Set</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*tZiJa6pEk3tWZc-l" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about Scala Set.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about Scala Set !</p><p>We saw other data structures in previous SKB like List or Map.</p><p>Let’s look at Set.</p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3DDlNiQ4U%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2FDlNiQ4U%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/16580cb54cb711bbac9ea1bb04585fbf/href">https://medium.com/media/16580cb54cb711bbac9ea1bb04585fbf/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/Xnga8KMIQimJPP8BwT5VAQ">Scastie (Xnga8KMIQimJPP8BwT5VAQ)</a>.</p><h3>More information about Scala Set</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about Scala Set.</p><p>Did you notice that Set cannot contain duplicate values? A Set is a list of unique values.</p><p>When you combine the two Set, it removes the duplicated values and only keep one of each.</p><p>One thing to know is that Set do not guarantee consistant ordering. You should not rely on index of the elements. If you want to learn more, you can read <a href="https://stackoverflow.com/a/5246204/3357831">this great answer on Stackoverflow</a>.</p><p>Last thing about Set is that it has all the same function as List such as map, flatMap, filter, etc...</p><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for Scala Set.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>Feel free to try on <a href="https://leobenkel.com/2020/09/skb-scala-defined-type/">the next Scala Knowledege Bit</a>.</p><p>If you are curious about <a href="https://leobenkel.com/2020/09/skb-scala-main/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-set/"><em>https://leobenkel.com</em></a><em> on September 16, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ec9fc837c75" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-set-5ec9fc837c75">SKB — Scala Set</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SKB — Scala main]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-main-2994a25b694b?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/2994a25b694b</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Mon, 14 Sep 2020 17:00:10 GMT</pubDate>
            <atom:updated>2020-10-14T16:02:33.564Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala main</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*8Nnaq2bYDTfPXumO" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about Scala main.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about Scala main !</p><p>A main is the method that is being called to start your program. It needs a specific structure - called <em>prototype</em> when talking about methods - to be recognized.</p><p>Until now we ran all the SKBs in <em>Worksheet</em> mode which hides the main from us.</p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3DbKOdVm4%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2FbKOdVm4%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d9f8621321b8674f2933b51b83f70b2/href">https://medium.com/media/7d9f8621321b8674f2933b51b83f70b2/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/Eb9UJewvRlOeORHTpjD5lQ">Scastie (Eb9UJewvRlOeORHTpjD5lQ)</a>.</p><h3>More information about Scala main</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about Scala main.</p><p>If you have tried to remove or change the main function, you might have noticed an exception:</p><pre>java.lang.RuntimeException: No main class detected.</pre><p>This Exception will be thrown if a main method cannot be found or is not contained within an object. Try to change the code to trigger it.</p><p>The main prototype is always of the form:</p><pre>def main(args: Array[String]): Unit = { }</pre><p>The args: Array[String] is where you would be able to read and use the arguments given to the application when started.</p><p>That is pretty much it concerning main, so I thought it would be nice to combine some of the things we&#39;ve seen in the past. This SKB is using Map, object, Option, lazy val, def all into the same project. Try to play with it and make it your own.</p><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for Scala main.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>Feel free to try on <a href="https://leobenkel.com/2020/09/skb-scala-set/">the next Scala Knowledege Bit</a>.</p><p>If you are curious about <a href="https://leobenkel.com/2020/09/skb-scala-list-parallel/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-main/"><em>https://leobenkel.com</em></a><em> on September 14, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2994a25b694b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-main-2994a25b694b">SKB — Scala main</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SKB — Scala List parallel]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-list-parallel-bb3446dab126?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb3446dab126</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Fri, 11 Sep 2020 17:01:21 GMT</pubDate>
            <atom:updated>2020-10-12T16:03:00.506Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala List parallel</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*7NvQ-uB3JniE5YeJ" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about Scala List par.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about Scala List par !</p><p><strong>I am going to give you an introduction to <em>parallelization</em>. For this, I will be using </strong><strong>par.</strong></p><p><strong>However, you have to know, that to use this in Scala 2.13+ you need extra steps. You can read more on </strong><a href="https://stackoverflow.com/a/57290463/3357831"><strong>Stackoverflow</strong></a><strong>. I made the choice to still be using it because, I think, it is a great stepping stone to understand more complex subjects.</strong></p><p><strong>Let’s dive in!</strong></p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3DJQFaFDM%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2FJQFaFDM%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/425cad5e0bfe658684e9f0a5b8c9015c/href">https://medium.com/media/425cad5e0bfe658684e9f0a5b8c9015c/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/8kl0ZPy6T2ycipzz5iNkSg">Scastie (8kl0ZPy6T2ycipzz5iNkSg)</a>.</p><h3>More information about Scala List par</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about Scala List par.</p><p><strong>Compare the output of the two </strong><strong>map. In the first one, you see the numbers in the same order they are in the source </strong><strong>Range. In the second one, the order is random, try running it several times ; you will see the order of the print statements change.</strong></p><p><strong>This happen because all the operation executed in the </strong><strong>map happen at the <em>same</em> time, in parallel.</strong></p><p><strong>Remember the SKB on </strong><strong>Thread.sleep, this was the introduction to the concept of Threads. To allow each operation to happen at the same time, Scala will manage a pool of threads for you. Each operation will be allocated to thread that the computer will compute and then return the result for each operation. Finally, the result will be combined before being returned to you.</strong></p><p><strong>In further SKBs, we are going to learn more about threads in more details. We are going to talk about </strong><strong>Fiber, </strong><strong>Future, </strong><strong>asynchronous and more. Stay tuned!</strong></p><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for Scala List par.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>The next Scala knowledge bit is coming in a few days ! Come back soon to check it out.</p><p>If you are curious about <a href="https://leobenkel.com/2020/09/skb-scala-range/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-list-parallel/"><em>https://leobenkel.com</em></a><em> on September 11, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb3446dab126" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-list-parallel-bb3446dab126">SKB — Scala List parallel</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SKB — Scala Range]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-range-ca43a2ae3fb8?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca43a2ae3fb8</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <category><![CDATA[teaching]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Wed, 09 Sep 2020 17:06:05 GMT</pubDate>
            <atom:updated>2020-10-09T16:03:14.215Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala Range</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*Ju7W53gPvaVnrzRw" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about Scala Range.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about Scala Range !</p><p><strong>I can’t believe we haven’t seen </strong><strong>Range yet !</strong></p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3DTpLSGwr%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2FTpLSGwr%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ead1ebd0dae5c8dfac5e41d3c3b0fca7/href">https://medium.com/media/ead1ebd0dae5c8dfac5e41d3c3b0fca7/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/3mkgQBbsRAKu0Yqo3tzoxA">Scastie (3mkgQBbsRAKu0Yqo3tzoxA)</a>.</p><h3>More information about Scala Range</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about Scala Range.</p><p><strong>Super easy ! Right ? And so useful and powerful.</strong></p><p><strong>Summary of the keywords:</strong></p><ul><li><strong>to: When you do </strong><strong>0 to 3, you will get the numbers </strong><strong>0, 1, 2, 3. Notice that the end boundary is included.</strong></li><li><strong>until: When you do </strong><strong>0 until 3, you will get the numbers </strong><strong>0, 1, 2. Notice that the end boundary is not included.</strong></li><li><strong>by: When you do </strong><strong>0 to 11 by 3, you will get the numbers </strong><strong>0, 3, 6, 9. The default value is </strong><strong>by 1.</strong></li></ul><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for Scala Range.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>Feel free to try on <a href="https://leobenkel.com/2020/09/skb-scala-list-parallel/">the next Scala Knowledege Bit</a>.</p><p>If you are curious about <a href="https://leobenkel.com/2020/09/skb-scala-try/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-range/"><em>https://leobenkel.com</em></a><em> on September 9, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca43a2ae3fb8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-range-ca43a2ae3fb8">SKB — Scala Range</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SKB — Scala Try]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-try-bc763792942d?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc763792942d</guid>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Mon, 07 Sep 2020 17:01:03 GMT</pubDate>
            <atom:updated>2020-10-07T16:01:11.351Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala Try</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*btOn0ArZ1YN2gNew" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about Scala Try.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about Scala Try !</p><p><strong>One thing to know first is the concept of </strong><strong>Exception. An </strong><strong>Exception, in java and Scala, is when an error happen. It will stop the interruption of the program and </strong><strong>throw an </strong><strong>Exception.</strong></p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3Dq8alpes%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2Fq8alpes%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/5013da28c6d66818ae6bd48e4f3ac5be/href">https://medium.com/media/5013da28c6d66818ae6bd48e4f3ac5be/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/qtHKpgWXTeiYGARNzTp6zA">Scastie (qtHKpgWXTeiYGARNzTp6zA)</a>.</p><h3>More information about Scala Try</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about Scala Try.</p><p><strong>The way to manually trigger an </strong><strong>Exception is with </strong><strong>throw. The code will then spit out what is called a <em>stack trace</em>. The stack trace will display each line of code that was in the stack of operation when the </strong><strong>Exception occurred. It is essential to know how to read those when fixing a bug in a software.</strong></p><p><strong>Sometimes, a code will trigger an unexpected error, not one you decide to trigger. For instance, with bad math or more commonly from a third party library like a database connection. The connection might fail or timeout, etc… And then you need to react from the error. Maybe it is a critical error and you will decide to let the program stop its execution. But sometimes, you might be able to recover, in the case of a database, you could retry until it works, or retries several times until it succeed.</strong></p><p><strong>Try is the way to handle </strong><strong>Exception in Scala. It allows you to abstract the potential failure and use the same methods that </strong><strong>Option has to manipulate the data that might or might not be there. But instead of </strong><strong>None when the </strong><strong>Option is empty, you get an </strong><strong>Exception when it is not defined which would carry more information about the kind of failure that was encountered. Like </strong><strong>Option you can use </strong><strong>map, </strong><strong>flatMap, </strong><strong>get, </strong><strong>getOrElse and more.</strong></p><p><strong>Go back to the editor and try to make some code using </strong><strong>map and </strong><strong>flatMap with </strong><strong>Try.</strong></p><p><strong>You might have noticed the </strong><strong>case as well. This is still <em>pattern matching</em>. It is a bit piece of Scala and it is hard to explain, which is why I have been trying to slowly introducing it so when it comes time to dive more into it, you will already have some kind of intuition about it. Patience 🙂</strong></p><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for Scala Try.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>Feel free to try on <a href="https://leobenkel.com/2020/09/skb-scala-range/">the next Scala Knowledege Bit</a>.</p><p>If you are curious about <a href="https://leobenkel.com/2020/09/skb-scala-curry/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-try/"><em>https://leobenkel.com</em></a><em> on September 7, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc763792942d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-try-bc763792942d">SKB — Scala Try</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SKB — Scala Curry]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-curry-b57b05c954d?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/b57b05c954d</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <category><![CDATA[scala]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Fri, 04 Sep 2020 17:03:48 GMT</pubDate>
            <atom:updated>2020-10-05T16:03:08.492Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala Curry</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*6_5fp7xASx_-tiT1" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about Scala Curry.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about Scala Curry !</p><p><strong>No, we are not talking about food here.</strong></p><p><strong>It is just a fancy way to talk about something simple. It describes the transformation of a method that takes several arguments into a series of function that each take one of those arguments. Simple? Try on the exercise.</strong></p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3DcZvYFQ7%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2FcZvYFQ7%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d71383691cc6e2a7bcba764ec6dd51b/href">https://medium.com/media/7d71383691cc6e2a7bcba764ec6dd51b/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/yOTTk60dS4W0xRVsPMejbg">Scastie (yOTTk60dS4W0xRVsPMejbg)</a>.</p><h3>More information about Scala Curry</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about Scala Curry.</p><p><strong>See? Simple. Some coding is worth a thousand words!</strong></p><p><strong>Writing the code that way has a few advantages.</strong></p><p><strong>For instance, you can decompose the function into <em>partially applied functions</em>, like </strong><strong>add2 in the exercise. This example is simple, but imagine a complex function that takes a database connector and/or configurations. You could set those arguments, and then only reuse the <em>partially applied function</em> when needed, I like to call it a pre-configured operation.</strong></p><p><strong>I also like using it for aesthetics, It allows to use </strong><strong>{ }like in </strong><strong>r3 in the exercise.</strong></p><p><strong>And you can have as many arguments chained that way, As well as also combinations, for instance the first block could have 2 arguments and then 1 and then 3 arguments. Use it wisely depending on your needs.</strong></p><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for Scala Curry.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>Feel free to try on <a href="https://leobenkel.com/2020/09/skb-scala-try/">the next Scala Knowledege Bit</a>.</p><p>If you are curious about <a href="https://leobenkel.com/2020/09/skb-scala-flatmap/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-curry/"><em>https://leobenkel.com</em></a><em> on September 4, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b57b05c954d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-curry-b57b05c954d">SKB — Scala Curry</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SKB — Scala flatMap]]></title>
            <link>https://medium.com/scala-knowledge-bits/skb-scala-flatmap-10685b226120?source=rss-d62891d58841------2</link>
            <guid isPermaLink="false">https://medium.com/p/10685b226120</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[scala-knowledge-bits]]></category>
            <dc:creator><![CDATA[Leo Benkel]]></dc:creator>
            <pubDate>Wed, 02 Sep 2020 17:10:15 GMT</pubDate>
            <atom:updated>2020-10-02T16:01:44.276Z</atom:updated>
            <content:encoded><![CDATA[<h3>SKB — Scala flatMap</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*MSzI5FN1k-FkKwWO" /></figure><p>This article is part of the <a href="https://leobenkel.com/category/scala/knowledge-bits">Scala knowledge bits Series</a>.</p><p>Periodically, I will publish new exercises so you can slowly build up knowledge about Scala.</p><p>It is designed to be done in a very short amount of time and learn a little bit each day, just to create a routine.</p><p>This episode will teach you about Scala flatMap.</p><p>Hope you are going to enjoy it! It is designed for anyone to learn Scala from scratch and slowly learn, one Bit at a time.</p><p>After this Bit, I would love to hear your feedback in the comments down below.</p><p>Feel free to join the <strong>Discord server</strong> as well if you would like some help and support from the rest of our community.</p><h3>What are we learning today?</h3><p>Today we are going to learn about Scala flatMap !</p><p><strong>I want to introduce you slowly to more complex problems. This one is still fun, as you know, the main topic is </strong><strong>flatMap but you are going to get an intuition for a little more.</strong></p><p><strong>Enjoy the ride.</strong></p><p>Time to try on the exercise on your own and scroll down for more information when you are done or if you are stuck.</p><h3>Exercise</h3><p>Here is an exercise to complete today.</p><p>If I did my job well, you should be able to guess by yourself the solution based on what you previously learned and based on the clues.</p><p>But if you get stuck, scroll down to get more information.</p><p>The goal of the exercise is to replace the ??? by a piece of code so that the exercise compiles and that&#39;s how you win! Good luck!</p><p>You can fill the exercise right in here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.scalafiddle.io%2Fembed%3Fsfid%3DkLLdQY5%2F0%26passive%26&amp;display_name=ScalaFiddle&amp;url=https%3A%2F%2Fscalafiddle.io%2Fsf%2FkLLdQY5%2F0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=scalafiddle" width="960" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/910e80029d479ca0857fe446be82136f/href">https://medium.com/media/910e80029d479ca0857fe446be82136f/href</a></iframe><p>Or, if it does not load, go on to <a href="https://scastie.scala-lang.org/7hRt7xVTRmujNkv1beZrAQ">Scastie (7hRt7xVTRmujNkv1beZrAQ)</a>.</p><h3>More information about Scala flatMap</h3><p>In this exercise you will learn (or have learned, if you have already solved the puzzle) about Scala flatMap.</p><p><strong>Did you get </strong><strong>flatMap ? It is </strong><strong>map followed by </strong><strong>flatten. Try to replace the </strong><strong>flatMap in the code above by </strong><strong>map and add </strong><strong>flatten after it.</strong></p><p><strong>Ok, now that the topic of today’s episode is done. What is the wizardry with all the </strong><strong>case ?! This is called <em>pattern matching</em>. I am sure that, right now, you have a good intuition about it, but we are going to dive more into it, soon.</strong></p><p><strong>Stay tuned!</strong></p><p>Feel free to go back to the exercise, modify the code to try out new things and get a better intuition for Scala flatMap.</p><h3>Conclusion</h3><p>I hope you have learned something new or had fun during this Scala Knowledge Bit.</p><p>Please ask questions or post feedback in the comments below.</p><p>Feel free to try on <a href="https://leobenkel.com/2020/09/skb-scala-curry/">the next Scala Knowledege Bit</a>.</p><p>If you are curious about <a href="https://leobenkel.com/2020/08/skb-scala-random/">the previous Scala knowledge Bits</a>, go check it out! 🙂</p><p><em>Originally published at </em><a href="https://leobenkel.com/2020/09/skb-scala-flatmap/"><em>https://leobenkel.com</em></a><em> on September 2, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10685b226120" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scala-knowledge-bits/skb-scala-flatmap-10685b226120">SKB — Scala flatMap</a> was originally published in <a href="https://medium.com/scala-knowledge-bits">Scala Knowledge Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>