<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Ifu Aniemeka]]></title><description><![CDATA[software engineer. martial artist.]]></description><link>https://www.lifeasalgorithm.com</link><image><url>https://substackcdn.com/image/fetch/$s_!rBqR!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9030814c-8767-4ca0-bc18-14977654def7_144x144.png</url><title>Ifu Aniemeka</title><link>https://www.lifeasalgorithm.com</link></image><generator>Substack</generator><lastBuildDate>Tue, 21 Apr 2026 10:37:44 GMT</lastBuildDate><atom:link href="https://www.lifeasalgorithm.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Ifu Aniemeka]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[ifuaniemeka@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[ifuaniemeka@substack.com]]></itunes:email><itunes:name><![CDATA[Ifu Aniemeka]]></itunes:name></itunes:owner><itunes:author><![CDATA[Ifu Aniemeka]]></itunes:author><googleplay:owner><![CDATA[ifuaniemeka@substack.com]]></googleplay:owner><googleplay:email><![CDATA[ifuaniemeka@substack.com]]></googleplay:email><googleplay:author><![CDATA[Ifu Aniemeka]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[OpenAI Scholars Demo Day 2018]]></title><link>https://www.lifeasalgorithm.com/p/openai-scholars-demo-day-2018</link><guid isPermaLink="false">https://www.lifeasalgorithm.com/p/openai-scholars-demo-day-2018</guid><dc:creator><![CDATA[Ifu Aniemeka]]></dc:creator><pubDate>Mon, 29 Dec 2025 02:26:34 GMT</pubDate><enclosure url="https://substackcdn.com/image/youtube/w_728,c_limit/wSVwTszUrck" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div id="youtube2-wSVwTszUrck" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;wSVwTszUrck&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/wSVwTszUrck?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div>]]></content:encoded></item><item><title><![CDATA[A Friendly Introduction to Convolutional Neural Networks]]></title><description><![CDATA[Originally published 8/22/2017 on the Hashrocket blog.]]></description><link>https://www.lifeasalgorithm.com/p/a-friendly-introduction-to-convolutional</link><guid isPermaLink="false">https://www.lifeasalgorithm.com/p/a-friendly-introduction-to-convolutional</guid><dc:creator><![CDATA[Ifu Aniemeka]]></dc:creator><pubDate>Thu, 25 Dec 2025 02:28:18 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!oiFD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em><strong>Originally published 8/22/2017 on the Hashrocket <a href="https://hashrocket.com/blog">blog</a>.</strong></em></p><h3>Introduction</h3><p>Convolutional neural networks (or convnets for short) are used in situations where data can be expressed as a &#8220;map&#8221; wherein the proximity between two data points indicates how related they are. An image is such a map, which is why you so often hear of convnets in the context of image analysis. If you take an image and randomly rearrange all of its pixels, it is no longer recognizable. The relative position of the pixels to one another, that is, the order, is significant.</p><p>Convnets are commonly used to categorize things in images, so that&#8217;s the context in which we&#8217;ll discuss them.</p><p>A convnet takes an image expressed as an array of numbers, applies a series of operations to that array and, at the end, returns the probability that an object in the image belongs to a particular class of objects. For instance, a convnet can let you know the probability that a photo you took contains a building or a horse or what have you. It might be used to distinguish between very similar instances of something. For example, you could use a convnet to go through a collection of images of skin lesions and classify the lesions as benign or malignant.</p><p>Convnets contain one or more of each of the following layers:</p><ul><li><p>convolution layer</p></li><li><p>ReLU (rectified linear units) layer</p></li><li><p>pooling layer</p></li><li><p>fully connected layer</p></li><li><p>loss layer (during the training process)</p></li></ul><p>We could also consider the initial inputs i.e. the pixel values of the image, to be a layer. However, since no operation occurs at this point, I&#8217;ve excluded it from the list.</p><p></p><h3>Convolution Layer</h3><p>The architecture of a convnet is modeled after the mammalian visual cortex, the part of the brain where visual input is processed. Within the visual cortex, specific neurons fire only when particular phenomena are in the field of vision. One neuron might fire only when you are looking at a left-sloping diagonal line and another only when a horizontal line is in view.</p><p>Our brains process images in layers of increasing complexity. The first layer distinguishes basic attributes like lines and curves. At higher levels, the brain recognizes that a configuration of edges and colors is, for instance, a house or a bird.</p><p>In a similar fashion, a convnet processes an image using a matrix of weights called filters (or features) that detect specific attributes such as diagonal edges, vertical edges, etc. Moreover, as the image progresses through each layer, the filters are able to recognize more complex attributes.</p><p>To a computer, an image is just an array of numbers. An image using the full spectrum of colors is represented using a 3-dimensional matrix of numbers.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oiFD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oiFD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png 424w, https://substackcdn.com/image/fetch/$s_!oiFD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png 848w, https://substackcdn.com/image/fetch/$s_!oiFD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png 1272w, https://substackcdn.com/image/fetch/$s_!oiFD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oiFD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png" width="405" height="480" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:480,&quot;width&quot;:405,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:200613,&quot;alt&quot;:&quot;owl&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182288002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="owl" title="owl" srcset="https://substackcdn.com/image/fetch/$s_!oiFD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png 424w, https://substackcdn.com/image/fetch/$s_!oiFD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png 848w, https://substackcdn.com/image/fetch/$s_!oiFD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png 1272w, https://substackcdn.com/image/fetch/$s_!oiFD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F529f6b9d-58f1-465b-9015-9da67c706f20_405x480.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>The depth of the matrix corresponds to RGB values. For the sake of simplicity, we&#8217;ll initially consider only grayscale images. Each pixel in a grayscale image can be represented using a single value that indicates the intensity of the pixel. These values lie between 0 and 255, where 0 is black and 255 is white.</p><p>The convolution layer is always the first step in a convnet. Let&#8217;s say we have a 10 x 10 pixel image, here represented by a 10 x 10 x 1 matrix of numbers:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Blzk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Blzk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png 424w, https://substackcdn.com/image/fetch/$s_!Blzk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png 848w, https://substackcdn.com/image/fetch/$s_!Blzk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png 1272w, https://substackcdn.com/image/fetch/$s_!Blzk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Blzk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png" width="400" height="392" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/afe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:392,&quot;width&quot;:400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:57127,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182288002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Blzk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png 424w, https://substackcdn.com/image/fetch/$s_!Blzk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png 848w, https://substackcdn.com/image/fetch/$s_!Blzk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png 1272w, https://substackcdn.com/image/fetch/$s_!Blzk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe45cad-1484-4418-b6f3-f6ca2e74a6cb_400x392.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>I&#8217;ve stuck to zeroes and ones to make the math simpler. You&#8217;ll see what I&#8217;m talking about in a bit.</p><p>The output of a convolution layer is something called a feature map (or activation map).</p><p>In order to generate a feature map, we take an array of weights (which is just an array of numbers) and slide it over the image, taking the dot product of the smaller array and the pixel values of the image as we go. This operation is called convolution. The array of weights is referred to as a filter or a feature. Below, we have a 3 x 3 filter (as with the image, we&#8217;ve used 1s and 0s for simplicity).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CMQ1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CMQ1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png 424w, https://substackcdn.com/image/fetch/$s_!CMQ1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png 848w, https://substackcdn.com/image/fetch/$s_!CMQ1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png 1272w, https://substackcdn.com/image/fetch/$s_!CMQ1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CMQ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png" width="190" height="194" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:194,&quot;width&quot;:190,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:7776,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182288002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CMQ1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png 424w, https://substackcdn.com/image/fetch/$s_!CMQ1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png 848w, https://substackcdn.com/image/fetch/$s_!CMQ1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png 1272w, https://substackcdn.com/image/fetch/$s_!CMQ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F376a9ab3-8923-4683-a0ca-d14e26d9c7df_190x194.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>We then use the filter to generate a feature map</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!O8Qh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!O8Qh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png 424w, https://substackcdn.com/image/fetch/$s_!O8Qh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png 848w, https://substackcdn.com/image/fetch/$s_!O8Qh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png 1272w, https://substackcdn.com/image/fetch/$s_!O8Qh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!O8Qh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png" width="1456" height="694" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:694,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:90527,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182288002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!O8Qh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png 424w, https://substackcdn.com/image/fetch/$s_!O8Qh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png 848w, https://substackcdn.com/image/fetch/$s_!O8Qh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png 1272w, https://substackcdn.com/image/fetch/$s_!O8Qh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de58fc9-8b06-429f-bfcf-bc74e2d9158d_1556x742.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The image shows the calculation for the first dot product taken. Imagine the filter overlaid on the upper left-hand corner of the image. Each weight in the filter is multiplied by the number beneath it. We then sum those products and put them in the upper left hand corner of what will be the feature map. We slide the filter to the right by 1 pixel and repeat the operation, placing the sum of the products in the next slot in the feature map. When we reach the end of the row, we shift the filter down by 1 pixel and repeat.</p><p>Filters are used to find where in an image details such as horizontal lines, curves, colors, etc. occur. The filter above finds right-sloping diagonal lines.</p><p>Note that higher values in the feature map are in roughly the same location as the diagonal lines in the image. Regardless of where a feature appears in an image, the convolution layer will detect it. If you know that your convnet can identify the letter &#8216;A&#8217; when it is in the center of an image, then you know that it can also find it when it is moved to the right-hand side of the image. Any shift in the &#8216;A&#8217; is reflected in the feature maps. This property of the convolution layer is called translation equivariance.</p><p>Thus far, we&#8217;ve been discussing the convolutional layer in the context of a grayscale image with a 2-dimensional filter. It&#8217;s also possible that you would be dealing with a color image, the representation of which is a 3-dimensional matrix, as well as multiple filters per convolutional layer, each of which is also 3-dimensional. This does require a little more calculation, but the math is still basically the same.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JRyc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JRyc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg 424w, https://substackcdn.com/image/fetch/$s_!JRyc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg 848w, https://substackcdn.com/image/fetch/$s_!JRyc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!JRyc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JRyc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg" width="1456" height="1297" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1297,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:315752,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182288002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JRyc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg 424w, https://substackcdn.com/image/fetch/$s_!JRyc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg 848w, https://substackcdn.com/image/fetch/$s_!JRyc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!JRyc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca7e3a6e-37ad-4b08-b016-4da25a61b0f1_2193x1953.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You&#8217;ll see that we&#8217;re still taking the dot product, it&#8217;s just that this time around we need to add the products along the depth dimension as well.</p><p>In the above example, we convolved two 3 x 3 x 3 filters with a 6 x 6 x 3 image and the result was a 4 x 4 x 2 feature map. If we had used three filters, the feature map would have been 4 x 4 x 3. If there were 4, then the size would have been 4 x 4 x 4, and so on. </p><p>To get the dimensions of the feature map is fairly straightforward.</p><p>Our input image has a width of 6, a height of 6, and a depth of 3, i.e. wi= 6, hi = 6, di = 3. Each of our filters has a width of 3, a height of 3 and a depth of 3 i.e. wf = 3, hf = 3, df = 3. </p><p>The stride is the number of pixels you move the filter between each dot product operation. In our example, we would take the dot product, move the filter over by one pixel, and repeat. When we get to the edge of the image, we move the filter down by one pixel. Hence, the stride in our example convolution layer is 1. </p><p>The width and height of the feature map are calculated like so:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;w_m = (w_i - w_f)/s + 1\n&quot;,&quot;id&quot;:&quot;BQXZUGWORW&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;h_m = (h_i - h_f)/s + 1&quot;,&quot;id&quot;:&quot;VVBOIVBPVM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>where <strong>s</strong> is the stride. </p><p>Let&#8217;s break that down a bit. If you have a filter that&#8217;s 2 x 2 and your image is 10 x 10, then when you overlay your filter on your image, you&#8217;ve already taken up 2 spaces across, i.e. along the width. That counts for 1 spot in the feature map (that&#8217;s the &#8216;+1&#8217; part). To get the number of spots left, you subtract the filter&#8217;s width from the total width. In this case, the result is 8. If your stride is 1, you have 8 spots left, i.e. 8 more dot products to take until you get to the edge of the image. If your stride is 2, then you have 4 more dot products to take.</p><p>The depth of the feature map is always equal to the number of filters used; in our case, 2.</p><h3>ReLU Layer</h3><p>The ReLU (short for rectified linear units) layer commonly follows the convolution layer. The addition of the ReLU layer allows the neural network to account for non-linear relationships, i.e. the ReLU layer allows the convnet to account for situations in which the relationship between the pixel value inputs and the convnet output is not linear. Note that the convolution operation is a linear one. The output in the feature map is just the result of multiplying the weights of a given filter by the pixel values of the input and adding them up:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y = w_1x_1 +w_2x_2 + w_3x_3  + ...&quot;,&quot;id&quot;:&quot;OBCTKWTASU&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>where <strong>w</strong> is a weight value and <strong>x</strong> is a pixel value.</p><p>The ReLU function takes a value <strong>x</strong> and returns 0 if <strong>x</strong> is negative and <strong>x</strong> if <strong>x</strong> is positive.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f(x) = max(0,x)&quot;,&quot;id&quot;:&quot;INBTIKUXPA&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0wOW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0wOW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg 424w, https://substackcdn.com/image/fetch/$s_!0wOW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg 848w, https://substackcdn.com/image/fetch/$s_!0wOW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!0wOW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0wOW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg" width="480" height="311" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:311,&quot;width&quot;:480,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21171,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182288002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0wOW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg 424w, https://substackcdn.com/image/fetch/$s_!0wOW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg 848w, https://substackcdn.com/image/fetch/$s_!0wOW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!0wOW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f0ee7f3-2402-4fa0-a470-215ef38e6faf_480x311.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>As you can see from the graph, the ReLU function is nonlinear.</p><p>In this layer, the ReLU function is applied to each point in the feature map. The result is a feature map without negative values.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!l_qg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l_qg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg 424w, https://substackcdn.com/image/fetch/$s_!l_qg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg 848w, https://substackcdn.com/image/fetch/$s_!l_qg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!l_qg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l_qg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg" width="871" height="424" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:424,&quot;width&quot;:871,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:88332,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182288002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!l_qg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg 424w, https://substackcdn.com/image/fetch/$s_!l_qg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg 848w, https://substackcdn.com/image/fetch/$s_!l_qg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!l_qg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28a46460-3746-4857-998a-063141f80ed9_871x424.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Other functions such as tanh or the sigmoid function can be used to add non-linearity to the network, but ReLU generally works better in practice.</p><h3>Pooling Layer</h3><p>The pooling layer also contributes towards the ability of the convnet to locate features regardless of where they are in the image. In particular, the pooling layer makes the convnet less sensitive to small changes in the location of a feature, i.e. it gives the convnet the property of translational invariance in that the output of the pooling layer remains the same even when a feature is moved a little. Pooling also reduces the size of the feature map, thus simplifying computation in later layers.</p><p>There are a number of ways to implement pooling, but the most effective in practice is max pooling. To perform max pooling, imagine a window sliding across the feature map. As the window moves across the map, we grab the largest value in the window and discard the rest.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mJwH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mJwH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg 424w, https://substackcdn.com/image/fetch/$s_!mJwH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg 848w, https://substackcdn.com/image/fetch/$s_!mJwH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!mJwH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mJwH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg" width="830" height="723" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:723,&quot;width&quot;:830,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:157219,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182288002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mJwH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg 424w, https://substackcdn.com/image/fetch/$s_!mJwH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg 848w, https://substackcdn.com/image/fetch/$s_!mJwH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!mJwH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F014c0ccd-4a81-4574-89c7-45778c39afde_830x723.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>As mentioned earlier, the output indicates the general region where a feature is present, as opposed to the precise location, which isn&#8217;t really important. In the above diagram, the result of the pooling operation indicates that the feature can be found in the upper left-hand corner of the feature map, and, thus, in the upper left hand corner of the image. We don&#8217;t need to know that the feature is exactly, say 100 pixels down and 50 pixels to the right relative to the top-left corner. </p><p>As an example, if we&#8217;re trying to discern if an image contains a dog, we don&#8217;t care if one of the dog&#8217;s ears is flopped slightly to the right.</p><p>The most common implementation of max pooling, and the one used in the example image, uses a 2 x 2 pixel window and a stride of 2, i.e. we take the largest value in the window, move the window over by 2 pixels, and repeat.</p><p>The operation is basically the same for 3D feature maps as well. The dimensions of a 3D feature map are only reduced along the x and y axes. The depth of the pooling layer output is equal to the depth of the feature map. </p><p></p><h3>The Fully-Connected and Loss Layers</h3><p>The fully-connected layer is where the final &#8220;decision&#8221; is made. At this layer, the convnet returns the probability that an object in a photo is of a certain type.</p><p>The convolutional neural networks we&#8217;ve been discussing implement something called supervised learning. In supervised learning, a neural network is provided with labeled training data from which to learn. Let&#8217;s say you want your convnet to tell you if an image is of a cat or of a dog. You would provide your network with a large set of pictures of cats and dogs, where pictures of cats are labeled &#8216;cat&#8217; and pictures of dogs are labeled &#8216;dog&#8217;. This is called the training set. Then, based on the difference between its guesses and the actual values, the network adjusts itself such that it becomes more accurate each time you run a test image through it.</p><p>You confirm that your network is in fact able to properly classify photos of cats and dogs in general (as opposed to just being able to classify photos in the training set you provided) by running it against an unlabeled collection of images. This collection is called the test set.</p><p>In this example, the fully-connected layer might return an output like &#8220;0.92 dog, 0.08 cat&#8221; for a specific image, indicating that the image likely contains a dog.</p><p>The fully-connected layer has at least 3 parts - an input layer, a hidden layer, and an output layer. The input layer is the output of the preceding layer, which is just an array of values. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Jpoo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Jpoo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Jpoo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Jpoo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Jpoo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Jpoo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg" width="1456" height="854" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:854,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:540038,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182288002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Jpoo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Jpoo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Jpoo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Jpoo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ec7423c-0537-47c7-8386-fb305cecedd2_2297x1348.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>You&#8217;ll note in the image, there are lines extending from the inputs </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;x_a \\: to \\: x_e&quot;,&quot;id&quot;:&quot;WJUIAUECFF&quot;}" data-component-name="LatexBlockToDOM"></div><p> to nodes</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y_a \\: to \\: y_d&quot;,&quot;id&quot;:&quot;NRFAXXUYNQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>that represent the hidden layer (so called because they&#8217;re sandwiched between the input and output layers and, thus, &#8220;invisible&#8221;).  The input values are assigned different weights</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;w_{xy}&quot;,&quot;id&quot;:&quot;FCXNPEZQHB&quot;}" data-component-name="LatexBlockToDOM"></div><p>per connection to a node in the hidden layer (in the image, only the weights for the value</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;x_a&quot;,&quot;id&quot;:&quot;VDYTDDNJAA&quot;}" data-component-name="LatexBlockToDOM"></div><p> are labeled). Each of the circles in the hidden layer is an instance of computation. Such instances are often called neurons. Each neuron applies a function to the sum of the product of a weight and its associated input value. </p><p>The neurons in the output layer correspond to each of the possible classes the convnet is looking for. Similar to the interaction between the input and hidden layer, the output layer takes in values (and their corresponding weights) from the hidden layer, applies a function and puts out the result. In the example above, there are two classes under consideration - cats and dogs. </p><p>Following the fully-connected layer is the loss layer, which manages the adjustments of weights across the network. Before the training of the network begins, the weights in the convolution and fully-connected layers are given random values. Then during training, the loss layer continually checks the fully-connected layer&#8217;s guesses against the actual values with the goal of minimizing the difference between the guess and the real value as much as possible. The loss layer does this by adjusting the weights in both the convolution and fully-connected layers.</p><h3>Hyperparameters</h3><p>It should be said at this point that each of these layers (with the exception of the loss layer) can be multiply stacked on one another. You may very well have a network that looks like this:</p><p><strong>convolutional layer &gt;&gt; reLU &gt;&gt; pooling &gt;&gt; convolutional layer &gt;&gt; pooling &gt;&gt; fully-connected layer &gt;&gt; convolutional layer &gt;&gt; fully-connected layer &gt;&gt; loss layer</strong></p><p>There are other parameters in addition to the order and number of the layers of a convnet that an engineer can modify. The parameters that are adjusted by a human agent are referred to as hyperparameters. This is where an engineer gets to be creative. </p><p>Other hyperparameters include the size and number of filters in the convolution layer and the size of the window used in the max pooling layer.</p><p></p><h3>Overview</h3><p>So, let&#8217;s run through an entire convolutional neural network from start to finish just to clarify things. </p><p>We start with an untrained convnet in which we have determined all of the hyperparameters. We initialize the weights in the convolution and fully-connected layers with random inputs. We then feed it images from our training set. Let&#8217;s say we have one instance of each layer in an example network. Each image is processed first in the convolution layer, then in the ReLu layer, then in the pooling layer. The fully-connected layer receives inputs from the pooling layer and uses these inputs to return a guess as to the contents of the image. The loss layer compares the guess to the actual value and figures out by how much to adjust the weights to bring the guess closer to the actual value. For instance, if the convnet returns that there is an 87% chance that an image contains a dog, and the image does indeed contain a dog, the guess is off by 13% and the weights are adjusted to bring that guess closer to 100%.</p><p></p><h3>Other Resources</h3><ul><li><p><a href="http://yosinski.com/deepvis">Understanding Neural Networks Through Deep Visualization</a> by Jason Yosinksi, Jeff Clune, Ang Nguyen, et al.</p></li><li><p><a href="https://brohrer.github.io/how_convolutional_neural_networks_work.html">How Do Convolutional Neural Networks Work?</a> by Brandon Rohrer</p></li><li><p><a href="https://ujjwalkarn.me/2016/08/09/quick-intro-neural-networks/">A Quick Introduction to Neural Networks</a> by Ujjwal Karn</p></li><li><p><a href="http://cs231n.github.io/convolutional-networks/">Convolutional Neural Networks for Visual Recognition</a> by Andrej Karpathy</p><p></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Document Your Confusion]]></title><description><![CDATA[Originally published 11/28/2017 on the Hashrocket blog.]]></description><link>https://www.lifeasalgorithm.com/p/document-your-confusion</link><guid isPermaLink="false">https://www.lifeasalgorithm.com/p/document-your-confusion</guid><dc:creator><![CDATA[Ifu Aniemeka]]></dc:creator><pubDate>Mon, 22 Dec 2025 02:31:24 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rBqR!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9030814c-8767-4ca0-bc18-14977654def7_144x144.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Originally published 11/28/2017 on the Hashrocket <a href="https://hashrocket.com/blog">blog</a>.</em></p><p>On a few occasions, I&#8217;ve started work on a brownfield project and found that, either due to poor programming practices or because there was no elegant way to implement a feature, it&#8217;s been necessary to create documentation beyond what is normally included in a README. This documentation often took the form of glossaries, diagrams, or additional exposition on the codebase.</p><p>Your typical README contains all or some of the following: a short introductory paragraph, a list of dependencies, instructions on how to install the app, configuration, how to run the test suite, database creation and migration, services, and how to deploy the app. If it&#8217;s an open source project, there will likely be sections devoted to listing authors, rules around contributing, the license under which it can be used, as well as additional documentation around how to use the package.</p><p>There are contexts in which this is inadequate.  Let&#8217;s describe such a situation in detail.</p><p>You&#8217;ve recently been assigned to a brownfield project. You&#8217;re looking at the app for the first time, and you notice fairly quickly that the codebase looks like a Jackson Pollock painting.</p><p>For starters, the company pivoted a couple years ago, so large portions of the app remain that aren&#8217;t relevant anymore. Perhaps entities are named in a way that no longer accurately describes them. Maybe there are references to features that have long since been abandoned.</p><p>Obscured by all of this cruft are the operative parts of the app, which aren&#8217;t much to look at, either. There are models named Article, Post, and Essay as well as models named Writer, Scribe, and Author. For business logic reasons, an Article can belong to an Author or a Writer, but not a Scribe, a Post can belong to all three, and an Essay can belong only to an Author.</p><p>There&#8217;s a &#8220;God&#8221; model that encompasses multiple concepts, another model that should really implement a state machine, etc.</p><p>In short, this app needs a serious overhaul, but maybe you&#8217;ve been brought on to implement just a few features or the client simply doesn&#8217;t have the budget to pay for an overhaul right now or the powers-that-be don&#8217;t see the value in well-crafted software and aren&#8217;t willing to pay you to refactor the code, no matter how many times you explain that substandard code actually costs more in the long run. Heck, maybe the client thinks the code is just fine and not in need of refactoring at all.</p><p>For whatever reason, refactoring this code is not something you&#8217;ll be able to do right now and you suspect that the technical debt that&#8217;s accumulated will only increase for the foreseeable future, making the app ever more brittle and difficult to add features to.</p><p>In an ideal world, this codebase would have been cleaned up ages ago. In the meantime, you still have to help your client.</p><p>Unfortunately, the mental overhead of working on this app makes development a grind. You&#8217;re constantly having to remind yourself of the subtle differences between an Author, a Writer, and a Scribe and how they relate to the other models in the application.</p><p>What&#8217;s needed is documentation that will reduce the mental overhead that comes with working with certain kinds of apps; basically, an augmented README. For simplicity, I&#8217;ll refer to this &#8216;superREADME&#8217; as a VELLUM (&#8217;cause it&#8217;s <em>fancy</em>).* I&#8217;ll also stop screaming README(!) and VELLUM(!) at you from here on out.</p><p>A vellum and a readme are quite similar (really, the former could be thought of as a &#8216;superset&#8217; of the latter). The difference is that a vellum adheres to a longer, more expository style of documentation than is typically found in readmes and there is an expectation that the author(s) of the vellum will reference it with some frequency. A vellum is the place where you document your confusion.</p><p>A vellum can serve as a guide through less-than-ideal codebases, but it also has a place in well-architected projects (brownfield or greenfield) that have complex domains and require a bit of explication. You would use the vellum as a way to note difficult or subtle concepts around the domain or the codebase that any developer coming into the project should know before starting work.</p><p>The remainder of this blog post will cover what should go into a thorough vellum file and some of the pitfalls of over-reliance on such documentation. It will be written from the perspective of a consultant working on a client application, but that isn&#8217;t to say that vellums can&#8217;t be carried over to open-source contexts. They can certainly be used to convey ideas that will help other or new contributors better understand the codebase.</p><p></p><h3>Introduction</h3><p>The first part of the vellum should consist of an introduction to the application including its purpose, its audience, and details around the business itself, such as how the app makes money. At this point, you&#8217;re providing context.</p><p>In the example below, we write an introduction to an application that helps users manage their stock portfolios.</p><p></p><blockquote><p>This application is called SmartMoney. It enables the casual trader to manage their portfolio of stocks. The app makes money by charging traders a flat per month fee of $5, in contrast to the payment structure of other services where users are charged per trade. The app allows users to make a wide variety of orders. Namely:</p><p></p><ul><li><p>market orders</p></li><li><p>limit orders</p></li><li><p>stop-loss orders</p></li><li><p>stop-limit orders</p></li><li><p>bracketed orders</p></li><li><p>trailing stop-loss orders</p></li></ul><p></p><p>The app also provides a simple interface for shorting stocks. Some other key features of the app include the ability to set up notifications for when a particular stock&#8217;s worth has dropped below or risen to a certain value. The app also has a recommendation engine that suggests stocks to invest in that are &#8220;hot&#8221; and in an industry in which the trader has shown interest.</p><p>When development first began, the app was geared towards only sending notifications based on changes in stock prices. However, the company decided to make a more fully featured app as customers wanted an experience that integrated setting up notifications with making orders.</p></blockquote><p></p><p>You&#8217;ll note that the introduction also lays out some terms (the types of orders that are available in the app) that the next developer should understand before writing any code (more about that soon). It also mentions the app&#8217;s history, which helps to explain any cruft that might be left behind.</p><p>Your goal is to convey enough salient information about the app that any developer could just open the vellum and know who this app is for, why certain quirks of the app are present, etc. You don&#8217;t want to go into excruciating detail. Save that for storyboarding.</p><p></p><h3>Glossary</h3><p>You should follow this introductory paragraph with a glossary of terms. The glossary should include any terms you think a developer stepping into this project should be aware of, but reasonably might not know.</p><p></p><blockquote><p>...</p><p></p><ul><li><p>ETF (Exchange Traded Fund): a collection of assets (stocks, bonds, etc.) that can be traded like a common stock, i.e. partial ownership in a corporation.</p></li></ul><p></p><ul><li><p>P/E Ratio (Price-Earnings Ratio): measures the amount of money traders are willing to pay for each dollar of earnings from a single share. It is equal to the stock price divided by the earnings per share.</p></li></ul><p></p><ul><li><p>PEG Ratio (Price-Earnings to Growth Ratio): It is similar to the P/E ratio, except that it takes the growth of the company into account. It is equal to the P/E ratio divided by the growth rate of the company.</p></li></ul><p></p><ul><li><p>Stop-Loss Order: an order to sell a stock if its price drops below a specified value</p></li></ul><p></p><p>...</p></blockquote><p></p><h3>Pitfalls</h3><p>Your vellum file should also contain a section devoted to potentially confusing aspects of the app. You want to provide clarification on things like</p><p></p><ul><li><p>complex models or relations between models</p></li><li><p>confusing or unusual model names</p></li><li><p>distinctions between similar or closely-related models</p></li><li><p>non-obvious relations between what a developer is dealing with on the backend versus what the user sees.</p></li></ul><p></p><blockquote><p>Bracketed Order Model: This model corresponds to bracketed orders. On the backend, it is a bracketed order, but for the user, it is a &#8216;One-Cancels-the-Other Order&#8217;.</p></blockquote><p></p><h3>Architectural Decisions</h3><p>You should also take the time to justify non-obvious architectural decisions. This may include talking about design patterns you used:</p><blockquote><p>We opted for using the Factory design pattern to handle the creation of order objects. Order types are quite similar and we want the client to be order-agnostic.  </p></blockquote><p></p><h3>README</h3><p>The final section should discuss the topics you would cover in a readme, including things like configuration, how to run the test suite, database creation and migration, services, and how to deploy the app, etc. I assume you&#8217;ve already written your fair share of readmes. If not, read this <a href="https://medium.com/@meakaakka/a-beginners-guide-to-writing-a-kickass-readme-7ac01da88ab3">brief tutorial on how to write a kick ass readme</a>.</p><h3>Caveats</h3><p>You don&#8217;t want to over-rely on your vellum file to the extent that you abandon good consulting and programming practices.</p><p>If you&#8217;re walking into a codebase badly in need of a refactor, this should be conveyed to the client. In such a situation, a vellum is stopgap documentation, i.e. explanation that makes up for code that is not self-explanatory.</p><p>If you&#8217;re writing the application from scratch, a vellum is used to elucidate complexity. It&#8217;s <em>not</em> an excuse to write opaque code or inexact stories.</p><p>Certainly, not every project requires a vellum file or all of the parts of a vellum detailed here. Simpler applications will generally not require one as there isn&#8217;t enough mental overhead to justify having this extra, rather involved document you have to maintain.</p><p>A good rule of thumb is that if you don&#8217;t have to consult the vellum very often, then you can go ahead and delete it. Conversely, if you constantly find yourself checking your notes while coding, your notes likely contain information that should be extracted into some kind of documentation.</p><p>Of course, all of the topics I described could simply be appended to a readme file. The important thing is to remember to reduce confusion for yourself and subsequent developers.</p><p>* Vellum is a high-quality parchment made from the skin of calves</p><p></p><p><em><strong>Related articles:</strong></em></p><p><a href="https://airbrake.io/blog/software-development/acceptable-technical-debt">Acceptable Technical Debt</a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Fun With Views and Common Table Expression]]></title><description><![CDATA[originally published 2/1/2018 on the Hashrocket blog]]></description><link>https://www.lifeasalgorithm.com/p/fun-with-views-and-common-table-expression</link><guid isPermaLink="false">https://www.lifeasalgorithm.com/p/fun-with-views-and-common-table-expression</guid><dc:creator><![CDATA[Ifu Aniemeka]]></dc:creator><pubDate>Sun, 21 Dec 2025 00:12:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!5f2r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>originally published 2/1/2018 on the Hashrocket <a href="https://www.hashrocket.com/blog/">blog</a></em></p><p>A view is a stored query the results of which can be treated like a table. Note that it is the query that is saved and <em>not</em> the results of the query. Each time you use a view, its associated query is executed.</p><p>A related concept is that of the common table expression or CTE. A CTE can be thought of as a temporary view; you can only use it within the query in which it appears (you <em>can</em> refer to it multiple times, however).</p><p>Let&#8217;s say that you&#8217;re the SQL-savvy owner of a store that sells kits for building robots. On your site, customers are guided through the process of selecting all of the components needed to build a quadrupedal robot, i.e. getting the right motors, microcontrollers, sensors, batteries, grippers, etc.</p><p>Robots have lots of component parts and you have to make sure that the correct components for each order arrive or your customers will leave mean comments on social media.</p><p>Right now you have the following tables:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5f2r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5f2r!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png 424w, https://substackcdn.com/image/fetch/$s_!5f2r!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png 848w, https://substackcdn.com/image/fetch/$s_!5f2r!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png 1272w, https://substackcdn.com/image/fetch/$s_!5f2r!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5f2r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png" width="728" height="375" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:750,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:146008,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5f2r!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png 424w, https://substackcdn.com/image/fetch/$s_!5f2r!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png 848w, https://substackcdn.com/image/fetch/$s_!5f2r!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png 1272w, https://substackcdn.com/image/fetch/$s_!5f2r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8fd619f-3452-419c-82e1-cc7961202f07_2294x1182.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>And those tables contain the following data:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!71l9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!71l9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png 424w, https://substackcdn.com/image/fetch/$s_!71l9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png 848w, https://substackcdn.com/image/fetch/$s_!71l9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png 1272w, https://substackcdn.com/image/fetch/$s_!71l9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!71l9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png" width="1306" height="346" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:346,&quot;width&quot;:1306,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:52182,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!71l9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png 424w, https://substackcdn.com/image/fetch/$s_!71l9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png 848w, https://substackcdn.com/image/fetch/$s_!71l9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png 1272w, https://substackcdn.com/image/fetch/$s_!71l9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa79682b5-dac9-4db1-8efb-14087cb66607_1306x346.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!q2sr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!q2sr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png 424w, https://substackcdn.com/image/fetch/$s_!q2sr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png 848w, https://substackcdn.com/image/fetch/$s_!q2sr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png 1272w, https://substackcdn.com/image/fetch/$s_!q2sr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!q2sr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png" width="1456" height="311" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:311,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:70158,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!q2sr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png 424w, https://substackcdn.com/image/fetch/$s_!q2sr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png 848w, https://substackcdn.com/image/fetch/$s_!q2sr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png 1272w, https://substackcdn.com/image/fetch/$s_!q2sr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd0def9c-93e1-4e94-8529-7c0e573abd09_1772x378.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OLtW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OLtW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png 424w, https://substackcdn.com/image/fetch/$s_!OLtW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png 848w, https://substackcdn.com/image/fetch/$s_!OLtW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png 1272w, https://substackcdn.com/image/fetch/$s_!OLtW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OLtW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png" width="450" height="405.63380281690144" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0183ec22-4831-422a-8254-f2d06618e55e_568x512.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:512,&quot;width&quot;:568,&quot;resizeWidth&quot;:450,&quot;bytes&quot;:37033,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OLtW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png 424w, https://substackcdn.com/image/fetch/$s_!OLtW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png 848w, https://substackcdn.com/image/fetch/$s_!OLtW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png 1272w, https://substackcdn.com/image/fetch/$s_!OLtW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0183ec22-4831-422a-8254-f2d06618e55e_568x512.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0G8L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0G8L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png 424w, https://substackcdn.com/image/fetch/$s_!0G8L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png 848w, https://substackcdn.com/image/fetch/$s_!0G8L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png 1272w, https://substackcdn.com/image/fetch/$s_!0G8L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0G8L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png" width="728" height="211" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:123316,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0G8L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png 424w, https://substackcdn.com/image/fetch/$s_!0G8L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png 848w, https://substackcdn.com/image/fetch/$s_!0G8L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png 1272w, https://substackcdn.com/image/fetch/$s_!0G8L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fa39ff-74bb-4776-b95f-f5f70e03c2fa_2172x630.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eu4O!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eu4O!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png 424w, https://substackcdn.com/image/fetch/$s_!eu4O!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png 848w, https://substackcdn.com/image/fetch/$s_!eu4O!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png 1272w, https://substackcdn.com/image/fetch/$s_!eu4O!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eu4O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png" width="1226" height="826" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:826,&quot;width&quot;:1226,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:66437,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eu4O!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png 424w, https://substackcdn.com/image/fetch/$s_!eu4O!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png 848w, https://substackcdn.com/image/fetch/$s_!eu4O!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png 1272w, https://substackcdn.com/image/fetch/$s_!eu4O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4b3dd4-c57c-40fc-bdd7-2ccb513e6cc3_1226x826.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>You want to see a list of all the purchases made and the components in those purchases. You might write a query like the following:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!a3_t!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!a3_t!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png 424w, https://substackcdn.com/image/fetch/$s_!a3_t!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png 848w, https://substackcdn.com/image/fetch/$s_!a3_t!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png 1272w, https://substackcdn.com/image/fetch/$s_!a3_t!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!a3_t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png" width="1112" height="375" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:375,&quot;width&quot;:1112,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:92162,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!a3_t!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png 424w, https://substackcdn.com/image/fetch/$s_!a3_t!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png 848w, https://substackcdn.com/image/fetch/$s_!a3_t!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png 1272w, https://substackcdn.com/image/fetch/$s_!a3_t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d67708-c0fe-4f66-93ae-88cb4db9fa66_1112x375.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Just a quick explanation in case anything in the query is unclear. We&#8217;re joining the tables <code>purchases</code>, <code>component_purchases</code>, and <code>components</code> and then grouping the rows by <code>purchase_id</code>. SQLFiddle <a href="http://sqlfiddle.com/#!17/03571/2">here</a>.</p><p>For each of the components in a purchase, the <code>sum</code> function adds the multiple of the number of units of a component ordered and the price of a component. The <code>array_agg</code> function composes an array of the details of the purchase. Notice that the <code>sum</code> and <code>array_agg</code> functions act across rows, but the <code>concat</code> function acts across columns.</p><p> The result of our query is thus:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!X4lv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!X4lv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png 424w, https://substackcdn.com/image/fetch/$s_!X4lv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png 848w, https://substackcdn.com/image/fetch/$s_!X4lv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png 1272w, https://substackcdn.com/image/fetch/$s_!X4lv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!X4lv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png" width="1456" height="319" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:319,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:96396,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!X4lv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png 424w, https://substackcdn.com/image/fetch/$s_!X4lv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png 848w, https://substackcdn.com/image/fetch/$s_!X4lv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png 1272w, https://substackcdn.com/image/fetch/$s_!X4lv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1db0ff81-e83b-457b-8bc3-769c276e6b5d_2018x442.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em>Check out the SQLFiddle <a href="http://sqlfiddle.com/#!17/5907b/1">here</a>.</em></p><p>It&#8217;s not an exceptionally long query, but you suspect that you&#8217;ll be using it quite a lot and you&#8217;d prefer not to have to write the whole thing out all of the time.</p><p>That&#8217;s where views come in:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!if4k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!if4k!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png 424w, https://substackcdn.com/image/fetch/$s_!if4k!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png 848w, https://substackcdn.com/image/fetch/$s_!if4k!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png 1272w, https://substackcdn.com/image/fetch/$s_!if4k!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!if4k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png" width="1118" height="815" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/43527780-8961-4443-9f35-92088953584b_1118x815.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:815,&quot;width&quot;:1118,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:119158,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!if4k!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png 424w, https://substackcdn.com/image/fetch/$s_!if4k!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png 848w, https://substackcdn.com/image/fetch/$s_!if4k!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png 1272w, https://substackcdn.com/image/fetch/$s_!if4k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43527780-8961-4443-9f35-92088953584b_1118x815.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Now you have a simple way to reuse this query. Let&#8217;s say that you want to know all of the purchases made within the last week. Now you can just write the following:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tI6l!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tI6l!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png 424w, https://substackcdn.com/image/fetch/$s_!tI6l!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png 848w, https://substackcdn.com/image/fetch/$s_!tI6l!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png 1272w, https://substackcdn.com/image/fetch/$s_!tI6l!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tI6l!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png" width="646" height="260" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:260,&quot;width&quot;:646,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:36171,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tI6l!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png 424w, https://substackcdn.com/image/fetch/$s_!tI6l!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png 848w, https://substackcdn.com/image/fetch/$s_!tI6l!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png 1272w, https://substackcdn.com/image/fetch/$s_!tI6l!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1df006a3-b5cb-4b66-9f2e-1814e46afdb3_646x260.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>SQLFiddle <a href="http://sqlfiddle.com/#!17/03571/3">here</a></em></p><p>From within the PostgreSQL interactive terminal, you can use the command <code>\dv</code> to see a list of all the views in the database.</p><p>Dropping a view is as simple as dropping a table:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!B51w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!B51w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png 424w, https://substackcdn.com/image/fetch/$s_!B51w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png 848w, https://substackcdn.com/image/fetch/$s_!B51w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png 1272w, https://substackcdn.com/image/fetch/$s_!B51w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!B51w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png" width="646" height="121" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:121,&quot;width&quot;:646,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:19897,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!B51w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png 424w, https://substackcdn.com/image/fetch/$s_!B51w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png 848w, https://substackcdn.com/image/fetch/$s_!B51w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png 1272w, https://substackcdn.com/image/fetch/$s_!B51w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6638d8c-4ce2-4ff8-a987-ee85b195e364_646x121.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Note that if you drop a table using <code>cascade</code>, any views dependent on that table will be dropped as well.</p><p>It&#8217;s also possible to perform operations on the data in the underlying tables of some views. Updatable views are views where data can be edited, inserted, or deleted. To be updatable, a view must be really basic. Think something along the lines of:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w8Ra!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w8Ra!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png 424w, https://substackcdn.com/image/fetch/$s_!w8Ra!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png 848w, https://substackcdn.com/image/fetch/$s_!w8Ra!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png 1272w, https://substackcdn.com/image/fetch/$s_!w8Ra!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w8Ra!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png" width="620" height="306" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:306,&quot;width&quot;:620,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:41794,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!w8Ra!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png 424w, https://substackcdn.com/image/fetch/$s_!w8Ra!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png 848w, https://substackcdn.com/image/fetch/$s_!w8Ra!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png 1272w, https://substackcdn.com/image/fetch/$s_!w8Ra!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf39f66c-dbc1-4392-bc1c-d7dafecb685a_620x306.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Updatable views can only select rows from a single table (or updatable view). They also cannot contain &#8216;group_by&#8217;, &#8216;limit&#8217;, or &#8216;with&#8217; clauses.</p><p>You can see all of the relevant restrictions in the Postgres docs <a href="https://www.postgresql.org/docs/10/static/sql-createview.html">here</a>.  </p><p>If you do have an updatable view, you can do something like</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vecu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vecu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png 424w, https://substackcdn.com/image/fetch/$s_!vecu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png 848w, https://substackcdn.com/image/fetch/$s_!vecu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png 1272w, https://substackcdn.com/image/fetch/$s_!vecu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vecu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png" width="620" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:620,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:29735,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vecu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png 424w, https://substackcdn.com/image/fetch/$s_!vecu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png 848w, https://substackcdn.com/image/fetch/$s_!vecu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png 1272w, https://substackcdn.com/image/fetch/$s_!vecu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c793a9f-8b61-4c4b-bcf7-1ef0e59af970_620x167.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>A new row for &#8216;Anne Droid&#8217; has been inserted into the customer table.</p><p>Note that the <code>customer_info</code> view only includes customers whose names begin with letters after &#8216;E&#8217;. If you were to run the following query:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Mc5r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Mc5r!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png 424w, https://substackcdn.com/image/fetch/$s_!Mc5r!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png 848w, https://substackcdn.com/image/fetch/$s_!Mc5r!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png 1272w, https://substackcdn.com/image/fetch/$s_!Mc5r!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Mc5r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png" width="620" height="121" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:121,&quot;width&quot;:620,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:19125,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Mc5r!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png 424w, https://substackcdn.com/image/fetch/$s_!Mc5r!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png 848w, https://substackcdn.com/image/fetch/$s_!Mc5r!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png 1272w, https://substackcdn.com/image/fetch/$s_!Mc5r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2571d63-cecf-4bf9-a693-e9ccb9c79782_620x121.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Anne&#8217;s name would not appear in the results because her last name begins with a &#8216;D&#8217;. A new row has been inserted into the <code>customers</code> table using the <code>customer_info</code> view, but that row is not accessible via the view. SQLFiddle <a href="http://sqlfiddle.com/#!17/03571/3">here</a>.</p><p>Note that you cannot insert values for columns that are present in the underlying table, but not in the view. The following query would result in an error:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pwO8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pwO8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png 424w, https://substackcdn.com/image/fetch/$s_!pwO8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png 848w, https://substackcdn.com/image/fetch/$s_!pwO8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png 1272w, https://substackcdn.com/image/fetch/$s_!pwO8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pwO8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png" width="868" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:868,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:38677,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pwO8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png 424w, https://substackcdn.com/image/fetch/$s_!pwO8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png 848w, https://substackcdn.com/image/fetch/$s_!pwO8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png 1272w, https://substackcdn.com/image/fetch/$s_!pwO8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22745824-cbb1-4514-87bd-8d67f0c62fd3_868x167.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>So, that&#8217;s views in a nutshell. Let&#8217;s move on to CTEs.</p><p>To start with, CTE stands for &#8216;common table expression&#8217;. They&#8217;re quite similar to views except that once the query is executed, a CTE ceases to be.</p><p>In the view <code>purchase_information</code>, we were able to get all of the components in a purchase, as well as the price of the purchase. Let&#8217;s say I wanted a query that would provide me with purchase information, but also the customers to whom the purchases belonged. This can be achieved pretty easily using a common table expression.</p><p>You start a CTE using the keyword <code>with</code> followed by the name of the CTE and the query itself.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xl8o!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xl8o!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png 424w, https://substackcdn.com/image/fetch/$s_!xl8o!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png 848w, https://substackcdn.com/image/fetch/$s_!xl8o!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!xl8o!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xl8o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png" width="812" height="1138" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1138,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:198498,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xl8o!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png 424w, https://substackcdn.com/image/fetch/$s_!xl8o!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png 848w, https://substackcdn.com/image/fetch/$s_!xl8o!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!xl8o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4a57594-a3d3-44a0-8a0f-962cccdee314_812x1138.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>SQLFiddle <a href="http://sqlfiddle.com/#!17/03571/4">here</a></em></p><p>The <code>purchases</code> CTE can be referred to <em>like</em> a table. Of course, once the query is executed, <code>purchases</code> doesn&#8217;t exist.</p><p>The results of this query are:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UFn8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UFn8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png 424w, https://substackcdn.com/image/fetch/$s_!UFn8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png 848w, https://substackcdn.com/image/fetch/$s_!UFn8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png 1272w, https://substackcdn.com/image/fetch/$s_!UFn8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UFn8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png" width="728" height="108.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:217,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:114744,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UFn8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png 424w, https://substackcdn.com/image/fetch/$s_!UFn8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png 848w, https://substackcdn.com/image/fetch/$s_!UFn8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png 1272w, https://substackcdn.com/image/fetch/$s_!UFn8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f5ef855-40b9-413a-9481-e81224e2a502_2110x314.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Phew!</p><p>Now you can send the correct robot parts to your customers.</p><p>But wait! There&#8217;s some complexity to the orders that you&#8217;ve forgotten. Some components need to be combined with other components in order to work. For the sake of simplicity, let&#8217;s say that any given component requires one or fewer other components to function.</p><p>Drawing out the relationship between our components, we see that we get a tree graph.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hdUQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hdUQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png 424w, https://substackcdn.com/image/fetch/$s_!hdUQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png 848w, https://substackcdn.com/image/fetch/$s_!hdUQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png 1272w, https://substackcdn.com/image/fetch/$s_!hdUQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hdUQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png" width="650" height="203.57142857142858" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:342,&quot;width&quot;:1092,&quot;resizeWidth&quot;:650,&quot;bytes&quot;:21780,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hdUQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png 424w, https://substackcdn.com/image/fetch/$s_!hdUQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png 848w, https://substackcdn.com/image/fetch/$s_!hdUQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png 1272w, https://substackcdn.com/image/fetch/$s_!hdUQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb1bcc63-5764-458c-8600-f19df6de1f5a_1092x342.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>To describe this in the database, we&#8217;ll need to add another column to the <code>component</code> table. The <code>subcomponent_id</code> field will point to the component upon which the current component depends.</p><p>Let&#8217;s say that a customer orders the component with id 4. In order to get all of the parts the customer needs, we&#8217;ll need to traverse the tree all the way down.</p><p>Luckily, Postgres has just the solution for this - recursive common table expressions. Recursive CTEs provide a way to allow queries to perform some action with a table, and then to perform the same action on the results of the previous action.</p><p>That&#8217;s probably kind of confusing.</p><p>Below is the structure of a recursive common table expression:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5gsk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5gsk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png 424w, https://substackcdn.com/image/fetch/$s_!5gsk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png 848w, https://substackcdn.com/image/fetch/$s_!5gsk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png 1272w, https://substackcdn.com/image/fetch/$s_!5gsk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5gsk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png" width="812" height="352" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:352,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:49420,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5gsk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png 424w, https://substackcdn.com/image/fetch/$s_!5gsk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png 848w, https://substackcdn.com/image/fetch/$s_!5gsk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png 1272w, https://substackcdn.com/image/fetch/$s_!5gsk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2026310a-e296-4b2e-b85a-8a81531d4050_812x352.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>The recursive CTE begins much like a non-recursive CTE. You&#8217;ll notice that the modifier <code>recursive</code> is required after <code>with</code>. Immediately after <code>recursive</code> is the name of the CTE.</p><p>Above the <code>union</code> operator is a query that initializes the working table. The working table is the result set upon which the recursive term is currently acting. For instance, you might put <code>select id, name from robots where name=&#8217;Cindi Mayweather&#8217;</code>. Since there is one and only one of the illustrious Cindi Mayweather, this query will return one row.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TD4K!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TD4K!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png 424w, https://substackcdn.com/image/fetch/$s_!TD4K!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png 848w, https://substackcdn.com/image/fetch/$s_!TD4K!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png 1272w, https://substackcdn.com/image/fetch/$s_!TD4K!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TD4K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png" width="374" height="151.71698113207546" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c45b6409-0734-4281-b067-ed263ac6ad33_424x172.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:172,&quot;width&quot;:424,&quot;resizeWidth&quot;:374,&quot;bytes&quot;:14484,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TD4K!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png 424w, https://substackcdn.com/image/fetch/$s_!TD4K!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png 848w, https://substackcdn.com/image/fetch/$s_!TD4K!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png 1272w, https://substackcdn.com/image/fetch/$s_!TD4K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc45b6409-0734-4281-b067-ed263ac6ad33_424x172.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Note that this query is not executed again.</p><p>We&#8217;ll come back to what purpose the <code>union</code> operator serves in a bit. For now, let&#8217;s talk about the recursive query. The recursive query will make a reference to the CTE name. Wherever you see the CTE name in the query, that is a reference to the working table.    </p><p>Given a single component that needs to be shipped, we need to fetch the ids of all of its subcomponents, and their subcomponents, etc. To get all of the subcomponents for the component with an id of 4, we use the following query:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qHsj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qHsj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png 424w, https://substackcdn.com/image/fetch/$s_!qHsj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png 848w, https://substackcdn.com/image/fetch/$s_!qHsj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png 1272w, https://substackcdn.com/image/fetch/$s_!qHsj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qHsj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png" width="750" height="537" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:537,&quot;width&quot;:750,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:87924,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qHsj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png 424w, https://substackcdn.com/image/fetch/$s_!qHsj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png 848w, https://substackcdn.com/image/fetch/$s_!qHsj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png 1272w, https://substackcdn.com/image/fetch/$s_!qHsj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4aeb4c92-f13f-4b3f-9e7f-0faebcef3c8d_750x537.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>That&#8217;s pretty gross-looking, so let&#8217;s go through what&#8217;s happening step by step.</p><p>Execution of the CTE starts with the non-recursive query. Running that query returns the following:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!im9r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!im9r!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png 424w, https://substackcdn.com/image/fetch/$s_!im9r!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png 848w, https://substackcdn.com/image/fetch/$s_!im9r!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png 1272w, https://substackcdn.com/image/fetch/$s_!im9r!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!im9r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png" width="374" height="191.5169082125604" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:212,&quot;width&quot;:414,&quot;resizeWidth&quot;:374,&quot;bytes&quot;:14611,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!im9r!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png 424w, https://substackcdn.com/image/fetch/$s_!im9r!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png 848w, https://substackcdn.com/image/fetch/$s_!im9r!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png 1272w, https://substackcdn.com/image/fetch/$s_!im9r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1becbeaf-8e3e-4208-bbe9-72e057e28984_414x212.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>This is the first working table.</p><p>We see that an inner join of the working table and the components table produces the following:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sTQF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sTQF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png 424w, https://substackcdn.com/image/fetch/$s_!sTQF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png 848w, https://substackcdn.com/image/fetch/$s_!sTQF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png 1272w, https://substackcdn.com/image/fetch/$s_!sTQF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sTQF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png" width="1248" height="200" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:200,&quot;width&quot;:1248,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24000,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sTQF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png 424w, https://substackcdn.com/image/fetch/$s_!sTQF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png 848w, https://substackcdn.com/image/fetch/$s_!sTQF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png 1272w, https://substackcdn.com/image/fetch/$s_!sTQF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b6a81b-720e-4fbf-9425-e741c84b5c56_1248x200.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>From this, we get the next working table.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!P6Fh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!P6Fh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png 424w, https://substackcdn.com/image/fetch/$s_!P6Fh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png 848w, https://substackcdn.com/image/fetch/$s_!P6Fh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png 1272w, https://substackcdn.com/image/fetch/$s_!P6Fh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!P6Fh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png" width="374" height="191.69849246231155" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:204,&quot;width&quot;:398,&quot;resizeWidth&quot;:374,&quot;bytes&quot;:14366,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!P6Fh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png 424w, https://substackcdn.com/image/fetch/$s_!P6Fh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png 848w, https://substackcdn.com/image/fetch/$s_!P6Fh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png 1272w, https://substackcdn.com/image/fetch/$s_!P6Fh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050f38a-540f-4e87-bbd0-ff911e32b3f9_398x204.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>The working table is substituted for <code>purchase_components</code> in the recursive query, with the following result:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4aNP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4aNP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png 424w, https://substackcdn.com/image/fetch/$s_!4aNP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png 848w, https://substackcdn.com/image/fetch/$s_!4aNP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png 1272w, https://substackcdn.com/image/fetch/$s_!4aNP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4aNP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png" width="1456" height="247" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:247,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34956,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4aNP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png 424w, https://substackcdn.com/image/fetch/$s_!4aNP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png 848w, https://substackcdn.com/image/fetch/$s_!4aNP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png 1272w, https://substackcdn.com/image/fetch/$s_!4aNP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e054160-87e4-4aa5-a9a3-7a6f51db53c5_1648x280.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>And so on...</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LKkk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LKkk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png 424w, https://substackcdn.com/image/fetch/$s_!LKkk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png 848w, https://substackcdn.com/image/fetch/$s_!LKkk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png 1272w, https://substackcdn.com/image/fetch/$s_!LKkk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LKkk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png" width="374" height="186.2943396226415" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:264,&quot;width&quot;:530,&quot;resizeWidth&quot;:374,&quot;bytes&quot;:19045,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LKkk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png 424w, https://substackcdn.com/image/fetch/$s_!LKkk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png 848w, https://substackcdn.com/image/fetch/$s_!LKkk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png 1272w, https://substackcdn.com/image/fetch/$s_!LKkk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa4cd5c4-a840-47d3-a33b-c554270bf3ff_530x264.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bx77!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bx77!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png 424w, https://substackcdn.com/image/fetch/$s_!bx77!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png 848w, https://substackcdn.com/image/fetch/$s_!bx77!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png 1272w, https://substackcdn.com/image/fetch/$s_!bx77!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bx77!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png" width="1456" height="236" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:236,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34830,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bx77!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png 424w, https://substackcdn.com/image/fetch/$s_!bx77!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png 848w, https://substackcdn.com/image/fetch/$s_!bx77!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png 1272w, https://substackcdn.com/image/fetch/$s_!bx77!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4596a81c-77ca-435b-9027-59249b4b03f9_1664x270.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CsJQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CsJQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png 424w, https://substackcdn.com/image/fetch/$s_!CsJQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png 848w, https://substackcdn.com/image/fetch/$s_!CsJQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png 1272w, https://substackcdn.com/image/fetch/$s_!CsJQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CsJQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png" width="374" height="191.21804511278197" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:272,&quot;width&quot;:532,&quot;resizeWidth&quot;:374,&quot;bytes&quot;:19354,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CsJQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png 424w, https://substackcdn.com/image/fetch/$s_!CsJQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png 848w, https://substackcdn.com/image/fetch/$s_!CsJQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png 1272w, https://substackcdn.com/image/fetch/$s_!CsJQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88ae283f-d5a2-4fee-9710-532ce7e62c6a_532x272.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sstj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sstj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png 424w, https://substackcdn.com/image/fetch/$s_!sstj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png 848w, https://substackcdn.com/image/fetch/$s_!sstj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png 1272w, https://substackcdn.com/image/fetch/$s_!sstj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sstj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png" width="1456" height="233" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:233,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34495,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sstj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png 424w, https://substackcdn.com/image/fetch/$s_!sstj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png 848w, https://substackcdn.com/image/fetch/$s_!sstj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png 1272w, https://substackcdn.com/image/fetch/$s_!sstj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11f102b-6be1-40b3-8946-f2452ad500dd_1662x266.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8t34!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8t34!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png 424w, https://substackcdn.com/image/fetch/$s_!8t34!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png 848w, https://substackcdn.com/image/fetch/$s_!8t34!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png 1272w, https://substackcdn.com/image/fetch/$s_!8t34!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8t34!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png" width="374" height="184.86692015209127" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:260,&quot;width&quot;:526,&quot;resizeWidth&quot;:374,&quot;bytes&quot;:19308,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8t34!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png 424w, https://substackcdn.com/image/fetch/$s_!8t34!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png 848w, https://substackcdn.com/image/fetch/$s_!8t34!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png 1272w, https://substackcdn.com/image/fetch/$s_!8t34!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f25412-3f0b-42cb-b946-f765f52cc5ec_526x260.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>The recursion ends when the working table has no rows, i.e. when the values for the rows are all null. </p><p>Now we come to what <code>union</code> is doing. The <code>union</code> operator acts on all of the working tables that have been generated, combining them all into one table. To ensure that there are no duplicate rows, you use <code>union all</code>.</p><p>Hence the result of running the query is</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IZ_f!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IZ_f!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png 424w, https://substackcdn.com/image/fetch/$s_!IZ_f!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png 848w, https://substackcdn.com/image/fetch/$s_!IZ_f!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png 1272w, https://substackcdn.com/image/fetch/$s_!IZ_f!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IZ_f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png" width="188" height="333.36082474226805" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:344,&quot;width&quot;:194,&quot;resizeWidth&quot;:188,&quot;bytes&quot;:8367,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!IZ_f!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png 424w, https://substackcdn.com/image/fetch/$s_!IZ_f!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png 848w, https://substackcdn.com/image/fetch/$s_!IZ_f!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png 1272w, https://substackcdn.com/image/fetch/$s_!IZ_f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d6fc95-b2fd-4469-ad48-abb8845a2644_194x344.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>SQLFiddle <a href="http://sqlfiddle.com/#!17/03571/5">here</a>.</p><p>Boom! Nailed it.</p><p>Kinda.</p><p>If you recall, up top we have a list of purchases with the associated components and customer information. Well, that component list isn&#8217;t complete; we have to include subcomponents as well.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fn5J!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fn5J!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png 424w, https://substackcdn.com/image/fetch/$s_!fn5J!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png 848w, https://substackcdn.com/image/fetch/$s_!fn5J!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png 1272w, https://substackcdn.com/image/fetch/$s_!fn5J!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fn5J!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png" width="812" height="2433" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2433,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:369469,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fn5J!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png 424w, https://substackcdn.com/image/fetch/$s_!fn5J!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png 848w, https://substackcdn.com/image/fetch/$s_!fn5J!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png 1272w, https://substackcdn.com/image/fetch/$s_!fn5J!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F994979f9-90a7-4115-b7e0-d7b4f6686bb9_812x2433.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>SQLFiddle [here](http://sqlfiddle.com/#!17/03571/6)</p><p>In this query, we have two CTEs. When you want to use multiple CTEs in a query, you place <code>with</code> at the start of the group and separate each CTE with a comma. Notice that, even though only one of the CTEs is recursive, the <code>recursive</code> modifier is placed directly after <code>with</code>, as opposed to directly before the recursive CTE. Each CTE is executed normally. Another nifty thing about using <code>recursive</code> is that its presence means your CTEs can be in any order, i.e. one CTE can make reference to a CTE that is defined later. If you&#8217;re wondering how the <code>component_id</code> alias showed up in the final results, remember that aliases are preserved in the results of a union.</p><p>To understand how this query works, we first need to understand what the results of the <code>purchases_made</code> query are.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SnBd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SnBd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png 424w, https://substackcdn.com/image/fetch/$s_!SnBd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png 848w, https://substackcdn.com/image/fetch/$s_!SnBd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png 1272w, https://substackcdn.com/image/fetch/$s_!SnBd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SnBd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png" width="1456" height="264" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:264,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:48274,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SnBd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png 424w, https://substackcdn.com/image/fetch/$s_!SnBd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png 848w, https://substackcdn.com/image/fetch/$s_!SnBd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png 1272w, https://substackcdn.com/image/fetch/$s_!SnBd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ca13832-a0d7-4c0f-b528-daa377ba225d_1768x320.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>SQLFiddle [here](http://sqlfiddle.com/#!17/03571/7)</p><p>This is our first working table.</p><p>Following a process similar to the one in the earlier recursive query, the first inner join results in:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mOJj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mOJj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png 424w, https://substackcdn.com/image/fetch/$s_!mOJj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png 848w, https://substackcdn.com/image/fetch/$s_!mOJj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png 1272w, https://substackcdn.com/image/fetch/$s_!mOJj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mOJj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png" width="1456" height="206" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:206,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:38973,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/176597855?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mOJj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png 424w, https://substackcdn.com/image/fetch/$s_!mOJj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png 848w, https://substackcdn.com/image/fetch/$s_!mOJj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png 1272w, https://substackcdn.com/image/fetch/$s_!mOJj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdde144f2-4ad0-4f6f-95cf-1bb404b67fe6_1700x240.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>The results of the <code>purchase_components</code> CTE can be found in <a href="http://sqlfiddle.com/#!17/03571/8">this</a> SQLFiddle.</p><p>I would recommend drawing out tables in a notebook to really hammer home some of the ideas presented in this blog post. And feel free to play around in the SQLFiddle examples provided. It&#8217;s a pretty great tool.</p><p></p><p><em><strong>Related articles</strong></em></p><ul><li><p><a href="https://coderbyte.com/algorithm/tree-traversal-algorithms">Tree Traversal Algorithms</a></p></li><li><p><a href="https://www.fusionbox.com/blog/detail/graph-algorithms-in-a-database-recursive-ctes-and-topological-sort-with-postgres/620/">Graph Algorithms in a Database: Recursive CTEs and Topological Sort in Postgres</a> </p></li><li><p><a href="https://hashrocket.com/blog/posts/understanding-common-table-expressions-with-fizzbuzz">Understanding Common Table Expressions with FizzBuzz</a> </p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[A Swift Read: Understanding and Using Optionals]]></title><description><![CDATA[Originally published 11/8/2016 on the DevMynd blog.]]></description><link>https://www.lifeasalgorithm.com/p/a-swift-read-understanding-and-using</link><guid isPermaLink="false">https://www.lifeasalgorithm.com/p/a-swift-read-understanding-and-using</guid><dc:creator><![CDATA[Ifu Aniemeka]]></dc:creator><pubDate>Sun, 21 Dec 2025 00:09:55 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rBqR!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9030814c-8767-4ca0-bc18-14977654def7_144x144.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Originally published 11/8/2016 on the DevMynd <a href="https://www.devmynd.com/blog/">blog</a>.</em></p><h3>Optionals: The Basics</h3><p>In Swift, the optional type is used to indicate that a variable (or constant) might not hold a value, i.e. that it might equal <code>nil</code>. Based on this, you may suspect that a non-optional variable cannot be assigned a value of <code>nil</code>, and you would be correct.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mqvy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mqvy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!mqvy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!mqvy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!mqvy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mqvy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png" width="812" height="144" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:144,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:29714,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mqvy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!mqvy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!mqvy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!mqvy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23fd521b-fb15-406e-83a1-cd24b0e07a2e_812x144.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p></p><p>You might be wondering if you can make use of type inference and simply assign <code>nil</code> to a variable for which no type has been assigned. Nice try but, alas:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eEVJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eEVJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!eEVJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!eEVJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!eEVJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eEVJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png" width="812" height="144" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:144,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:28003,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eEVJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!eEVJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!eEVJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!eEVJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ed05685-8be7-4f65-b2fe-6f5e9f8f521e_812x144.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><p></p><p>The compiler is trying to infer the type here, but you haven&#8217;t really given it one. You&#8217;ve only indicated that <code>stillCannotBeNil</code> is an optional, not if it&#8217;s an optional <code>String</code> or <code>Int</code> or what have you.</p><p>Anyhow, let&#8217;s go ahead and declare an optional variable:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4dGa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4dGa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!4dGa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!4dGa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!4dGa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4dGa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png" width="812" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:29396,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4dGa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!4dGa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!4dGa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!4dGa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5341e88-ef5a-4db8-916c-7b829e24a022_812x167.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>We could also make the declaration like so:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QaZ9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QaZ9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!QaZ9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!QaZ9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!QaZ9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QaZ9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png" width="812" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:31322,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QaZ9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!QaZ9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!QaZ9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!QaZ9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa46ec3f6-5b87-4807-b759-4bf56a260b20_812x167.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Optional declarations can be formally declared with <code>Optional&lt;TypeName&gt;</code> as well as the provided syntactic sugar in the form of <code>TypeName?</code>. Either way is acceptable, but be aware that the latter is more common.</p><p>You&#8217;ll note in the example above that <code>canTotesBeNil</code> can totes be <code>nil</code> and, in fact, is <code>nil</code>. When you declare an optional variable, its default value is <code>nil</code>.</p><p>Let&#8217;s assign a value to <code>canTotesBeNil</code> and print it out.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FAKS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FAKS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!FAKS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!FAKS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!FAKS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FAKS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png" width="812" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37894,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FAKS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!FAKS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!FAKS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!FAKS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F747a61e5-d164-4d55-8c53-517cad2b28de_812x167.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Gross.</p><p>What&#8217;s happening here? If an optional is equal to <code>nil</code>, then you can go ahead and treat it as you&#8217;d expect. However, if an optional has a non-nil value, you have to unwrap it using the force-unwrap operator (<code>!</code>) to get access to its value.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AWmA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AWmA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!AWmA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!AWmA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!AWmA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AWmA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png" width="812" height="144" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:144,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26408,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AWmA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!AWmA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!AWmA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!AWmA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf524dd5-b085-413c-81ef-2ecaebfb402e_812x144.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Boom!</p><p>This works great when <code>canTotesBeNil</code> is totes not <code>nil</code>. If <code>canTotesBeNil</code> is totes <code>nil</code>, there&#8217;s some awfulness.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tYb7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tYb7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png 424w, https://substackcdn.com/image/fetch/$s_!tYb7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png 848w, https://substackcdn.com/image/fetch/$s_!tYb7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png 1272w, https://substackcdn.com/image/fetch/$s_!tYb7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tYb7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png" width="812" height="190" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:190,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:39517,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tYb7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png 424w, https://substackcdn.com/image/fetch/$s_!tYb7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png 848w, https://substackcdn.com/image/fetch/$s_!tYb7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png 1272w, https://substackcdn.com/image/fetch/$s_!tYb7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a034781-d107-4f37-a97c-72ba109f3d35_812x190.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>One way to get around this would be to check if <code>canTotesBeNil</code> is equal to <code>nil</code> before unwrapping it.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vuzl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vuzl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png 424w, https://substackcdn.com/image/fetch/$s_!Vuzl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png 848w, https://substackcdn.com/image/fetch/$s_!Vuzl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png 1272w, https://substackcdn.com/image/fetch/$s_!Vuzl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vuzl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png" width="812" height="214" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b99976ff-49f4-4791-91da-ce4703186e74_812x214.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:214,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:35947,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Vuzl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png 424w, https://substackcdn.com/image/fetch/$s_!Vuzl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png 848w, https://substackcdn.com/image/fetch/$s_!Vuzl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png 1272w, https://substackcdn.com/image/fetch/$s_!Vuzl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb99976ff-49f4-4791-91da-ce4703186e74_812x214.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>There&#8217;s a simpler way to do this that we&#8217;ll talk about later.</p><p>At this point, you&#8217;re probably wondering about optional constants and when in the heck you&#8217;d ever use them.</p><p>I mean, you&#8217;d likely never do something like this:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7b_F!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7b_F!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png 424w, https://substackcdn.com/image/fetch/$s_!7b_F!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png 848w, https://substackcdn.com/image/fetch/$s_!7b_F!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png 1272w, https://substackcdn.com/image/fetch/$s_!7b_F!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7b_F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png" width="812" height="121" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:121,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22932,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7b_F!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png 424w, https://substackcdn.com/image/fetch/$s_!7b_F!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png 848w, https://substackcdn.com/image/fetch/$s_!7b_F!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png 1272w, https://substackcdn.com/image/fetch/$s_!7b_F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b5a7931-7cd4-4325-9ce2-e2067ac9bda0_812x121.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You would more likely use them in cases where a method returns an optional value and you have no intention of changing said value.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CG78!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CG78!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png 424w, https://substackcdn.com/image/fetch/$s_!CG78!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png 848w, https://substackcdn.com/image/fetch/$s_!CG78!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png 1272w, https://substackcdn.com/image/fetch/$s_!CG78!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CG78!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png" width="812" height="260" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/473ac24f-672c-4da7-90a4-54df5c261775_812x260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:260,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45642,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CG78!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png 424w, https://substackcdn.com/image/fetch/$s_!CG78!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png 848w, https://substackcdn.com/image/fetch/$s_!CG78!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png 1272w, https://substackcdn.com/image/fetch/$s_!CG78!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F473ac24f-672c-4da7-90a4-54df5c261775_812x260.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>So that&#8217;s optionals in a nutshell.</p><p>Right now optionals probably seem like some pain-in-the-ass BS, what with having to constantly check if they have a value and the insulting error messages they give you. Fortunately, Swift provides a number of ways to avoid peppering your code with <code>if myOptional != nil</code>.</p><p></p><h3>Optionals and Control Flow</h3><p>So, if you want to run one bit of code when your optional has a value, and another when it doesn&#8217;t, Swift has you covered with optional binding. Optional binding allows you to check for and assign the value of an optional</p><p>You see this mess?</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!B68y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!B68y!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png 424w, https://substackcdn.com/image/fetch/$s_!B68y!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png 848w, https://substackcdn.com/image/fetch/$s_!B68y!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png 1272w, https://substackcdn.com/image/fetch/$s_!B68y!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!B68y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png" width="812" height="260" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:260,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:48273,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!B68y!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png 424w, https://substackcdn.com/image/fetch/$s_!B68y!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png 848w, https://substackcdn.com/image/fetch/$s_!B68y!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png 1272w, https://substackcdn.com/image/fetch/$s_!B68y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb6f866a-2d73-4059-962f-f67c833c9b10_812x260.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>This is lame and you shouldn&#8217;t do it. Instead, use optional binding:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!slac!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!slac!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png 424w, https://substackcdn.com/image/fetch/$s_!slac!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png 848w, https://substackcdn.com/image/fetch/$s_!slac!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png 1272w, https://substackcdn.com/image/fetch/$s_!slac!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!slac!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png" width="812" height="237" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:237,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45674,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!slac!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png 424w, https://substackcdn.com/image/fetch/$s_!slac!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png 848w, https://substackcdn.com/image/fetch/$s_!slac!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png 1272w, https://substackcdn.com/image/fetch/$s_!slac!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa1f41d-c342-47cc-86ae-f697299e0b24_812x237.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Notice anything special about the print statement on line 2? We didn&#8217;t have to force unwrap the argument to <code>print</code>. If <code>methodThatReturnsAnOptionalString()</code> returns a non-nil optional, then <code>textToPrint</code> is set to that value. Otherwise, the code in the <code>else</code> branch is executed.</p><p>There is one gotcha, however. The variable declaration after the <code>if</code> is not a normal declaration. <code>textToPrint</code> is only available in the first branch of the conditional. If you attempt to use it in the <code>else</code> branch or outside of the conditional, you will get an error.</p><p>Optional binding also allows for variables, meaning you can do this:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6ZLr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6ZLr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!6ZLr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!6ZLr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!6ZLr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6ZLr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png" width="812" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:31947,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6ZLr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!6ZLr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!6ZLr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!6ZLr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d9e597e-32a5-4912-9fb4-7add6f27d1b5_812x167.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Note, however, that if <code>textToPrint</code> is never mutated you will get an error from the compiler asking you to change it to a constant.</p><p>You can also make use of optional binding in <code>guard</code> statements.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!V2YN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!V2YN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png 424w, https://substackcdn.com/image/fetch/$s_!V2YN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png 848w, https://substackcdn.com/image/fetch/$s_!V2YN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png 1272w, https://substackcdn.com/image/fetch/$s_!V2YN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!V2YN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png" width="812" height="237" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:237,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43815,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!V2YN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png 424w, https://substackcdn.com/image/fetch/$s_!V2YN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png 848w, https://substackcdn.com/image/fetch/$s_!V2YN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png 1272w, https://substackcdn.com/image/fetch/$s_!V2YN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa05f8597-4f33-4f36-b0eb-69b26429c8e1_812x237.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Optional binding in the context of a guard statement is a little different. Unlike the <code>if</code> conditional above, <code>textToPrint</code> is only available outside of the <code>guard</code> statement. Hence, we&#8217;re able to print it.</p><p></p><h3>Nil-Coalescing Operator</h3><p>Let&#8217;s say you would like to set a variable to the value of an optional if the optional is non-nil or to a default value if it&#8217;s <code>nil</code>. You can accomplish this using the ternary operator.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!niob!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!niob!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png 424w, https://substackcdn.com/image/fetch/$s_!niob!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png 848w, https://substackcdn.com/image/fetch/$s_!niob!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png 1272w, https://substackcdn.com/image/fetch/$s_!niob!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!niob!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png" width="812" height="190" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:190,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:41685,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!niob!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png 424w, https://substackcdn.com/image/fetch/$s_!niob!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png 848w, https://substackcdn.com/image/fetch/$s_!niob!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png 1272w, https://substackcdn.com/image/fetch/$s_!niob!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a2ca769-0ddf-4f36-93aa-5baa7d2ffcdc_812x190.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Alternatively, you could make use of the nil-coalescing operator.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Jtv_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Jtv_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png 424w, https://substackcdn.com/image/fetch/$s_!Jtv_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png 848w, https://substackcdn.com/image/fetch/$s_!Jtv_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png 1272w, https://substackcdn.com/image/fetch/$s_!Jtv_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Jtv_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png" width="812" height="121" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:121,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:23311,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Jtv_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png 424w, https://substackcdn.com/image/fetch/$s_!Jtv_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png 848w, https://substackcdn.com/image/fetch/$s_!Jtv_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png 1272w, https://substackcdn.com/image/fetch/$s_!Jtv_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64f57f69-8c4c-4078-ac65-50f92e791845_812x121.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>If the optional is not <code>nil</code>, the nil-coalescing operator will assign its value to <code>getStuff</code>. If the optional is <code>nil</code>,  <code>getStuff</code> is assigned the provided default. One potential gotcha lies in a type mismatch between the optional and the default. The default must be of the same type as the optional. For instance, you couldn&#8217;t do something like this:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TcTF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TcTF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png 424w, https://substackcdn.com/image/fetch/$s_!TcTF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png 848w, https://substackcdn.com/image/fetch/$s_!TcTF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png 1272w, https://substackcdn.com/image/fetch/$s_!TcTF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TcTF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png" width="812" height="190" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:190,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:44954,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TcTF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png 424w, https://substackcdn.com/image/fetch/$s_!TcTF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png 848w, https://substackcdn.com/image/fetch/$s_!TcTF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png 1272w, https://substackcdn.com/image/fetch/$s_!TcTF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4cc87ef-5f37-45e0-b722-96284e299bc2_812x190.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Ouch.</p><p></p><h3>Optional Chaining</h3><p>What about situations in which you want to call a property or method on an optional? You might, for instance, want to get the size of an optional array. In order to do that, however, you&#8217;d have to force unwrap it, potentially triggering an ego-obliterating error.</p><p>Optional chaining lets you call whatever properties or methods you would like to on an optional and to get back <code>nil</code> if the optional is empty.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!V8ok!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!V8ok!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png 424w, https://substackcdn.com/image/fetch/$s_!V8ok!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png 848w, https://substackcdn.com/image/fetch/$s_!V8ok!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png 1272w, https://substackcdn.com/image/fetch/$s_!V8ok!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!V8ok!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png" width="812" height="190" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:190,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:35503,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!V8ok!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png 424w, https://substackcdn.com/image/fetch/$s_!V8ok!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png 848w, https://substackcdn.com/image/fetch/$s_!V8ok!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png 1272w, https://substackcdn.com/image/fetch/$s_!V8ok!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520a78bb-50e7-4ff0-9f72-269a36c3758a_812x190.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>In contrast to the force-unwrap operator, which has no chill, the question mark operator loves and accepts you for who you are and does not trigger an error.</p><p>One important thing to note is that optional chaining always returns an optional value, given that its result could be <code>nil</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!v71z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!v71z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png 424w, https://substackcdn.com/image/fetch/$s_!v71z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png 848w, https://substackcdn.com/image/fetch/$s_!v71z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png 1272w, https://substackcdn.com/image/fetch/$s_!v71z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!v71z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png" width="812" height="237" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:237,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43190,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!v71z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png 424w, https://substackcdn.com/image/fetch/$s_!v71z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png 848w, https://substackcdn.com/image/fetch/$s_!v71z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png 1272w, https://substackcdn.com/image/fetch/$s_!v71z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e748951-f3b1-47ca-a1b8-225e3e5d504c_812x237.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>I imagine some part of you wants to write something like this to get ahold of the value of <code>count</code> directly:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yqPa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yqPa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!yqPa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!yqPa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!yqPa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yqPa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png" width="812" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:35416,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yqPa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!yqPa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!yqPa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!yqPa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc09a6c7-f0db-47e7-8738-26dc9c6d9dc3_812x167.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>I see what you&#8217;re trying to do, but the above will bring the wrath of the compiler upon you. What you&#8217;re actually aiming for is</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Bqb7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bqb7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png 424w, https://substackcdn.com/image/fetch/$s_!Bqb7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png 848w, https://substackcdn.com/image/fetch/$s_!Bqb7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png 1272w, https://substackcdn.com/image/fetch/$s_!Bqb7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bqb7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png" width="812" height="121" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:121,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21536,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Bqb7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png 424w, https://substackcdn.com/image/fetch/$s_!Bqb7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png 848w, https://substackcdn.com/image/fetch/$s_!Bqb7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png 1272w, https://substackcdn.com/image/fetch/$s_!Bqb7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2921cfa3-35f8-4f4b-a78c-c7852ee76044_812x121.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><h3>Implicitly Unwrapped Optionals</h3><p>It&#8217;s likely you won&#8217;t make much use of implicitly unwrapped optionals outside of class initialization. I don&#8217;t want to get too deep into classes, but we&#8217;ll talk about them briefly here.</p><p>Implicitly unwrapped optionals are used whenever you are absolutely, positively sure that your application will not make any attempt to get an optional&#8217;s value before it has been set. Implicitly unwrapped optionals are kinda unsafe, so you want to be <em>dead certain</em> that they&#8217;re what you want. If you&#8217;re not sure, just use a plain old optional.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SXm6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SXm6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!SXm6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!SXm6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!SXm6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SXm6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png" width="812" height="144" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/60918831-5f66-4ced-94fb-022bd20ce256_812x144.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:144,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:28042,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SXm6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!SXm6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!SXm6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!SXm6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60918831-5f66-4ced-94fb-022bd20ce256_812x144.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Note the absence of the force-unwrap operator in the <code>print</code> statement. That&#8217;s because <code>dangerString</code> has been unwrapped for you.</p><p>Keep in mind, though, that if you were to try to print <code>dangerString</code> without first giving it a value (or if, like some kind of adrenaline-junkie, you set it to <code>nil</code> later), you would get an error. That&#8217;s what makes implicit unwrapping so dangerous. So, you know, be careful.</p><p></p><h3>Optionals in the Wild</h3><p>Try to keep in mind that optionals will always be used whenever it is possible that a value will not be present. That&#8217;s not simply a guideline for how you should write your own code, but a general rule for what you should expect when interacting with Swift objects. For instance, if you try to receive a value from a dictionary, you will get an optional.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ppBt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ppBt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!ppBt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!ppBt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!ppBt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ppBt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png" width="812" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32068,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ppBt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png 424w, https://substackcdn.com/image/fetch/$s_!ppBt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png 848w, https://substackcdn.com/image/fetch/$s_!ppBt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png 1272w, https://substackcdn.com/image/fetch/$s_!ppBt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d78888d-1e47-4bd6-9c50-0e18457fbe3a_812x167.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Similarly, if you attempt to convert a <code>String</code> to an <code>Int</code> using the <code>Int</code> initializer, you get an optional.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hlvZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hlvZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!hlvZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!hlvZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!hlvZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hlvZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png" width="812" height="144" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:144,&quot;width&quot;:812,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27604,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.lifeasalgorithm.com/i/182193508?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hlvZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png 424w, https://substackcdn.com/image/fetch/$s_!hlvZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png 848w, https://substackcdn.com/image/fetch/$s_!hlvZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png 1272w, https://substackcdn.com/image/fetch/$s_!hlvZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5d513c9-01c0-4d4b-8172-ae84d213a83e_812x144.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Optionals. Optionals everywhere.</p><p></p><h3>Get Swifty</h3><p>Great. So&#8230;get out there and use some optionals. Be super inspired. Be the best. Dream big. Swift hard. Good night.</p><p></p>]]></content:encoded></item><item><title><![CDATA[TIL Compilation]]></title><description><![CDATA[A Collection of Today I Learned Posts]]></description><link>https://www.lifeasalgorithm.com/p/til-compilation</link><guid isPermaLink="false">https://www.lifeasalgorithm.com/p/til-compilation</guid><dc:creator><![CDATA[Ifu Aniemeka]]></dc:creator><pubDate>Tue, 07 Oct 2025 00:49:48 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rBqR!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9030814c-8767-4ca0-bc18-14977654def7_144x144.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here I&#8217;ve put together a bunch of my Today I Learned posts from way back when. I started writing these when I worked for <a href="https://til.hashrocket.com/">Hashrocket</a>. </p><p>For those not familiar with the TIL format, it&#8217;s a short blog post wherein you describe something you learned recently. It doesn&#8217;t have to be anything terribly impressive. It could be some obscure Ruby method you discovered or a neat thing you can do with Git. It&#8217;s a fun way to catalogue the small facts you learn everyday.</p><p></p><h4>Today I Learned: Squeaky Clean Anaconda Environments</h4><p><em>originally published 7/24/2017 on the Hashrocket TIL blog</em></p><p>To delete packages, caches, and other files that aren&#8217;t being used in any of your environments run:</p><pre><code>conda clean -a -y</code></pre><p>The <code>-a </code>flag is to delete all unused files and the <code>-y</code> option runs the <code>clean</code> command without asking for confirmation.</p><p>If you want to know what files would be deleted before actually deleting them, run:</p><pre><code>conda clean -a --dry-run</code></pre><p></p><h4>Today I Learned: Keep Your Brews Bubbly</h4><p><em>originally published 8/25/2017 on the Hashrocket TIL blog</em></p><p>Life is too short to have Homebrew problems. Run these commands to keep your brews bubbly.</p><p>Checks your system to make sure that future installs go smoothly:</p><pre><code>brew doctor</code></pre><p>Upgrades Homebrew to the latest version:</p><pre><code>brew update</code></pre><p>Gets a list of what packages are outdated:</p><pre><code>brew outdated</code></pre><p>Looks through your installed packages and deletes any old versions that may still be hanging around:</p><pre><code>brew cleanup</code></pre><p>You could alternatively add the <code>--dry-run</code> flag to <code>cleanup</code> to see all the outdated packages that would be removed.</p><p>Deletes old symlinks:</p><pre><code>brew prune</code></pre><p>Updates packages to the latest version:</p><pre><code>brew upgrade</code></pre><p>You can add the <code>--cleanup</code> flag to delete older versions of the packages you are updating.</p><h4>Today I Learned: Viewing the Git Leaderboard</h4><p><em>Originally published 8/31/2017 on the Hashrocket TIL blog</em></p><p>Everyone knows that writing code is a competition in which she with the most commits wins. So, obviously, you want to periodically check the leaderboard to see who the 10x developer on the team is.</p><p>How do you do that?</p><pre><code>git shortlog</code></pre><p>This will give you a list of all the contributors to the repository and the number of commits they have made. You can add the <code>-s</code> flag (for &#8216;summary&#8217;) to just see names and numbers.</p><p>Once you have acquired the evidence that you are indeed the mythical 10x developer, demand a raise from your employer and threaten to go work for Google if you don&#8217;t get it.</p><p>If you already work for Google, threaten to...I don&#8217;t know, get a job at Space X or something.</p><p></p><h4>Today I Learned: Ruby Binding Class</h4><p><em>originally published 10/16/2017 on the Hashrocket TIL blog</em></p><p>Ruby&#8217;s Binding class allows you to access classes, variables, and methods outside of your current scope.</p><pre><code>class Foo

