<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bryan Acosta</title>
    <description>The latest articles on DEV Community by Bryan Acosta (@bryanacosta).</description>
    <link>https://dev.to/bryanacosta</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F584652%2Fb24300fb-fddb-420e-8879-45604ff55706.png</url>
      <title>DEV Community: Bryan Acosta</title>
      <link>https://dev.to/bryanacosta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bryanacosta"/>
    <language>en</language>
    <item>
      <title>Build Once, Sell Twice: caching LLM analysis with pgvector</title>
      <dc:creator>Bryan Acosta</dc:creator>
      <pubDate>Thu, 07 May 2026 19:53:23 +0000</pubDate>
      <link>https://dev.to/bryanacosta/build-once-sell-twice-caching-llm-analysis-with-pgvector-5eh8</link>
      <guid>https://dev.to/bryanacosta/build-once-sell-twice-caching-llm-analysis-with-pgvector-5eh8</guid>
      <description>&lt;p&gt;A few months ago I was staring at a spreadsheet trying to figure out why our unit economics looked terrible. Every new AI feature was increasing revenue — and quietly destroying our margins.&lt;/p&gt;

&lt;p&gt;The product details don't matter but the shape will be familiar to anyone building AI-powered features. Imagine you're building an Instagram DM CRM that qualifies leads, scores intent, drafts follow-ups, and alerts sales reps when hot leads land. Customers pay per seat, plus add-ons like pipeline reports or lead reactivation audits. Each DM costs ~$0.02 to analyze with AI.&lt;/p&gt;

&lt;p&gt;The product looks simple on paper and the unit economics look fine.&lt;br&gt;
Then you notice something. The same DM gets analyzed when it first comes in. Then again on Monday when the customer pulls the "Weekly Pipeline Report". Then again on Friday when someone runs the "Hot Leads Audit". Different angles, different prompts, but the underlying message is the same and you're paying the LLM to re-read the exact same "hey is this still available?" three times in one week. The more your customers engage, the more your margin bleeds.&lt;/p&gt;

&lt;p&gt;This is the story of how &lt;code&gt;pgvector&lt;/code&gt; becomes the cheapest line item on your balance sheet.&lt;/p&gt;
&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Every DM that comes in, regardless of which features the customer eventually pays for, gets a free embedding:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;dm_analysis&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dm_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;embedding&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;-- everything else (intent, qualification, summary...) stays NULL&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. One row, one 1536-dim vector from &lt;code&gt;text-embedding-3-small&lt;/code&gt;, ~$0.000003 per DM, generated synchronously on intake. By the time a customer queries, every DM already has its row. You absorb the embedding cost as infrastructure. Why? Because if the customer ever runs a semantic search ("show me leads like the one that just closed") or asks a chatbot a question, you want 100% of their DMs discoverable — not just the slice they've paid to deeply analyze.&lt;/p&gt;

&lt;p&gt;The schema looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;dm_analysis&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;analysis_id&lt;/span&gt;          &lt;span class="n"&gt;UUID&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;gen_random_uuid&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="n"&gt;dm_id&lt;/span&gt;                &lt;span class="n"&gt;UUID&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;dms&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dm_id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="c1"&gt;-- expensive fields, filled when the LLM runs:&lt;/span&gt;
    &lt;span class="n"&gt;intent&lt;/span&gt;               &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;qualification_score&lt;/span&gt;  &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;fit_label&lt;/span&gt;            &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;urgency_level&lt;/span&gt;        &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;summary&lt;/span&gt;              &lt;span class="nb"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;-- always filled, free:&lt;/span&gt;
    &lt;span class="n"&gt;embedding&lt;/span&gt;            &lt;span class="n"&gt;VECTOR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1536&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt;           &lt;span class="nb"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;NOW&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_analysis_embedding&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;dm_analysis&lt;/span&gt;
    &lt;span class="k"&gt;USING&lt;/span&gt; &lt;span class="n"&gt;hnsw&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;embedding&lt;/span&gt; &lt;span class="n"&gt;vector_cosine_ops&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trick: a &lt;code&gt;dm_analysis&lt;/code&gt; row with a filled &lt;code&gt;summary&lt;/code&gt; means you paid an LLM for it. A row with only &lt;code&gt;embedding&lt;/code&gt; means you haven't yet. The schema &lt;em&gt;is&lt;/em&gt; the cache.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "target vector" trick
&lt;/h2&gt;

