<?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 Andrew Werner on Medium]]></title>
        <description><![CDATA[Stories by Andrew Werner on Medium]]></description>
        <link>https://medium.com/@awerner1?source=rss-d17a8248d04f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LKwwsZJpzYfowb--nHHwmg.jpeg</url>
            <title>Stories by Andrew Werner on Medium</title>
            <link>https://medium.com/@awerner1?source=rss-d17a8248d04f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 14:57:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@awerner1/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[3 ways to easily improve your code’s readability]]></title>
            <link>https://medium.com/@awerner1/3-ways-to-easily-improve-your-codes-readability-caf2a827c9f0?source=rss-d17a8248d04f------2</link>
            <guid isPermaLink="false">https://medium.com/p/caf2a827c9f0</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Andrew Werner]]></dc:creator>
            <pubDate>Fri, 23 Aug 2019 09:31:35 GMT</pubDate>
            <atom:updated>2019-08-23T09:33:04.047Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the many reasons that functional programming is often touted as a better way to write programs is its ability to improve readability but why is this important?</p><p>There’s the famous quote from Bob Martin’s <a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=as_li_ss_tl?s=books&amp;ie=UTF8&amp;qid=1458577041&amp;sr=1-1&amp;keywords=clean+code&amp;linkCode=sl1&amp;tag=devdaily-20&amp;linkId=b02cce691c33e6c64b8daf0c169d39f7">Clean Code</a> that the ratio of reading code to writing code is ten to one. If this is even close to true and if we care at all about efficiency then any gains we can make in our ability to read code will pay us back big-time in terms of allowing us more time to write code. Who doesn’t want to <em>write</em> more code?!</p><p>So in this article we’re going to go back to the basics and look at how you can leverage that functional style to really write super readable code.</p><h3>It all begins with pure functions</h3><p>A pure function will always return the same outputs for a given set of inputs.</p><p>This is the simple way of saying that it is <em>deterministic</em>. It also has no side-effects: things like mutating the state of an object or writing to a file. For an example in Scala:</p><pre>var baseNumber: Int = 10<br><br>def impureAdd(numberToAdd: Int): Int = baseNumber += numberToAdd<br><br>def pureAdd(baseNumber: Int, numberToAdd: Int): Int = baseNumber + numberToAdd</pre><p>This is completely contrived but does show the difference. for pureAdd we will always get the same result back for the same input no matter what we do.</p><p>So what’s this got to do with readability and how does it help us write better code?</p><p>The things to spot is that all of the functions dependencies are passed to it. If your program is constructed purely from functions that act on data you only ever need to look to a single function to understand what it does. You are then completely in control of how far into Wonderland you have to go. To take the metaphor all the way: you also don’t have to bring any baggage with you.</p><p>This leads me to:</p><h4><strong><em>Suggestion 1 — Pass all dependencies to your functions</em></strong></h4><h3>You can also pass functions to your functions</h3><p>One of the key things we try to do in functional programming to treat functions themselves just like we do the data they act on. You may have heard this referred to as treating functions as first class. For example we can do the following:</p><pre>def someFunction(numberOne: Int, numberTwo: Int): Int =<br>  numberOne + numberTwo<br><br>def myImpureFunction(numberOne: Int, numberTwo: Int): Int =<br>  someFunction(numberOne, numberTwo)<br><br>def myPureFunction(numberOne: Int, numberTwo: Int, fn: (Int, Int) =&gt; Int): Int =<br>  fn(numberOne, numberTwo)</pre><p>While this example makes no sense functionally (pun intended) it does illustrate something that I’ve certainly been very guilty of in the past. You can picture the scene: we’ve written a long function and want to keep things DRY (Don’t Repeat Yourself for the uninitiated) so we pull some common operation or code that has a single responsibility into its own function. That leaves us in the exact situation we see with the bad example. We are now coupled to a particular implementation and we must hold both functions in mind when reading this code.</p><p>The best bit about this from a readability perspective is that this is <em>referentially transparent</em> which means that we can always replace the value of this function call with the operations it references at the results would be the same. For example:</p><pre>def add(numberOne: Int, numberTwo: Int): Int = numberOne + numberTwo<br><br>val resultOne: Int = firstClass(1, 2, add)<br><br>val resultTwo: Int = add(1, 2)<br><br>val resultThree: Int = 1 + 2</pre><p>Again this example is just to prove the point that the way we calculate resultOne and resultTwo are interchangeable and while it might be difficult to see how this is valuable to the program at the moment imagine you are trying to debug what’s going on here. You never need to hold the context of some previous computation in your head. It can simply be replaced by some value that it equates to, breezy!</p><h4><strong><em>Suggestion 2 — Pass your functions around just like your data</em></strong></h4><h3>But we can’t always use pure functions</h3><p>It’s always good to admit where things can fall down and when it comes to programs its the areas that we have to have side effects that bite us. These are often one of the following:</p><ul><li>anything that changes the file system</li><li>calling an API</li><li>altering a mutable data structure</li><li>printing or logging</li><li>obtaining user input</li><li>inserting a record into a database</li></ul><p>In functional programming we have the idea of Monads which, simply put, act as a wrapper around some value. With monads we can take unreliable mutating side effects and wrap them into something that is reliable and can always be used.</p><p>Essentially Monads allow us to build a program where for our core we can always assume that we have what we need to operate on. We don’t need to define control flow or check for nil as part of our application or business logic. Two great examples of Monads in Scala are the Option and Either Monads both of which are often used to simplify the presence or absence of data and/or errors that may have occurred during processing.</p><p>Now couple this with the idea of <a href="https://blog.ndepend.com/hexagonal-architecture/">hexagonal architecture</a> also sometimes referred to as ports and adaptors. Implementing this pattern means that your side-affecting components are defined at the edge of your system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/0*vlIMHqGez48fjYoG.png" /></figure><p>The key here for our purposes is that any edge operations and results are wrapped in Monads. In the case of a http call this might be a Future. The point is the same. With our values wrapped all of our core application functions can be purely written to deal with the Monads they are supplied and other side-affect-y operations such as error handling can be implemented in a similar fashion at the edge of the system.</p><h4><strong><em>Suggestion 3 — Wrap your side affects and data</em></strong></h4><h4><strong><em>Suggestion 4 — Build your side affecting components at the edge of your system</em></strong></h4><p>It might not seem like much but by sticking to the suggestions above you end up with a system that is incredibly easy to define and reason about and this just scratches the surface because this pattern of programming also has other massive benefits. Think of all the time you can save on your testing because you don’t need to setup the world? Property based testing? What about the fact that each of your functions is ultimately just an algebraic formula that you can use simple mathematical principles to reduce and refactor. Definitely food for thought.</p><p><em>Originally published at </em><a href="https://www.reasontree.io/blog/2019-08-20-3-ways-to-easily-improve-your-codes-readability/"><em>https://www.reasontree.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caf2a827c9f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GDPR: A simple solution to encryption and the right to be forgotten]]></title>
            <link>https://medium.com/@awerner1/gdpr-a-simple-solution-to-encryption-and-the-right-to-be-forgotten-e166a2e78f2e?source=rss-d17a8248d04f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e166a2e78f2e</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[clojure]]></category>
            <category><![CDATA[vault]]></category>
            <category><![CDATA[gdpr]]></category>
            <category><![CDATA[encryption]]></category>
            <dc:creator><![CDATA[Andrew Werner]]></dc:creator>
            <pubDate>Thu, 17 Jan 2019 17:08:51 GMT</pubDate>
            <atom:updated>2019-10-07T06:43:58.355Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IedXc-OiHW3XQp4clxHQzQ.jpeg" /></figure><p>Programmers have rarely been subject to anything that looks like regulatory oversight until recently when the EU passed a piece of legislation called the General Data Protection Regulation. While this is only legally applicable in the EU it has become the de-facto global standard when it comes to handling user data in IT systems.</p><p>While it wont cover the <a href="https://eugdpr.org/">legislation</a> itself this post is intended to offer a simple practical solution to the problem of how to encrypt Personally Identifiable Information (PII) and how to do that in a way that allows us the programmer to ensure a users right to be forgotten. The examples below are written in Clojure but the end result can be accomplished in any language.</p><p>Rather than forcing individual applications within an ecosystem to all implement encryption themselves we’ll outsource the problem to: the <a href="https://www.vaultproject.io/docs/secrets/transit/index.html">Vault Transit Encryption Engine</a> which gives us encryption as a service. Let’s dive into the implementation, in a terminal run the following:</p><pre>$ brew install consul vault</pre><p>To work locally you’ll also need to specify the local vault address:</p><pre>$ export VAULT_ADDR=&#39;http://127.0.0.1:8200&#39;</pre><p>Now we can spin up a local vault development server:</p><pre>$ vault server -dev</pre><p>All being well, you should now have a running vault server. Now look back at your terminal. As the server spun up it should have printed out something that includes the following:</p><pre>The unseal key and root token are displayed below in case you want to<br>seal/unseal the Vault or re-authenticate.</pre><pre>Unseal Key: SOME_UNSEAL_KEY<br>Root Token: SOME_ROOT_TOKEN</pre><p>Take the root token and export it to an environment variable</p><pre>export VAULT_ROOT_TOKEN=&quot;SOME_ROOT_TOKEN&quot;</pre><p>For the sake of speed we’ll be using this to identify our requests to the local vault server.</p><blockquote>As an aside, you should never use the root token outside of development. If you need to know more about how vault authenticates requests to setup your own tokens then have a look at <a href="https://www.vaultproject.io/docs/concepts/policies.html">vault policies</a></blockquote><p>The final thing we need to do is to enable the transit encryption engine.</p><pre>$ vault secrets enable transit</pre><h4>Implementing our encryption</h4><p>We’re now moving over to our hypothetical application to implement the encryption of message as they pass through our hands. I’ve used the Clojure REPL here but all the code is completely valid and can be ported straight into your application. I’ve also used 3 libraries: <strong>clj-http</strong> to make http calls, <strong>cheshire</strong> to parse json and <strong>clojure.data.codec.base64</strong> to handle b64 encoding and decoding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*MVEvV0FZfI79unGTNflXRg.png" /><figcaption>Import required libraries</figcaption></figure><p>I’ll also quickly define a binding so that we can use our Vault Root Token in our application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*KnDj_87U4VY6JjhYNrXyAw.png" /><figcaption>Grab the VAULT_ROOT_TOKEN environment variable</figcaption></figure><p>The vault transit encryption engine only deals in data in a common format: base 64. This means that before we get onto the business of encryption we need some helper functions to encode and decode our messages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*bMUDuvgZ81JZU-GI57wpqg.png" /><figcaption>Function to base 64 encode a string</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*3X3BqQ-BxwmRK1Jbg1dYNw.png" /><figcaption>Function to decode a b64 string</figcaption></figure><p>Fantastic, we now have everything to write our encryption functions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*RVKMt0fo3X1jYBwvI-NRPw.png" /><figcaption>Encryption function</figcaption></figure><p>Something to note here. The URL used ends with our encryption-key, this is the unique encryption key ring that is used to encrypt the data. To support the right to be forgotten this should be unique per user but we’ll dive into this a bit more later.</p><p>If we now call this function with a test message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F0aPbxWC6jS8g26VF_mYmw.png" /><figcaption>Encrypt a ‘Hello World!’ message</figcaption></figure><p>We get a response containing a lot of metadata. However, buried within the body of the message is the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*PGlObAmFBS4ZFZ8GxNSkmQ.png" /><figcaption>Pulling out the relevant ciphertext field</figcaption></figure><p>This is our encrypted message. So now let us consider that we are some downstream consumer of data and we need to decrypt this message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*L54oiHH5lbZvThXkHgi9gw.png" /><figcaption>Decryption Function</figcaption></figure><p>Note that this function uses the same encryption key ring to decrypt this piece of data. So if we now call this function with our ciphertext value and that same encryption key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zp6rOY927omujgGmPF_fgg.png" /><figcaption>Decryption response</figcaption></figure><p>Pull out the relevant field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*pgo79jqmsMDu4Lup3EeJog.png" /><figcaption>Plaintext message reponse</figcaption></figure><p>Then decode this using our b64-&gt;string function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*ANVwKpoDTUDws5n6d6Gp_g.png" /><figcaption>Our initial message is returned to us</figcaption></figure><p>Fantastic encryption and decryption as a service implemented incredibly simply.</p><h4>The Right to be Forgotten</h4><p>One of the thorniest issues to deal with is the right to be forgotten. For anyone who hasn’t grappled with this issues, it’s the legally defined right of a user to ask for their data to be removed from a system. But if you have their data and it is spread across various applications, sitting in different forms in multiple databases and storage systems then how do you draw all this stuff together and guarantee that it has been removed? The answer: Crypto Shredding. Remember that encryption key ring that we were talking about. If all your user data for a particular user is encrypted and we need the encryption key ring to decrypt it then if we delete the encryption key ring we will no longer every be able to see that user data. For all intents and purposes it has been shredded and all we’re left with is a bunch of unusable strings.</p><p>The beauty of this is that it is incredibly easy: all you need to do is run the following for a particular key:</p><pre>vault delete transit/keys/some_key</pre><p>And with that we have GDPR encryption in a nutshell.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e166a2e78f2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All the things you can learn from a kata to become a better Programmer]]></title>
            <link>https://medium.com/@awerner1/all-the-things-you-can-learn-from-a-kata-to-become-a-better-programmer-393d0df713e2?source=rss-d17a8248d04f------2</link>
            <guid isPermaLink="false">https://medium.com/p/393d0df713e2</guid>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Andrew Werner]]></dc:creator>
            <pubDate>Tue, 15 Jan 2019 16:25:07 GMT</pubDate>
            <atom:updated>2019-01-15T16:25:07.130Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6hd4nTIV1h9X1-C334XEQg.jpeg" /></figure><p>One of the easiest ways to get to grips with a new programming language is to run through a few code katas (for anyone who’s new to the concept a <a href="https://en.wikipedia.org/wiki/Kata_(programming)">kata</a> is a small learning/training exercise). Often the tendency is to put together a few tests, run through the challenge and move onto the next kata the instant those tests are passing but what if we delved a little deeper?</p><p>What i’ll be trying to get to is an understanding of how to create cleaner code (and also why we’d even want to do this) by going from the simple to the complex. Walking through a simple kata I’ll show how you can learn to spot some common patterns and then show how you can apply to a more real-world scenario.</p><h4>Starting with a bad solution</h4><p>Probably the most infamous kata is FizzBuzz. The spec for this is relatively simple and is usually some variant of the following:</p><pre>Write a function that takes a number as an input and converts it to a string the contents of which depend on the factor of the number</pre><pre>- if the number has 3 as a factor add &quot;Fizz&quot; to the output<br>- if the number has 5 as a factor add &quot;Buzz&quot; to the output<br>- if neither 3 nor 5 is a factor return the input as a string </pre><p>Fantastic, that sounds easy enough we can probably code a solution to that without too much thought! Using JavaScript as a <em>Lingua-franca</em>:</p><pre>function fn (number) {<br>  let output = &#39;&#39;<br>  if (number % 3 === 0) output += &#39;Fizz&#39;<br>  if (number % 5 === 0) output += &#39;Buzz&#39;<br>  return output || number.toString()<br>}</pre><p>Awesome, we’ve just created a masterful solution! But is this really extensible? What if we add another requirement?</p><h4>Changing Requirements</h4><p>The problem we’re facing here crops up all the time. Someone has come along and pulled the rug out from under us: changing the original specification. So let’s mimic this by adding another requirement to our FizzBuzz program.</p><pre>- if the number has 7 as a factor add &quot;Bazz&quot; to the output</pre><p>You might be thinking, that’s annoying but still not really a problem: we just update our solution:</p><pre>function fn (number) {<br>  let output = &#39;&#39;<br>  if (number % 3 === 0) output += &#39;Fizz&#39;<br>  if (number % 5 === 0) output += &#39;Buzz&#39;<br>  if (number % 7 === 0) output += &#39;Bazz&#39;<br>  return output || number.toString()<br>}</pre><p>We’ve just copied and pasted a line of code, changed a number and a letter and now we’re good to go, not the biggest crime perhaps but something doesn’t feel right.</p><p>What would happen if we kept on getting asked to add new FizzBuzz features? Things could get tedious, the code could get hard to follow (the word spaghetti comes to mind). What if we put an operation out of order and created a bug? With our current approach and multiple future requirements it might take us a while to track down the offending line of code. Our productivity by this point is wilting! This is technical debt at its most simple: a small innocent change that on its own is harmless but when multiplied adds complexity and obfuscates the intended purpose of the application. Luckily greater minds that ours have already thought of a good way of avoiding this issue: by following the DRY principle (don’t repeat yourself).</p><h4>Spotting the pattern</h4><p>So how do we DRY out our code? How can we tackle this issue and make our solution more extensible and future-proof?</p><p>As a start there is one incredibly common pattern we can spot here. At the core of our solution we have data mixed into our operation. It’s the data that keeps changing but the operation is exactly the same each time.</p><p>Armed with this new realisation we can separate out the divisor and the string-result into a data structure and then create a general operation:</p><pre>function fn (number) {<br>  const data = [[3, &#39;Fizz&#39;], [5, &#39;Buzz&#39;], [7, &#39;Bazz&#39;]]<br>  let output = &#39;&#39;<br>  data.forEach(([divisor, word]) =&gt; {<br>    if(number % divisor === 0) output += word<br>  })<br>  return output || number.toString()<br>}</pre><p>This is looking better. We now have a generalised operation and data that it operates over. Could we take this even further? Certainly, we could pass the data as an argument to the function, allowing any data that conforms to this structure to be used . You might also be thinking that this is also a good example of the Single Responsibility Principle in that this function will now only be responsible for operating over data rather than defining and operating. Why is this good? Well, we’ve just increased its potential to be used in other situations with different data sets. Our kata is now more future proof!</p><pre>function fn (n, data = [[3, &#39;Fizz&#39;], [5, &#39;Buzz&#39;], [7, &#39;Bazz&#39;]]) {<br>  let output = &#39;&#39;<br>  data.forEach(([divisor, word]) =&gt; {<br>    if(n % divisor === 0) output += word<br>  })<br>  return output || n.toString()<br>}</pre><h4>Things get Functional</h4><p>Now things are going to take a turn for the functional, because there’s another pattern at play here and again this is one that pops up all the time! I’m talking, of course, about … wait for it … Monoids!</p><p>Don’t let the term scare you, if you actually want to know about Monoids <a href="https://blog.axosoft.com/monoids-practical-category-theory/">this blog is the best practical expalanation</a> I’ve come across. However, for our purposes I’m going to ignore the terminology and maths completely. What we care about is spotting the pattern.</p><p>So essentially we have some data that shares a type: string (that’s our &#39;Fizz&#39; &#39;Buzz&#39; etc.), has some idea of what empty is: &#39;&#39; and lastly has a common operation that ties these pieces of data together: that’s our += or addition.</p><p>Ok, that’s not very complex. So what does this mean for us? Well Monoids are <em>Incremental Combination</em> friendly and there is a great core JavaScript function that’s just awesome for this: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce">reduce</a>. So how does this change our solution?</p><pre>function fn (n, data = [[3, &#39;Fizz&#39;], [5, &#39;Buzz&#39;], [7, &#39;Bazz&#39;]]) {<br>  return data.reduce((result, [divisor, word]) =&gt;<br>    n % divisor === 0 ? result + word : result, &#39;&#39;) <br>  || n.toString()<br>}</pre><p>Holy smokes, that’s looking a lot nicer!</p><h4>Is any of this useful?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*tKRTwe9nWPTavq-HE4IfIA.jpeg" /></figure><p>At this point we’ve hopefully learnt some new things, hooray for us! And ok, this works well in the context of our lovely, sheltered, kata-world but how is this useful in our day to day work? Well let’s expand our horizons and look at a simplified real world example.</p><p>We’re putting together a gorgeous website and so far have the following:</p><pre>&lt;!DOCTYPE html&gt;</pre><pre>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;title&gt;Title&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;  <br>    &lt;div id=&quot;homePage&quot;&gt;<br>    &lt;h1&gt;Welcome!&lt;/h1&gt;    <br>    &lt;script&gt;<br>      let page = document.getElementById(&#39;homePage&#39;)<br>      if (new Date().getDay() === 1) {<br>        page.insertAdjacentHTML(&#39;beforeend&#39;, &#39;&lt;p&gt;Cheer up!&lt;/p&gt;&#39;) <br>      } else {<br>        page.insertAdjacentHTML(&#39;beforeend&#39;, &#39;&lt;p&gt;Hello&lt;/p&gt;&#39;)       <br>      }<br>    &lt;/script&gt;<br>    &lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>In the above example we assume that most of the time we want to have just the normal title and a paragraph but on a Monday everyone needs cheering up so we need to have a more cheery welcome message…do you see where we’re going? What if we get told that we need a different message for each day of the week, or even content some of which stays the same and some of which differs on any given day?</p><p>Well the exact same principles we’ve discussed previously apply. HTML can be treated in exactly the same way as our FizzBuzz strings: as a monoid. We can just define the different elements as data and then add them together into a single item.</p><pre>&lt;!DOCTYPE html&gt;</pre><pre>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;title&gt;Title&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;  <br>    &lt;div id=&quot;homePage&quot;&gt;<br>    &lt;script&gt;<br>      const page = document.getElementById(&#39;homePage&#39;) <br>      const data = [[1, &#39;&lt;p&gt;Cheer up!&lt;/p&gt;&#39;][5, &#39;&lt;p&gt;Friyay!&lt;/p&gt;&#39;]]<br>      const content = data.reduce((result, [n, message]) =&gt; <br>        new Date().getDay() === n ? result + message : result<br>        , &#39;&lt;h1&gt;Welcome!&lt;/h1&gt;)<br>      page.insertAdjacentHTML(&#39;beforeend&#39;, content) <br>    &lt;/script&gt;<br>    &lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>We are left with a webpage that can be composed from a series of different elements based on random characteristics. For the sake of simplicity i’ll stop there but as food for thought: could you treat your predicate as data? Could you use the same pattern with say React or Vue components? Could you even use this pattern to build up your data…functions acting on functions as data acting on data…it might sound complicated but hopefully you’ve seen how as with our FizzBuzz example it can remarkably simple.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=393d0df713e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>