The refactoring is now published as Slice on sammancoaching.org: https://sammancoaching.org/refactorings/slice.html - git mv ideas/split-loop-with-lambda -> ideas/slice-with-lambda - rename learning-hour file and update frontmatter name - update paths in tools/rehearse scripts and report title - update prose: 'Split Loop with Lambda' -> 'Slice with Lambda' in learning hour, exercise READMEs, storyboard, solution comments - link the published Slice refactoring from the pattern draft
45 lines
3.5 KiB
XML
45 lines
3.5 KiB
XML
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 760 460" font-family="Helvetica, Arial, sans-serif">
|
|
<defs>
|
|
<marker id="arrR" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
|
<path d="M0,0 L10,5 L0,10 z" fill="#dc2626"/>
|
|
</marker>
|
|
<marker id="arrO" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
|
<path d="M0,0 L10,5 L0,10 z" fill="#d97706"/>
|
|
</marker>
|
|
</defs>
|
|
<rect width="760" height="460" fill="#ffffff"/>
|
|
<text x="24" y="34" font-size="20" font-weight="bold" fill="#0f172a">Demo — printSalesForecasts: one loop, three unwanted dependencies</text>
|
|
<text x="24" y="56" font-size="13" fill="#475569">The clock is already out (prep). Count the rest: a static side-channel write, a random re-roll, a value read, and IO.</text>
|
|
|
|
<!-- method -->
|
|
<rect x="60" y="74" width="380" height="250" rx="10" fill="#f8fafc" stroke="#64748b" stroke-width="1.5"/>
|
|
<text x="76" y="98" font-size="14" font-weight="bold" fill="#0f172a">printSalesForecasts()</text>
|
|
|
|
<!-- loop -->
|
|
<rect x="80" y="112" width="340" height="196" rx="8" fill="#eef2ff" stroke="#818cf8"/>
|
|
<text x="94" y="136" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">for (String name : names)</text>
|
|
<text x="94" y="158" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">if (name.equals("Steve"))</text>
|
|
<text x="94" y="180" font-size="11" font-family="Menlo, Consolas, monospace" font-weight="bold" fill="#dc2626"> Scorer.flavour = Strawberry;</text>
|
|
<text x="94" y="202" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">else</text>
|
|
<text x="94" y="224" font-size="11" font-family="Menlo, Consolas, monospace" font-weight="bold" fill="#dc2626"> scorer.updateSelection();</text>
|
|
<text x="94" y="246" font-size="11" font-family="Menlo, Consolas, monospace" font-weight="bold" fill="#dc2626">score = scorer.getSalesForecast();</text>
|
|
<text x="94" y="274" font-size="11" font-family="Menlo, Consolas, monospace" font-weight="bold" fill="#d97706">System.out.println(name + " score: " + score);</text>
|
|
<text x="94" y="298" font-size="10" fill="#64748b">the weather/sales loop</text>
|
|
|
|
<!-- Scorer -->
|
|
<rect x="580" y="110" width="150" height="90" rx="8" fill="#fef2f2" stroke="#dc2626" stroke-width="1.5"/>
|
|
<text x="655" y="140" font-size="14" font-weight="bold" fill="#dc2626" text-anchor="middle">Scorer</text>
|
|
<text x="655" y="160" font-size="11" fill="#7f1d1d" text-anchor="middle">Random + a static</text>
|
|
<text x="655" y="176" font-size="11" fill="#7f1d1d" text-anchor="middle">field (flavour)</text>
|
|
|
|
<line x1="424" y1="180" x2="572" y2="140" stroke="#dc2626" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#arrR)"/>
|
|
<line x1="424" y1="224" x2="572" y2="160" stroke="#dc2626" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#arrR)"/>
|
|
<line x1="424" y1="246" x2="572" y2="182" stroke="#dc2626" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#arrR)"/>
|
|
|
|
<!-- System.out -->
|
|
<rect x="580" y="250" width="150" height="60" rx="8" fill="#fffbeb" stroke="#d97706" stroke-width="1.5"/>
|
|
<text x="655" y="274" font-size="12" font-weight="bold" fill="#d97706" text-anchor="middle">System.out</text>
|
|
<text x="655" y="292" font-size="10" fill="#92400e" text-anchor="middle">IO — next time's split</text>
|
|
<line x1="424" y1="274" x2="572" y2="282" stroke="#d97706" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#arrO)"/>
|
|
</svg>
|