&lt;p&gt;When a customer triggers the "Hot Leads This Week" report, you don't dump every DM of the week into an LLM. That'd be wasteful, slow, and noisy. Instead, you build a &lt;strong&gt;target vector&lt;/strong&gt; for the report type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reportVector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;embed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I'm ready to buy this week. We have budget approved. Need to make a decision soon.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Match the shape of your target text to the shape of your data. DMs are prose, so the target vector should be prose too, embedding a keyword bag against natural messages produces fuzzier matches.&lt;/p&gt;

&lt;p&gt;Then you let Postgres find the 50 DMs most relevant to that intent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dm_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;da&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;da&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;qualification_score&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;dms&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;dm_analysis&lt;/span&gt; &lt;span class="n"&gt;da&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;da&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dm_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dm_id&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tenant_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;received_at&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="c1"&gt;-- this week&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;da&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;embedding&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;  &lt;span class="c1"&gt;-- cosine distance to target&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cost of this query: $0. Time: ~50ms with the HNSW index, even at hundreds of thousands of DMs.&lt;/p&gt;

&lt;p&gt;Now here's the part that turns the business around.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build once, sell twice
&lt;/h2&gt;

&lt;p&gt;When those 50 DMs come back, you split them into two piles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enriched&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// already paid for&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;raw&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// need LLM&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You only pay the LLM for &lt;code&gt;raw&lt;/code&gt;. The &lt;code&gt;enriched&lt;/code&gt; DMs — analyzed by some other feature, days or weeks ago — come back for free. Their intent, qualification score, and summary are already in &lt;code&gt;dm_analysis&lt;/code&gt;, sitting in Postgres, waiting.&lt;/p&gt;

&lt;p&gt;The compounding works because target vectors for related features overlap heavily — the "Hot Leads" report and the "Pipeline Deep Dive" both surface high-intent DMs, even though the prompts ask different questions. Different framings, same source material.&lt;/p&gt;

&lt;p&gt;The first time a customer runs a report, all 50 DMs might be raw. Cost: $1.00.&lt;/p&gt;

&lt;p&gt;By the third report, maybe 30 of the 50 retrieved are already enriched (because they were relevant to &lt;em&gt;some&lt;/em&gt; previous feature run and got paid for then). Cost drops to $0.40.&lt;/p&gt;

&lt;p&gt;By month three, on a "Monthly Pipeline Deep Dive" pulling 200 DMs, 150 of them are typically already enriched. Cost: $1.00 instead of $4.00.&lt;/p&gt;

&lt;p&gt;The tendency is monotonic: the more a customer engages, the cheaper each subsequent run becomes for you. The LLM bill grows sublinearly while revenue grows linearly. That's the whole game.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why pgvector specifically
&lt;/h2&gt;

&lt;p&gt;Three reasons not to reach for Pinecone or Weaviate here:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One database.&lt;/strong&gt; The embedding lives in the same row as the structured analysis. The same JOIN that filters by &lt;code&gt;tenant_id&lt;/code&gt; (for row-level tenancy) also filters the vector search. No two-phase commits, no "find IDs in Pinecone, fetch rows from Postgres" dance, no consistency window where a DM exists in one system and not the other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The cache is a column, not a service.&lt;/strong&gt; &lt;code&gt;WHERE summary IS NOT NULL&lt;/code&gt; distinguishes an enriched DM from a raw one. There's no separate metadata store to keep in sync. When the LLM finishes, an &lt;code&gt;UPDATE&lt;/code&gt; happens, and that's the entire state transition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HNSW is good enough.&lt;/strong&gt; At reasonable scale — say a million DMs per tenant in the worst case — &lt;code&gt;pgvector&lt;/code&gt;'s HNSW index returns top-50 in single-digit milliseconds. You will not be bottlenecked by vector search. You'll be bottlenecked by your LLM rate limits, by Stripe webhooks, by your own code. Never by the vectors.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;If you're building anything LLM-shaped where the same source data gets re-analyzed for different purposes — reports, dashboards, chatbots, alerts, auto-categorization, lead scoring — the cheapest dollar you'll ever spend is on a &lt;code&gt;VECTOR&lt;/code&gt; column and an HNSW index. Pay the LLM once per piece of content, ever. Let semantic search decide which pieces are relevant to the next question. Let your margin compound.&lt;/p&gt;

