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
48 lines
3.6 KiB
XML
48 lines
3.6 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>
|
|
</defs>
|
|
<rect width="760" height="460" fill="#ffffff"/>
|
|
<text x="24" y="34" font-size="20" font-weight="bold" fill="#0f172a">Step 0 — one method, three loops, one unwanted dependency</text>
|
|
<text x="24" y="56" font-size="13" fill="#475569">The weather loop reaches outside the method to Scorer (which uses Random) — that is why the test is red & flaky.</text>
|
|
|
|
<!-- method -->
|
|
<rect x="60" y="74" width="340" height="356" rx="10" fill="#f8fafc" stroke="#64748b" stroke-width="1.5"/>
|
|
<text x="76" y="98" font-size="14" font-weight="bold" fill="#0f172a">longRangeForecast()</text>
|
|
|
|
<!-- reset loop -->
|
|
<rect x="80" y="112" width="300" height="56" rx="8" fill="#eef2ff" stroke="#818cf8"/>
|
|
<text x="94" y="134" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">for (IceCream flavour : IceCream.values())</text>
|
|
<text x="94" y="154" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b"> result.put(flavour, 0);</text>
|
|
|
|
<!-- weather loop -->
|
|
<rect x="80" y="184" width="300" height="112" rx="8" fill="#eef2ff" stroke="#818cf8"/>
|
|
<text x="94" y="206" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">for (Instant interestingDate : DATES)</text>
|
|
<text x="94" y="228" font-size="11" font-family="Menlo, Consolas, monospace" font-weight="bold" fill="#dc2626">scorer.updateSelection();</text>
|
|
<text x="94" y="248" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">daysForward = DAYS.between(ANCHOR, date)</text>
|
|
<text x="94" y="268" font-size="11" font-family="Menlo, Consolas, monospace" font-weight="bold" fill="#dc2626">weather = scorer.lookupWeather(daysForward);</text>
|
|
|
|
<!-- scoring loop -->
|
|
<rect x="80" y="312" width="300" height="104" rx="8" fill="#eef2ff" stroke="#818cf8"/>
|
|
<text x="94" y="334" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">for (flavour : keySet) result += 10</text>
|
|
<text x="94" y="356" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">if (sunnyHolidays > 2 && Vanilla) += 5</text>
|
|
<text x="94" y="376" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">if (sunnyHolidays > 1 && weather[1]) += 2</text>
|
|
<text x="94" y="402" font-size="10" fill="#64748b">scoring loop</text>
|
|
|
|
<!-- Scorer -->
|
|
<rect x="580" y="200" width="150" height="80" rx="8" fill="#fef2f2" stroke="#dc2626" stroke-width="1.5"/>
|
|
<text x="655" y="230" font-size="14" font-weight="bold" fill="#dc2626" text-anchor="middle">Scorer</text>
|
|
<text x="655" y="250" font-size="11" fill="#7f1d1d" text-anchor="middle">stands for the weather</text>
|
|
<text x="655" y="266" font-size="11" fill="#7f1d1d" text-anchor="middle">service — uses Random</text>
|
|
|
|
<line x1="384" y1="228" x2="572" y2="222" stroke="#dc2626" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#arrR)"/>
|
|
<line x1="384" y1="268" x2="572" y2="254" stroke="#dc2626" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#arrR)"/>
|
|
|
|
<!-- test -->
|
|
<rect x="580" y="330" width="150" height="60" rx="8" fill="#ffffff" stroke="#94a3b8" stroke-dasharray="4 3"/>
|
|
<text x="655" y="354" font-size="12" fill="#334155" text-anchor="middle">approval test</text>
|
|
<text x="655" y="372" font-size="12" font-weight="bold" fill="#dc2626" text-anchor="middle">red & flaky ✗</text>
|
|
</svg>
|