&#9;def bar

&#9;&#9;my_var = 20

&#9;&#9;binding()

&#9;end

end</code></pre><p>Normally, if you made reference to <code>my_var</code> outside of that method, you&#8217;d get an error.</p><p>Binding objects allow you to do this:</p><pre><code>my_foo = Foo.new

foo_bar = my_foo.bar

puts foo_bar.eval(&#8217;my_var&#8217;)

# 20</code></pre><p></p><h4>Today I Learned: Hi, Sierra</h4><p><em>originally published 11/25/2017 on the Hashrocket TIL blog</em></p><p>I recently upgraded my Mac to High Sierra and got this gross message when I tried to use Git:</p><pre><code>xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun</code></pre><p>My machine was expecting Git to be implemented as an Xcode command line tool. To fix the problem, I simply installed Xcode. </p><pre><code>xcode-select --install</code></pre><p></p><h4>Today I Learned: Aliasing an Elixir Module Within Itself</h4><p><em>originally published 1/26/2018 on the Hashrocket TIL blog</em></p><p>I was attempting to compile a Phoenix application and I got this error: </p><pre><code>Post.__struct__/0 is undefined, cannot expand struct Post</code></pre><p>The issue was in a function I defined in the module.</p><pre><code>def changeset(%Post{}= post, attrs \\ %{}) do

    ...

end</code></pre><p>I assumed that you would get references to a module within said module for free. That&#8217;s not the case.</p><p>There are two ways to fix the error. One is to use the full module name in the parameter list.</p><pre><code>def changeset(%Forum.Post{}= post, attrs \\ %{}) do

    ...

end</code></pre><p>Alternatively, I can alias the module within itself.</p><pre><code>alias Forum.Post</code></pre><p></p><h4>Today I Learned: Prying Open Your Phoenix App</h4><p><em>originally published 1/29/2018 on the Hashrocket TIL blog</em></p><p>I wanted to do some debugging in a Phoenix app, so I threw <code>require IEx</code> and <code>IEx.pry()</code> into my code, only to receive the following error:</p><pre><code>Cannot pry
...

Is an IEx shell running?</code></pre><p>In order to pry into your code, you&#8217;ll have to start the server from within the Elixir shell.</p><pre><code>iex -S mix phx.server</code></pre><p></p><h4>Today I Learned: Phoenix Select Form Helper</h4><p><em>originally published 1/30/2018 on the Hashrocket TIL blog</em></p><p>The <code>select</code> form helper allows you to easily add a select input to your forms. </p><pre><code>= form_for @changeset, resource_path(@conn, :create), fn f -&gt;

  = select f, :book_id, @books

  = submit &#8220;Save Post&#8221;, class: &#8220;btn&#8221;</code></pre><p>Among the types of arguments that the <code>select</code> helper can accept are two-item tuples. The first item in the tuple is used as the label for the option and the second item is used as the value for the option.</p><p><code>Media.list_books</code> returns a list of structs representing all of the books in the database. We&#8217;ll need to get from a list of structs to a list of tuples. </p><p>To do that, we&#8217;ll pipe the list of <code>Book</code> structs to <code>Enum.map</code> and use an anonymous function to generate two-value tuples from those structs. </p><p></p><pre><code>def new(conn, _params)

  ...

  books =

    Media.list_books

      |&gt; Enum.map(&amp;{&#8221;#{&amp;1.title} by #{&amp;1.author}&#8221;, &amp;1.id})

  render conn, &#8220;new.html&#8221;, changeset: changeset, books: books

end</code></pre><p></p><h4>Today I Learned: Little Bits</h4><p><em>originally published 4/25/2018 on the Hashrocket TIL blog</em></p><p>4 bits (or half a byte) is referred to as a &#8220;nibble&#8221;. </p><p></p><h4>Today I Learned: Truncating Floats in Elixir</h4><p><em>originally published 4/26/2018 on the Hashrocket TIL blog</em></p><p>To remove everything after the decimal point in a floating-point number, use <code>Kernel.trunc/1</code>.</p><pre><code>iex&gt; Kernel.trunc(3.141)

3

iex&gt; Kernel.trunc(-3.141)

-3</code></pre><p>Alternatively, you can simply type <code>trunc</code></p><pre><code>iex&gt; trunc(3.141)

3</code></pre><p></p><h4>Today I Learned: Elixir String Manipulation</h4><p><em>originally published 4/26/2018 on the Hashrocket TIL blog</em></p><p>To get the list of strings that compose a longer string, use <code>String.codepoints/1</code></p><pre><code>iex&gt; cdp =  String.codepoints(&#8221;abcdefg&#8221;)

[&#8221;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;, &#8220;d&#8221;, &#8220;e&#8221;, &#8220;f&#8221;, &#8220;g&#8221;]

iex&gt; Enum.at(cdp, 0)

&#8220;a&#8221;</code></pre><p>To get the list of codepoints that represent each letter in the string, use <code>String.to_charlist/1</code></p><pre><code>iex&gt; chr = String.to_charlist(&#8221;abcdefg&#8221;)

&#8216;abcdefg&#8217;

iex&gt; Enum.at(chr, 0)

97</code></pre><p></p><h4>Today I Learned: Capturing Frames from Video Files</h4><p><em>originally published 8/6/2018</em></p><p>First head over <a href="https://www.ffmpeg.org/">here</a> to download FFMPEG. If you happen to be a Mac user, you can use Homebrew:</p><pre><code>brew install ffmpeg</code></pre><p>I would check out the Homebrew <a href="https://formulae.brew.sh/formula/ffmpeg">page</a> for all of the options available (of which, there are quite a few).</p><p>To extract frames from a video file, you use the following command:</p><pre><code>ffmpeg -i my_vid.webm -r 10 -frames:v 30 -f image2 foo-%03d.jpeg</code></pre><p>The above command extracts 10 frames per second and saves them as jpeg files with names &#8216;foo-001.jpeg&#8217;, &#8216;foo-002.jpeg&#8217;, and so on. The maximum number of images that will be created is 30. `image2` refers to the demuxer used. </p><p>You can read more about this in the <a href="https://www.ffmpeg.org/ffmpeg.html#Video-and-Audio-file-format-conversion">documentation</a>.</p><p></p><p></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[Intro: Life As Algorithm]]></title><description><![CDATA[Welcome to my blog]]></description><link>https://www.lifeasalgorithm.com/p/intro-life-as-algorithm</link><guid isPermaLink="false">https://www.lifeasalgorithm.com/p/intro-life-as-algorithm</guid><dc:creator><![CDATA[Ifu Aniemeka]]></dc:creator><pubDate>Tue, 07 Oct 2025 00:28:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rBqR!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9030814c-8767-4ca0-bc18-14977654def7_144x144.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>My name&#8217;s Ifu. This is my blog. </p><p>I talk about tech, comedy, martial arts, and other things. </p><p> </p>]]></content:encoded></item></channel></rss>