&lt;p&gt;The fancy moat isn't the AI. It's the cache.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>postgres</category>
      <category>performance</category>
    </item>
    <item>
      <title>A brief introduction to functional programming concepts in JavaScript</title>
      <dc:creator>Bryan Acosta</dc:creator>
      <pubDate>Fri, 12 Mar 2021 09:47:08 +0000</pubDate>
      <link>https://dev.to/bryanacosta/a-brief-introduction-to-functional-programming-concepts-in-javascript-5bg9</link>
      <guid>https://dev.to/bryanacosta/a-brief-introduction-to-functional-programming-concepts-in-javascript-5bg9</guid>
      <description>&lt;p&gt;Functional programming is a highly valued programming paradigm, so is a way of thinking about software construction by creating pure functions. It avoids concepts of shared state, mutable data observed in Object-Oriented Programming.&lt;/p&gt;

&lt;p&gt;But what are all these buzzwords I'm talking about?&lt;/p&gt;

&lt;p&gt;Well. As everyone knows, functions are pieces of code that can be reused once, and once again, they can receive some inputs, compute that input, and finally return an output, piece of cake, huh?&lt;/p&gt;

&lt;h2&gt;
  
  
  Functional code is characterized by:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The absence of side effects.&lt;/li&gt;
&lt;li&gt;Pure functions.&lt;/li&gt;
&lt;li&gt;Stateless.&lt;/li&gt;
&lt;li&gt;First-class functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's find an easy way to define all these concepts.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a side-effect?
&lt;/h2&gt;

&lt;p&gt;Side-effects are the process of modifying any variable or object property (e.g., a global variable, or a variable in the parent function scope chain).&lt;/p&gt;

&lt;p&gt;Another side-effect would be print something into the console.&lt;br&gt;
No having side effects means that the function doesn't change the outer world.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a pure function?
&lt;/h2&gt;

&lt;p&gt;A pure function is a function which:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Take its input and use that and only that to compute an output and then return it.&lt;/li&gt;
&lt;li&gt;They can't use variables either functions out of their scope.&lt;/li&gt;
&lt;li&gt;Produces no side effects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Not pure function&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjjrlenyeuxygzew0wbri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjjrlenyeuxygzew0wbri.png" alt="Alt Text" width="800" height="756"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Pure function&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5z1oml3bm4xnaxhyw1rw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5z1oml3bm4xnaxhyw1rw.png" alt="Alt Text" width="800" height="637"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What does stateless mean?
&lt;/h2&gt;

&lt;p&gt;That means values don't mutate.&lt;/p&gt;

&lt;h2&gt;
  
  
  First-class functions.
&lt;/h2&gt;

&lt;p&gt;When functions are treated like any other variable.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For instance:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functions can be stored in variables.&lt;/li&gt;
&lt;li&gt;Passed around as arguments, or even returned from other functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to do functional programming?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Don't iterate, map, filter, and reduce instead.&lt;/li&gt;
&lt;li&gt;Use higher-order functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Higher-order function&lt;/strong&gt;&lt;br&gt;
A higher-order function meets at least one of the following conditions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Takes functions as input.&lt;/li&gt;
&lt;li&gt;Return another function as output.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4kxpbeiceeotr8r8nlqo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4kxpbeiceeotr8r8nlqo.png" alt="Alt Text" width="800" height="718"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Holy Trinity of Functional Programming&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;map() instead of for&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm4fe7zpdr5xti58ff2zj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm4fe7zpdr5xti58ff2zj.png" alt="Alt Text" width="800" height="659"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;map() does not mutate the array, it makes a copy.&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9p4gvm7z56fvetxnzaz6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9p4gvm7z56fvetxnzaz6.png" alt="Alt Text" width="800" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;filter()&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5u7x3k6g50tbf6x8shb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5u7x3k6g50tbf6x8shb.png" alt="Alt Text" width="800" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;reduce() takes an array and return just one reduced element&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu28xoxf1okvbxqeg5s7m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu28xoxf1okvbxqeg5s7m.png" alt="Alt Text" width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of functional programming.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;They don't raise any side-effects.&lt;/li&gt;
&lt;li&gt;Easy to refactor.&lt;/li&gt;
&lt;li&gt;Better encapsulation.&lt;/li&gt;
&lt;li&gt;Increase reusability.&lt;/li&gt;
&lt;li&gt;Modularity.&lt;/li&gt;
&lt;li&gt;Easy to test.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Well, that's all about this brief introduction to functional programming concepts. Thank's for reading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More information about map, filter, and reduce:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;map&lt;/a&gt; &lt;a href="https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/filter" rel="noopener noreferrer"&gt;filter&lt;/a&gt; &lt;a href="https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce" rel="noopener noreferrer"&gt;reduce&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>functional</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
