<?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 Ufuk Halis on Medium]]></title>
        <description><![CDATA[Stories by Ufuk Halis on Medium]]></description>
        <link>https://medium.com/@ufukhalis?source=rss-35cb22082151------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*eMuUk6otd0dTb23HB9jzmw.jpeg</url>
            <title>Stories by Ufuk Halis on Medium</title>
            <link>https://medium.com/@ufukhalis?source=rss-35cb22082151------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 00:58:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ufukhalis/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[Functional Programming Stories: Final Episode — Come Together!]]></title>
            <link>https://medium.com/dev-jam/functional-programming-stories-final-episode-come-together-848212f3bf03?source=rss-35cb22082151------2</link>
            <guid isPermaLink="false">https://medium.com/p/848212f3bf03</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[category-theory]]></category>
            <dc:creator><![CDATA[Ufuk Halis]]></dc:creator>
            <pubDate>Thu, 09 Jan 2025 15:22:55 GMT</pubDate>
            <atom:updated>2025-01-10T10:15:29.451Z</atom:updated>
            <content:encoded><![CDATA[<h3>Functional Programming Stories: Final Episode — Come Together!</h3><p>Yes, this is the <strong>final episode</strong>! I know I didn’t mention it in the previous article, but I thought a little twist would keep things interesting. When I started this series, the plans were different, but sometimes, as with <strong>functional programming</strong>, we pivot based on new insights. I hope this change is as exciting for you as it is for me! 😊</p><p>In this <strong>final episode</strong>, we’ll consolidate the knowledge we’ve built so far by diving into more <strong>FP</strong> terms and <strong>Kotlin</strong> examples. Let’s come together and celebrate what we’ve learned!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LgfNUfAnaYPOodOs" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Pure Functions</h3><p>We’ve talked about <strong>pure functions</strong> before, but let’s revisit them to solidify our understanding. In simple terms, a <strong>pure function</strong> always gives the same output for the same input and has no <strong>side effects</strong>. <strong>Side effects</strong>? They are any changes in the state of your program or its environment that aren’t reflected in the function’s output. Pretty straightforward, right? Let’s look at a <strong>pure function</strong> in action:</p><pre>fun square(x: Int): Int = x * x</pre><p>This function is pure because it:</p><ul><li>Returns the square of x, always producing the same result for the same input.</li><li>Does not modify any <strong>external state</strong>.</li></ul><pre>var counter = 0<br>fun increment(): Int {<br>    counter++<br>    return counter<br>}</pre><p>What about the increment function above? It’s pretty obvious, isn’t it? This function changes the external variable counter, introducing a <strong>side effect</strong>. And that, my friends, is the definition of <strong>impurity</strong>. Another way to think about it? <strong>IMPURE</strong> with all caps—it’s doing something sneaky that makes it less predictable and harder to manage.</p><p><strong>Impure</strong> functions like this can wreak havoc on your program’s state, leading to bugs and confusion. That’s why pure functions are so cherished in functional programming — they keep everything clean and under control.</p><p><strong>Why are pure functions important then?</strong></p><p>Pure functions are predictable, testable, and composable. They are the building blocks of <strong>FP</strong>.</p><p><strong>Relation to Category Theory</strong></p><p>In <strong>category theory</strong>, a <strong>morphism</strong> (function) must map every value in the domain to a single, consistent value in the codomain. <strong>Pure functions</strong> align with this principle as they are deterministic and side-effect-free, embodying the identity rule: for every object, there is a morphism (identity) that maps it to itself without changing it.</p><h3>Higher-Order Functions</h3><p>This one’s important — and likely one you’ve encountered frequently without realizing it! 🙂 A <strong>higher-order</strong> function is a function that:</p><ul><li>Takes one or more functions as parameters,</li><li>Returns a function as its result.</li></ul><pre>fun &lt;T, R&gt; applyFunction(input: T, operation: (T) -&gt; R): R = operation(input)<br><br>val double = { x: Int -&gt; x * 2 }<br>println(applyFunction(5, double)) // Output: 10</pre><p>As you can see from the example above, applyFunction takes a function (operation) and applies it to the input. Now, let me ask you—what are the most popular <strong>higher-order functions</strong> that come to mind? You’ve probably used them in many list, set, or map operations! For example, map and flatMap—yes, they’re both <strong>higher-order functions</strong>!</p><p><strong>Why are higher-order functions important?</strong></p><p>They allow us to abstract over actions and behaviors, promoting code reuse and clarity.</p><p><strong>Relation to Category Theory</strong></p><p><strong>Higher-order</strong> <strong>functions</strong> demonstrate composition by treating functions as first-class citizens. They allow chaining and combining morphisms, adhering to the composition rule: combining multiple transformations into a single one.</p><h3>Immutability</h3><p>Another yet very important concept! You’ve probably heard the term thrown around quite a bit, but maybe didn’t realize just how crucial it is for <strong>functional programming</strong>. Let me tell you — it’s a game-changer. Once you get this idea under your belt, it shifts your perspective on how you write and think about code.</p><p><strong>Immutability</strong> means that once a data structure is created,<strong> it cannot be modified</strong>. Instead, any updates create a new instance with the updated data.</p><pre>data class Person(val name: String, val age: Int)<br><br>val person = Person(&quot;Alice&quot;, 30)<br>val olderPerson = person.copy(age = person.age + 1)<br>println(olderPerson) // Output: Person(name=Alice, age=31)</pre><p>See how easy <strong>Kotlin</strong> makes it to work with <strong>immutable</strong> objects? The copy method allows us to create a new instance with modified data while keeping the original untouched. Here, person remains the same, and olderPerson is a brand-new object with an updated age. No overwriting, no shared state—just clean, predictable behavior.</p><p><strong>Why is immutability important?</strong></p><p><strong>Immutability</strong> eliminates shared mutable state, making programs easier to reason about and debug, especially in concurrent environments.</p><p><strong>Relation to Category Theory</strong></p><p><strong>Immutability</strong> ensures that objects (categories) retain their identity and states do not change, aligning with the identity morphism principle.</p><h3>Referential Transparency</h3><p>Let’s start with a simple explanation for this one! 🙂</p><p>A piece of code is <strong>referentially transparent</strong> if it can be replaced with its result without affecting the program’s behavior. Sounds a bit abstract, right? Don’t worry — let’s look at an example to make it clearer!</p><pre>val result = square(4) // Always 16</pre><p>The expression square(4) can be replaced with 16 without affecting the program. So, it is very clear, right?</p><p>Then another example that breaks this one</p><pre>fun randomValue(): Int = (1..10).random()<br>println(randomValue())</pre><p>This is not referentially transparent because calling randomValue() multiple times can produce different results. Simple!</p><p><strong>Why is referential transparency important?</strong></p><p>It enables reasoning about code and supports optimizations like memoization.</p><p><strong>Relation to Category Theory</strong></p><p><strong>Referential transparency</strong> ensures morphisms consistently map inputs to outputs, reinforcing the concept of deterministic mappings in category theory and supporting associativity in transformations.</p><h3>Function Composition</h3><p>This is one of my favorite concepts! <strong>Function composition</strong> is all about combining two or more functions to create a new one, enabling cleaner and more modular code.</p><p>In <strong>Kotlin</strong>, you won’t find predefined functions like applyThen or compose to make function composition straightforward. But don’t worry—<strong>Kotlin</strong> gives us the flexibility to create our own function composition, tailored to our needs.</p><pre>val triple = { x: Int -&gt; x * 3 }<br>val squareThenTriple = triple compose ::square<br>println(squareThenTriple(2)) // Output: 12<br><br>infix fun &lt;P, Q, R&gt; ((P) -&gt; Q).compose(other: (R) -&gt; P): (R) -&gt; Q = {<br>    this(other(it))<br>}</pre><p><strong>Why is function composition important?</strong></p><p>It promotes modularity and reuse by combining smaller functions into larger ones.</p><p><strong>Relation to Category Theory</strong></p><p><strong>Function composition</strong> mirrors the composition rule in <strong>category theory</strong>. <strong>Associativity</strong> ensures that the order of grouping operations does not affect the result.</p><h3>Recursion</h3><p>You probably already know this — I know! But let’s take a moment to explain it anyway, just to keep things in order. <strong>Recursion</strong> happens when a function calls itself to solve a problem. It’s a powerful technique that helps break down complex tasks into simpler, more manageable ones, often leading to elegant solutions.</p><pre>fun factorial(n: Int): Int = if (n &lt;= 1) 1 else n * factorial(n - 1)<br>println(factorial(5)) // Output: 120</pre><p><strong>Why is recursion important?</strong></p><p>It enables elegant solutions to problems that can be broken into smaller subproblems.</p><p><strong>Relation to Category Theory</strong></p><p><strong>Recursion</strong> aligns with compositionality, as each recursive step represents a smaller morphism that contributes to the larger transformation.</p><h3>Currying</h3><p><strong>Currying</strong> is such an interesting concept! At its core, currying transforms a function that takes multiple parameters into a series of functions, where each one accepts a single parameter. It’s a powerful way to break down complex functions into smaller, more manageable ones, making them more reusable and easier to work with.</p><pre>fun add(x: Int) = { y: Int -&gt; x + y }<br>val addFive = add(5)<br>println(addFive(10)) // Output: 15</pre><p><strong>Why is currying important?</strong></p><p>It simplifies function composition and partial application.</p><p><strong>Relation to Category Theory</strong></p><p><strong>Currying</strong> represents breaking down complex morphisms into simpler, composable transformations. It adheres to associativity as each curried function builds upon the previous one in a consistent order.</p><h3>Lazy Evaluation</h3><p>Finally, we come to <strong>lazy</strong> <strong>evaluation</strong>. This concept delays the computation of a value until it’s actually needed, which can significantly improve performance. It also opens the door to working with infinite data structures, as values are only computed on demand.</p><pre>val lazyValue: Int by lazy {<br>    println(&quot;Computing...&quot;)<br>    42<br>}<br>println(lazyValue) // Triggers computation<br>println(lazyValue) // Uses cached value</pre><p><strong>Why is lazy evaluation important?</strong></p><p>It avoids unnecessary computations and supports modularity.</p><h3>Conclusion</h3><p>And here we are, at the end! We’ve finally swum in the vast sea of <strong>Functional Programming</strong> (FP). If you’ve made it this far, it means you didn’t drown in the depths of complexity! 😄 I know, writing about <strong>FP</strong> and understanding its concepts hasn’t been the easiest, and this series certainly wasn’t exhaustive. You might need a whole book to dive deeper into it! But hey, we’ve covered a lot of ground, and now you can comfortably discuss many of these terms. This could just be the beginning of your <strong>FP</strong> journey if you’re eager to explore more. So, with that, here comes the “<strong>Where to Go Next?</strong>” section!</p><h3><strong>Where to Go Next?</strong></h3><ul><li><strong>Practice</strong>: The best way to get better at <strong>FP</strong> is to incorporate its principles into your daily coding. Pick one concept, like immutability, and really focus on applying it consistently.</li><li><strong>Learn More</strong>: Once you’re comfortable, dive into more advanced <strong>FP</strong> concepts like <strong>monads</strong>, <strong>functors</strong>, and <strong>applicatives</strong>. These ideas can take your understanding of <strong>FP</strong> to a whole new level.</li><li><strong>Study Category Theory</strong>: If you’re ready to get into the deeper, mathematical side of <strong>FP</strong>, category theory is where the magic happens. “<strong>Category Theory for Programmers</strong>” by <strong>Bartosz Milewski</strong> is a fantastic resource to start with.</li><li><strong>Experiment</strong>: <strong>FP</strong> isn’t just for <strong>Kotlin</strong>. Explore other languages that embrace <strong>FP</strong>, such as <strong>Haskell</strong>, <strong>Scala, </strong>etc. Each language offers its own unique take on functional programming.</li></ul><p>Remember, <strong>functional programming</strong> is a journey, not a destination. With every step, you’ll uncover new ways to write elegant, expressive, and efficient code. Thank you for following along in this series! Let’s keep learning, experimenting, and growing as developers.</p><ul><li><a href="https://medium.com/dev-jam/functional-programming-stories-episode-1-what-is-it-about-b2b45134539c?source=collection_detail----b2189b08e11e-----6-----------------------">Functional Programming Stories: Episode 1 — What is it about?</a></li><li><a href="https://medium.com/dev-jam/functional-programming-stories-episode-2-category-theory-d1cc04d769d1?source=collection_detail----b2189b08e11e-----1-----------------------">Functional Programming Stories: Episode 2 — Category Theory</a></li><li><a href="https://medium.com/dev-jam/functional-programming-stories-final-episode-come-together-848212f3bf03?source=collection_detail----b2189b08e11e-----0-----------------------">Functional Programming Stories: Final Episode — Come Together!</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=848212f3bf03" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dev-jam/functional-programming-stories-final-episode-come-together-848212f3bf03">Functional Programming Stories: Final Episode — Come Together!</a> was originally published in <a href="https://medium.com/dev-jam">Devjam</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functional Programming Stories: Episode 2— Category Theory]]></title>
            <link>https://medium.com/dev-jam/functional-programming-stories-episode-2-category-theory-d1cc04d769d1?source=rss-35cb22082151------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1cc04d769d1</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[category-theory]]></category>
            <category><![CDATA[function]]></category>
            <dc:creator><![CDATA[Ufuk Halis]]></dc:creator>
            <pubDate>Thu, 09 Jan 2025 15:22:52 GMT</pubDate>
            <atom:updated>2025-01-10T10:15:16.611Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous episode, we dipped our toes into the sea of <strong>Functional Programming</strong> — just enough to get a little wet, but nothing too overwhelming, right? We explored some <strong>terms</strong>, <strong>paradigms</strong>, and even came up with a definition for <strong>Functional Programming</strong>.</p><p>Before we dive deeper with more concrete definitions and examples, we need to take a few more steps into the water to prepare ourselves for the plunge. That’s why, in this episode, we’ll focus on more abstract concepts to set the stage for what’s to come.</p><p>It’s time for <strong>Category Theory!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dEJjutWAGeDoMq-z" /><figcaption>Photo by <a href="https://unsplash.com/@thisisengineering?utm_source=medium&amp;utm_medium=referral">ThisisEngineering</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>What is a Function?</strong></h3><p>You thought I’d jump straight into explaining <strong>Category Theory</strong>, didn’t you? No, no — not yet! We need to lay the groundwork first. Let’s start with the basics.</p><p>In programming, we often refer to <strong><em>functions</em> </strong>or <strong><em>methods</em></strong>. Their names and conventions might vary depending on the programming language, but we always understand their purpose. However, <strong>functions</strong> aren’t just limited to <strong>programming</strong> — they also exist in <strong>mathematics</strong>, and you’re probably already familiar with them! 😊</p><p>In <strong>mathematics</strong>, a function describes how to calculate an output given an input value. Take a look at the figure below — it’s a <strong>mathematical representation of a function</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-t0rN_yDCDR3tWZbJjOlkg.png" /></figure><p>Let’s look at a more concrete example:</p><pre>fun twice(x: Int) = 2 * x</pre><p>In the context of <strong>Functional Programming</strong>, a function is something more <strong>abstract</strong> — it’s not necessarily tied to computation. Instead, <strong>a function is a way to map values from one set to another</strong>.</p><p>The set of all values a function can accept as input is called its <strong>domain</strong>, while the set of all values it can return as output is called its <strong>range</strong>. Interestingly, the <strong>domain</strong> and <strong>range</strong> can be the same set of values.</p><p>To visualize this concept more clearly, take a look at the figure below — it provides a better representation of what a <strong>function</strong> truly is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K2t1Pz9VDJMO2ip5zn655A.png" /></figure><ul><li>For every value in the <strong>domain</strong>, there is exactly one corresponding value in the <strong>range</strong>.</li><li>A function can map multiple values from the <strong>domain</strong> to the same value in the <strong>range</strong>.</li><li>By definition, a <strong>function</strong> must have meaning for every value in its <strong>domain</strong>.</li></ul><p>And now, let’s dive into the real topic!</p><h3><strong>Category Theory</strong></h3><p><strong>Category Theory</strong> is one of the most <strong>abstract</strong> branches of mathematics, and it plays a crucial role here because programming is one of its primary applications. To understand it better, we should start with the definition of a <strong>category</strong>.</p><p>A category consists of a collection of objects and connections between them, called <strong>morphisms</strong>. Categories adhere to three fundamental rules:</p><ol><li><strong>Composition</strong></li><li><strong>Associativity</strong></li><li><strong>Identity</strong></li></ol><p>You can imagine an object as a dot with no inherent properties and no way to break it down further. A <strong>morphism</strong>, on the other hand, is represented as an arrow connecting two objects — like in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9X9J2bYdk9bbKLc1UIqpXA.png" /></figure><ul><li>Have <strong>objects</strong> named <strong>a</strong> , <strong>b</strong> and <strong>c</strong> .</li><li>Define two <strong>morphisms</strong> between <strong>a</strong> and <strong>b</strong>, and one <strong>morphism</strong> between <strong>b</strong> and <strong>c</strong>.</li><li>The <strong>morphisms</strong> between <strong>a</strong> and <strong>b</strong> are named <strong>f₁</strong> and <strong>f₂</strong>, while the <strong>morphism</strong> between <strong>b</strong> and <strong>c</strong> is named <strong>g</strong>.</li></ul><p><strong>Objects</strong> and <strong>morphisms</strong> are the foundational tools used to describe every concept in <strong>Category Theory</strong>. However, they must adhere to certain rules, which pave the way to other fundamental <strong>Functional Programming</strong> concepts.</p><p>Let’s explore those rules now!</p><h3><strong>Composition</strong></h3><p>A collection of objects and arrows alone doesn’t form a category — they must also follow some important rules, with <strong>composition</strong> being arguably the most significant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T7oMnG4wDe-HDPsypCMA_g.png" /></figure><ul><li>The objects <strong>a</strong> , <strong>b</strong> and <strong>c</strong>.</li><li>The <strong>morphism</strong> <strong>f</strong> from <strong>a</strong> to <strong>b</strong>.</li><li>The <strong>morphism</strong> <strong>g</strong> from <strong>b</strong> to <strong>c</strong>.</li></ul><p>The <strong>composition rule</strong> states that for any objects <strong>a</strong>, <strong>b</strong>, and <strong>c</strong>, and for any morphisms <strong>f</strong> and <strong>g</strong> (as shown in the figure above), the <strong>category</strong> must include a <strong>morphism</strong> from <strong>a</strong> to <strong>c</strong>. This <strong>morphism</strong> is represented as <strong>g◦f</strong>, which is the <strong>composition</strong> of <strong>f</strong> and <strong>g</strong>.</p><p>You read <strong>g◦f</strong> as “g after f,” where the small circle <strong>◦</strong> symbolizes composition.</p><p>For a <strong>Kotlin</strong> example, if <strong>f</strong> is a function that doubles a number (twice) and <strong>g</strong> triples it (triple), then <strong>g◦f</strong> could be written as:</p><pre>val `g◦f`: ( Int ) -&gt; Int = { triple(twice(it)) }</pre><h3><strong>Associativity</strong></h3><p>The <strong>associativity rule</strong> is similar to the one you learned back in school regarding addition or multiplication. Take a look at the following image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qouV7wi5yp8dhG5QErWd1w.png" /></figure><ul><li>The <strong>objects</strong> <strong>a</strong>,<strong> b</strong>, <strong>c</strong> and <strong>d</strong>.</li><li>The <strong>morphism</strong> <strong>f</strong> from a to <strong>b</strong>.</li><li>The <strong>morphism</strong> <strong>g</strong> from b to <strong>c</strong>.</li><li>The <strong>morphism</strong> <strong>h</strong> from <strong>c</strong> to <strong>d</strong>.</li></ul><p>The <strong>associativity rule</strong> states that for every <strong>object</strong> <strong>a</strong>, <strong>b</strong>, <strong>c</strong>, and <strong>d</strong>, and for every <strong>morphism</strong> <strong>f</strong>, <strong>g</strong>, and <strong>h</strong>, the following equivalence must hold:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*UOral6_cxLDVitdgPMV39w.png" /></figure><p>This means that when composing <strong>f</strong>, <strong>g</strong>, and <strong>h</strong>, it doesn’t matter whether you first compose <strong>f</strong> with <strong>g</strong> or <strong>g</strong> with <strong>h</strong>. In other words, with those <strong>objects</strong> and <strong>morphisms</strong>, there must be a <strong>morphism</strong> from <strong>a</strong> to <strong>d</strong>, which you can obtain by either composing <strong>f</strong> with <strong>h◦g</strong> or composing <strong>g◦f</strong> with <strong>h</strong>.</p><p>Continuing with the previous example and quadrupling <strong>h</strong>, this means:</p><pre>twice(triple(quadruple(x))) == quadruple(twice(triple(x)))</pre><h3><strong>Identity</strong></h3><p>The <strong>identity rule</strong> is the last rule, but it’s no less important than the other two. Consider the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yV0nFmAHaEpokCv49j1sPg.png" /></figure><p>The <strong>identity property</strong> states that every object in a category must have at least one morphism to itself. This is why, in the figure above, we have:</p><ul><li>The <strong>objects</strong> <strong>a</strong> and <strong>b</strong></li><li>A <strong>morphism</strong> <strong>f</strong> from <strong>a</strong> to <strong>b</strong></li><li>A <strong>morphism</strong> <strong>iₐ</strong> from <strong>a</strong> to itself</li><li>A <strong>morphism</strong> <strong>iᵦ</strong> from <strong>b</strong> to itself</li></ul><p>This must hold true for all objects in the category.</p><h3>Conclusion</h3><p>Well, we’ve come a long way, haven’t we? We started by dipping our toes into the abstract world of <strong>Category Theory</strong>, looking at some fundamental concepts like <strong>composition</strong>, <strong>associativity</strong>, and <strong>identity</strong>. While these ideas might seem a bit theoretical at first glance, they’re actually the backbone of <strong>Functional Programming (FP)</strong> — and they can make a huge difference in how we approach writing clean, maintainable code.</p><p>In FP, we think of <strong>functions</strong> as the core building blocks. These are the objects in our <strong>Category Theory</strong> framework, and the relationships between them — like <strong>function composition</strong> — are the <strong>morphisms</strong>. Just like how two morphisms can be combined to form a new one in <strong>Category Theory</strong>, we compose functions in FP to create more complex behavior.</p><p>Let’s look at <strong>composition</strong> again. In <strong>Category Theory</strong>, when we compose two morphisms, we end up with a new one. The same thing happens when we compose functions in <strong>FP</strong>. For example, if we have two functions, <strong>f(x) = x * 2</strong> and <strong>g(x) = x + 3</strong>, we can combine them into a new function <strong>g◦f(x)</strong>, which is “g after f”:</p><pre>val f: (Int) -&gt; Int = { it * 2 }<br>val g: (Int) -&gt; Int = { it + 3 }<br>val g◦f: (Int) -&gt; Int = { g(f(it)) }</pre><p>The result is a new function that multiplies the input by 2 and then adds 3. This is a simple example of how composition works in both <strong>Category Theory</strong> and <strong>FP</strong>.</p><p>Then, we saw how the <strong>associativity</strong> rule plays out. When you have three functions to compose, it doesn’t matter how you group them — if you first combine <strong>f</strong> and <strong>g</strong>, and then compose with <strong>h</strong>, or if you first combine <strong>g</strong> and <strong>h</strong>, and then with <strong>f</strong>, the result will always be the same:</p><pre>val h: (Int) -&gt; Int = { it - 1 }<br>val g◦f◦h = { f(g(h(it)))) }<br>val f◦(g◦h) = { f(g(h(it)))) }</pre><p>Both compositions give you the same outcome, which is the beauty of associativity — no matter how you group the functions, the result is guaranteed to be the same.</p><p>Finally, the <strong>identity</strong> rule is all about consistency. In <strong>FP</strong>, <strong>pure functions</strong> are a great example of this. A pure function is one that always gives the same output for the same input, without any side effects — just like an identity morphism in <strong>Category Theory</strong>. For example:</p><pre>val id: (Int) -&gt; Int = { it }</pre><p>Here, <strong>id</strong> is a function that simply returns the value it’s given, just like an identity morphism. It’s predictable, safe, and easy to test — key qualities in building reliable software.</p><p>These fundamental rules from <strong>Category Theory</strong> help us think about how we compose and structure our code in <strong>Functional Programming</strong>. By following these principles — composition, associativity, and identity — we’re able to create programs that are modular, readable, and maintainable.</p><p>And with that, we’ve wrapped up the theory behind how <strong>Category Theory</strong> lays the groundwork for <strong>Functional Programming</strong>. But this is just the beginning! In the next article, we’ll dive into some more hands-on concepts in FP, like <strong>higher-order functions</strong>, <strong>pure functions, </strong>and other FP terms, and how these ideas really come to life in code. We’ll explore examples and see how they tie back to the concepts we’ve just covered.</p><p>I hope this journey so far has sparked your curiosity about how abstract ideas like <strong>Category Theory</strong> can shape the way we write software. Stay tuned for the next article — I can’t wait to dive deeper into the world of <strong>Functional Programming</strong> with you!</p><p>Images and some examples in this article are referenced from <em>Functional Programming in Kotlin by Tutorials</em> by Massimo Carli.</p><ul><li><a href="https://medium.com/dev-jam/functional-programming-stories-episode-1-what-is-it-about-b2b45134539c?source=collection_detail----b2189b08e11e-----6-----------------------">Functional Programming Stories: Episode 1 — What is it about?</a></li><li><a href="https://medium.com/dev-jam/functional-programming-stories-episode-2-category-theory-d1cc04d769d1?source=collection_detail----b2189b08e11e-----1-----------------------">Functional Programming Stories: Episode 2 — Category Theory</a></li><li><a href="https://medium.com/dev-jam/functional-programming-stories-final-episode-come-together-848212f3bf03?source=collection_detail----b2189b08e11e-----0-----------------------">Functional Programming Stories: Final Episode — Come Together!</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1cc04d769d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dev-jam/functional-programming-stories-episode-2-category-theory-d1cc04d769d1">Functional Programming Stories: Episode 2— Category Theory</a> was originally published in <a href="https://medium.com/dev-jam">Devjam</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functional Programming Stories: Episode 1 — What is it about?]]></title>
            <link>https://medium.com/dev-jam/functional-programming-stories-episode-1-what-is-it-about-b2b45134539c?source=rss-35cb22082151------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2b45134539c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[declarative-programming]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Ufuk Halis]]></dc:creator>
            <pubDate>Mon, 09 Dec 2024 08:35:02 GMT</pubDate>
            <atom:updated>2025-01-10T10:14:44.956Z</atom:updated>
            <content:encoded><![CDATA[<h3>Functional Programming Stories: Episode 1 — What is it about?</h3><p>Writing about this topic has been on my mind for quite some time (I mean it — maybe a couple of years!). But now, it’s finally happening. Together, we’ll dive into the vast sea of <strong>functional programming</strong>, exploring its depths step by step. Let’s see if we can make it to the end of this series unscathed! One thing is certain: we’ll learn a lot along the way and uncover insights hidden in the shadows.</p><blockquote>Note: <strong>Kotlin</strong> will be our main language for these series of the articles.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kwcsltfpxz3OMP2S" /><figcaption>Photo by <a href="https://unsplash.com/@louis993546?utm_source=medium&amp;utm_medium=referral">Louis Tsai</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>First Sight!</h3><p>Before diving into the main story, I want to share my personal journey with <strong>Functional Programming(FP)</strong>. It all began in 2017 when I joined a mid-sized company. (By the way, it was there that I learned a lot about various topics like microservices, distributed systems, NoSQL databases, Cloud computing, and more.) At the time, I was your typical Java developer, comfortably working within the <strong>object-oriented paradigm</strong>.</p><p>Then came my first PR. (For context, Scala was the primary language at this company.) My initial code was written in a very <strong>imperative</strong> style. After the PR review (which came with plenty of comments! 😊), a colleague sat down with me for a session to refactor the code using a functional approach — focusing on <strong>pure functions</strong>, <strong>immutability</strong>, and a more <strong>declarative</strong> style. That was my first encounter with a whole new world of concepts and terms from <strong>Functional Programming</strong>. 😊</p><h3>Episode 1: What is it about?</h3><p>In the section above, I bolded a few words because we’ll touch on them later. 😉</p><p>When most of us first start learning a programming language (whether by ourselves, in university, or elsewhere), we focus on telling the language <strong><em>how</em> to</strong> accomplish a goal. This approach — focused on the <strong><em>how</em></strong> — is known as the <strong>imperative paradigm</strong>. 😊</p><p>To illustrate, here’s some <strong>Java</strong> code that finds numbers between 0 and 100 divisible by 3. It’s an example of<strong> imperative programming</strong> because we explicitly tell the language how to do that:</p><ul><li>Create a for loop that iterates from 0 to 100.</li><li>Check if the number is divisible by 3.</li><li>If the remainder is 0, add it to the list; otherwise, skip it.</li></ul><pre>var numbersCanBeDividedByThree = ArrayList&lt;Integer&gt;();<br>for(int i=0; i &lt; 100; i++) {<br>  if (i % 3 == 0) {<br>    numbersCanBeDividedByThree.add(i);<br>  }<br>}</pre><p>Wouldn’t it be easier and more readable if we simply told our programming language <strong><em>what</em> to do</strong>? Of course!</p><pre>(0..100)<br>  .filter { it % 3 == 0 }<br>  .forEach { println(it) }</pre><ul><li>Between 0 to 100.</li><li>Filter the numbers that can be divided by 3.</li><li>Write the number to the console.</li></ul><p>As you can see, from a readability perspective, we’ve made significant improvements — it’s much closer to how we naturally communicate as humans. Now, imagine having multiple operations to apply. It becomes even clearer why the second approach remains superior to the first. This, my friends, is the <strong>declarative way</strong>!</p><p>We haven’t yet talked about what <strong>Functional Programming</strong> really is — but don’t worry, we’ll get there soon. For now, know that being<strong> declarative</strong> is one of its core principles. :)</p><p>We’ve also mentioned the <strong>object-oriented paradigm</strong>, so it’s worth noting that <strong>Functional Programming</strong> is another paradigm. While the<strong> object-oriented paradigm</strong> revolves around principles like encapsulation, inheritance, polymorphism, and abstraction, <strong>FP</strong> is built on key principles such as <strong>immutability</strong>, <strong>referential transparency</strong>, <strong>higher-order functions</strong>, and <strong>recursion.</strong> (These are crucial concepts in <strong>FP</strong>, and we’ll explore them in detail later in this series!)</p><p>There are two more bold terms we’ll touch on before we’re ready to officially define <strong>Functional Programming</strong>.</p><p>The first is <strong>pure functions</strong>. A <strong>pure function</strong> produces an output that depends solely on its input. This means it will always return the same output for the same input, no matter how many times it’s called, and it has no <strong>side effects</strong>. Let’s elaborate on <strong><em>side effects</em></strong>: they occur when a function modifies something outside its scope, such as global variables, files, or databases. Since pure functions avoid side effects, they’re incredibly reliable and can be called repeatedly without impacting the software’s overall state. 😊</p><p>The second term is <strong>immutability</strong>. This simply means that once data is created, it cannot be changed. Instead, any updates result in new versions of the data. Thanks to <strong>immutability</strong>, FP is inherently <strong>parallel-friendly</strong>, making it <strong>easier to test</strong>, <strong>debug</strong>, and <strong>scale</strong>. And that’s just the beginning — there’s a long list of benefits! 😄</p><p>Before you start squeezing your cheeks (like the girl in the image below 😄) after such an introduction to make an official definition of <strong>FP</strong>, let me share one with you. Then, we can finally wrap up this part — hopefully! 😊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aJ_kqrypGSmNteYz" /><figcaption>Photo by <a href="https://unsplash.com/@henrikkedue?utm_source=medium&amp;utm_medium=referral">Henrikke Due</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Functional Programming</strong> is a programming paradigm centered around treating computation as the evaluation of <strong>mathematical functions</strong> and avoiding changing state or mutable data. It emphasizes declarative programming, where the focus is on <em>what to solve</em> rather than <em>how to solve it</em>.</p><p>I hope I’ve given you a clear description of <strong>FP</strong> that ties into the concepts we touched on in the introduction. :) But before we dive into terms like <strong>higher-order functions</strong>, <strong>recursion</strong>, <strong>immutability</strong>, and so on (you remember, right?), I’d like to take a different direction. The second article in this series will explore how <strong>FP</strong> relates to mathematical functions — specifically, <strong>CATEGORY THEORY</strong>!</p><p>And that’s a wrap for the first episode — not a goodbye, and definitely not a season finale!</p><ul><li><a href="https://medium.com/dev-jam/functional-programming-stories-episode-1-what-is-it-about-b2b45134539c?source=collection_detail----b2189b08e11e-----6-----------------------">Functional Programming Stories: Episode 1 — What is it about?</a></li><li><a href="https://medium.com/dev-jam/functional-programming-stories-episode-2-category-theory-d1cc04d769d1?source=collection_detail----b2189b08e11e-----1-----------------------">Functional Programming Stories: Episode 2 — Category Theory</a></li><li><a href="https://medium.com/dev-jam/functional-programming-stories-final-episode-come-together-848212f3bf03?source=collection_detail----b2189b08e11e-----0-----------------------">Functional Programming Stories: Final Episode — Come Together!</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2b45134539c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dev-jam/functional-programming-stories-episode-1-what-is-it-about-b2b45134539c">Functional Programming Stories: Episode 1 — What is it about?</a> was originally published in <a href="https://medium.com/dev-jam">Devjam</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Discovering MicroK8s: A Lightweight Journey into Kubernetes]]></title>
            <link>https://medium.com/dev-jam/discovering-microk8s-a-lightweight-journey-into-kubernetes-78bff16fe816?source=rss-35cb22082151------2</link>
            <guid isPermaLink="false">https://medium.com/p/78bff16fe816</guid>
            <category><![CDATA[minikube]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[microk8s]]></category>
            <dc:creator><![CDATA[Ufuk Halis]]></dc:creator>
            <pubDate>Mon, 25 Nov 2024 10:13:11 GMT</pubDate>
            <atom:updated>2024-11-25T10:13:11.520Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I was working on a side hustle and needed to deploy my services to a <strong>container orchestration tool</strong>. With so many options out there, I thought about using <strong>Kubernetes</strong> — it’s all the rage these days, after all! But in my past experiences, I’ve spent way too much time setting up <strong>Kubernetes</strong> clusters, which can be a bit of a headache.</p><p>For my current plans, I didn’t need anything fancy; a local setup would do just fine. The obvious choice was <strong>Minikube</strong>, which works great for local <strong>Kubernetes</strong> setups. But this time, I wanted to try something new! Since I’ve already used <strong>Minikube</strong> before, I figured this was a perfect chance to explore other tools and see what’s out there.</p><p>This quote always inspires me to think outside the box:</p><blockquote><em>“For certain, you have to be lost to find a place as can’t be found. Elseways, everyone would know where it was.”<br>― Hector Barbossa</em></blockquote><p>So, I dived on the internet sea… and land ho! : the microk8s. (Of course, I know that I’m not the only one but this way is more fun!)</p><figure><img alt="microk8s.io" src="https://cdn-images-1.medium.com/proxy/1*khIGfLdFvVcaJWdrQ4H3eg.png" /></figure><p>In this article, I’ll share a few thoughts about <strong>MicroK8s</strong> — and yes, this will involve some good old keyboard action! 😊</p><p>Let’s start by quickly answering the big question: <em>“</em><strong><em>What is MicroK8s?</em></strong><em>”</em> According to their official website, here’s the scoop:</p><blockquote><em>The </em><strong><em>lightweight</em></strong><em> Kubernetes. Zero-ops, pure-upstream Kubernetes, from developer workstations to production.</em></blockquote><p>I’ve highlighted one word from the explanation above — sharp-eyed readers might have spotted it right away. 😉 The word is <strong>lightweight</strong>. It instantly caught my attention and stuck in my mind, almost like it cast a little spell on me!</p><p>Of course, the rest of the description is packed with other great terms like <em>zero-ops</em> and <em>from developer workstations to production</em>. But let’s be honest, <strong>lightweight</strong> was love at first sight!</p><p>I highly recommend checking out their website: <a href="https://microk8s.io/"><strong>https://microk8s.io/</strong></a>. It’s packed with fantastic details, resources, tutorials, and more. If you enjoy diving into some good reading material, there’s plenty to explore!</p><p>Now, let me share another charming detail from their site:</p><blockquote><strong><em>Hassle-free Kubernetes.</em></strong></blockquote><blockquote><em>The simplest way to get </em><strong><em>K8s</em></strong><em> anywhere.</em></blockquote><blockquote><strong><em>ARM</em></strong><em> or </em><strong><em>Intel</em></strong><em>. Under the cell tower. On </em><strong><em>Raspberry Pis</em></strong><em>. On clouds or everyday appliances. </em><strong><em>MicroK8s</em></strong><em> delivers the full </em><strong><em>Kubernetes</em></strong><em> experience with a single command. Install. Cluster. Enable the services you need. No hassle.</em></blockquote><blockquote><em>A fully isolated deployment package protects your underlying system. Self-healing high-availability and over-the-air updates for ultra-reliable operations.</em></blockquote><blockquote><strong><em>MicroK8s</em></strong><em> architecture and </em><strong><em>OS</em></strong><em> compatibility allows you to deploy on </em><strong><em>COTS</em></strong><em> hardware and develop on any workstation.</em></blockquote><p>This is exactly what I wanted! I didn’t want to spend hours just getting <strong>Kubernetes</strong> up and running locally — I needed something quick and ready to go. My goal was simple: deploy a few services I created, along with <strong>Kafka</strong>, <strong>Mongo</strong>, and a few other tools.</p><p>In short, <strong>MicroK8s</strong> fit perfectly into my plan, and that’s why I’m writing this article — to showcase what it can do!</p><p>Here’s the basic scenario we’ll be working with:</p><ol><li>Install and run microk8s locally.</li><li>Deploy a simple <strong>spring boot application</strong>.</li></ol><p>First things first — we need to install <strong>MicroK8s</strong>. I ran everything on my <strong>MacBook</strong>, so the commands I’ll share will be specific to <strong>macOS</strong>. But don’t worry! Their website has installation instructions for other systems like <strong>Windows</strong> and <strong>Linux</strong> as well. You’ll be covered no matter what you’re using!</p><h3>This may take some time, be patient!</h3><pre>brew install ubuntu/microk8s/microk8s<br>microk8s install</pre><p>Then check the status;</p><pre>microk8s status - wait-ready</pre><p>If you see any errors on your console, try to use start and stop commands. I kinda had some errors, and stopping then starting microk8s worked.</p><pre>microk8s stop  <br>microk8s start</pre><p>Once you do not see any errors, you can enable some add-ons.</p><pre>microk8s enable dashboard dns registry istio</pre><p>Since we enabled the dashboard add-on, we can run the below one to get access to the dashboard.</p><pre>microk8s dashboard-proxy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*NIkNIjgwGKZXnddCC9CNAQ.png" /></figure><p>This will have an output with an access token and also the dashboard<strong> URL</strong>, so you can use them to access the dashboard. If you can reach that, I would say congrats! You have <strong>k8s</strong> which is available in your local!</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*3xn5Q9PMddpDGSEl05AHaQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*HnTKRaHMD9EM2DBi2raAcw.png" /></figure><p>Now it’s time to deploy an application to <strong>MicroK8s</strong>! I didn’t create a sample application for this because I already have a set of applications ready to go (remember the <em>plan</em> I mentioned earlier? 😉).</p><p>You can check out the project here: <a href="https://github.com/ufukhalis/product-alert-system"><strong>Product Alert System</strong></a><strong>.</strong></p><p>Of course, we’re not deploying the entire system I created (although you could — it’s pretty straightforward; just follow the <strong>README</strong>! 😊). Instead, we’ll deploy one service and <strong>MongoDB</strong> from the project. Specifically, we’ll deploy the user-subscriber-service application, which is already pushed to the public Docker registry under the ufukhalis namespace (feel free to dive into the code if you’re curious!).</p><p>For MongoDB, we’ll use a deployment file named mongo-deployment.yml to handle everything.</p><p>After you cloned that project, you can run the below command at the root of the project:</p><pre>microk8s kubectl create -f mongo-deployment.yml</pre><p>Once it is executed, you can check the status of the pods from the dashboard. Everything must be green! Then, we need to deploy our user-subscriber-service .</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*-CuqvyjMujL3-VPzDP_fOw.png" /></figure><h3>go to user-subscriber-service folder</h3><pre>cd user-subscriber-service  <br>microk8s kubectl create -f deployment.yml</pre><p>You can check the pods again and also the logs if the application is working or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*3MPlGAZJasNsatOPFYAAng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*ZTnWQncpwWDPhV0f-5rQ0A.png" /></figure><blockquote><em>Note: I didn’t give any details of the </em><em>_deployment.yml_ files. Because they are not the purpose of this article. But, basically, they contain a set of instructions that </em><strong><em>k8s</em></strong><em> will use to deploy your applications.</em></blockquote><p>Since that application has <strong>Swagger</strong> integration, we can access its <strong>Swagger</strong> interface to interact with its exposed <strong>API</strong>. To do that, we need the dashboard <strong>IP address</strong> and <strong>port number</strong>.</p><p>To have a <strong>port number</strong>;<br>Go to the Replica Sets and enter the user-subscriber-service-app. And there is Internal Endpoints section that contains two values. So, we need the port number from the second one. And replace the values in the below URL;</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*qYReR44LBOszgGG1TodThQ.png" /></figure><pre>http://{IP_ADDRESS_DASHBOARD}:{PORT_NUMBER}/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config#/user-subscriber-controller</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*chzYOewXKSBbMU7CumOlYQ.png" /></figure><p>Now, you can play with the API and you shouldn’t get any error for each API request :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*2jUlStaC5l8Lj2a9kpgqqA.png" /></figure><p>And, congrats again! You have deployed some applications on <strong>microk8s</strong> and they are working like a charm!</p><h3>Final words…</h3><p>Like all good things, this article has come to an end. My goal was to give you a quick introduction to <strong>MicroK8s</strong> with a simple example. I hope it sparked some interest and left you with good vibes about <strong>MicroK8s</strong>. Who knows, maybe you’ll fall in love with this tool just like I did! 😊</p><p>See you in another article — until then, happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78bff16fe816" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dev-jam/discovering-microk8s-a-lightweight-journey-into-kubernetes-78bff16fe816">Discovering MicroK8s: A Lightweight Journey into Kubernetes</a> was originally published in <a href="https://medium.com/dev-jam">Devjam</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>