Files
learning-hour-maker/ideas/split-loop-with-lambda/storyboard/svg/d5-overload-test.svg
T
Your Name 558ad54516 Add demo script for printSalesForecasts (Split Loop with Lambda)
Demo on the messier sibling of the exercise method: three unwanted
dependencies in one loop (Scorer incl. static field write, System.out,
clock — clock stripped in 2-min prep). Same six mechanics with SVGs in
the storyboard style, ends green via overload + pure-lambda approval
test. Pointer added to the learning hour's demo section.
2026-09-28 07:42:33 +00:00

55 lines
4.4 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="arrGr" 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="#16a34a"/>
</marker>
</defs>
<rect width="760" height="460" fill="#ffffff"/>
<text x="24" y="34" font-size="20" font-weight="bold" fill="#0f172a">Step 5 — the overload, and the test goes green</text>
<text x="24" y="56" font-size="13" fill="#16a34a" font-weight="bold">The test passes nameToSalesScore through the seam. Scorer is never touched: deterministic, glanceable.</text>
<!-- test -->
<rect x="50" y="150" width="230" height="140" rx="10" fill="#f0fdf4" stroke="#16a34a" stroke-width="1.5"/>
<text x="66" y="176" font-size="13" font-weight="bold" fill="#14532d">DailyForecastsTest</text>
<text x="66" y="202" font-size="11" font-family="Menlo, Consolas, monospace" fill="#334155">capture System.out</text>
<text x="66" y="224" font-size="11" font-family="Menlo, Consolas, monospace" font-weight="bold" fill="#16a34a">name -&gt; Steve ? 9 : 11</text>
<text x="66" y="248" font-size="11" font-family="Menlo, Consolas, monospace" fill="#14532d">printSalesForecasts(λ)</text>
<text x="66" y="272" font-size="11" font-family="Menlo, Consolas, monospace" fill="#14532d">Approvals.verify(...)</text>
<!-- middle: overload -->
<rect x="340" y="150" width="190" height="180" rx="10" fill="#f8fafc" stroke="#64748b" stroke-width="1.5"/>
<text x="354" y="176" font-size="11" font-weight="bold" fill="#0f172a">printSalesForecasts(<tspan fill="#9333ea">λ</tspan>)</text>
<text x="354" y="196" font-size="10" fill="#475569">no-arg overload bakes</text>
<text x="354" y="210" font-size="10" fill="#475569">in the real λ</text>
<text x="354" y="238" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">collectSalesScores</text>
<text x="354" y="256" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">(names, <tspan fill="#9333ea" font-weight="bold">λ</tspan>)</text>
<text x="354" y="284" font-size="11" font-family="Menlo, Consolas, monospace" fill="#d97706">print loop</text>
<text x="354" y="304" font-size="11" font-family="Menlo, Consolas, monospace" fill="#d97706">(still in here)</text>
<!-- right: extracted method -->
<rect x="570" y="150" width="170" height="180" rx="10" fill="#f8fafc" stroke="#64748b" stroke-width="1.5"/>
<text x="584" y="176" font-size="10" font-weight="bold" fill="#0f172a">collectSalesScores(λ)</text>
<text x="584" y="202" font-size="10" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">for name : names</text>
<text x="584" y="224" font-size="10" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">scores.put(name,</text>
<text x="584" y="242" font-size="10" font-family="Menlo, Consolas, monospace" fill="#1e1b4b"> <tspan fill="#9333ea" font-weight="bold">λ</tspan>.apply(name))</text>
<text x="584" y="270" font-size="10" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">return scores</text>
<text x="584" y="304" font-size="10" fill="#16a34a" font-weight="bold">pure ✓</text>
<!-- green arrows -->
<line x1="284" y1="225" x2="334" y2="225" stroke="#16a34a" stroke-width="1.5" marker-end="url(#arrGr)"/>
<text x="284" y="214" font-size="10" fill="#16a34a">λ</text>
<line x1="534" y1="225" x2="564" y2="225" stroke="#16a34a" stroke-width="1.5" marker-end="url(#arrGr)"/>
<!-- scorer, never called -->
<rect x="570" y="370" width="170" height="56" rx="8" fill="#f8fafc" stroke="#94a3b8" stroke-width="1.5" stroke-dasharray="4 3" opacity="0.8"/>
<text x="655" y="392" font-size="12" font-weight="bold" fill="#94a3b8" text-anchor="middle">Scorer</text>
<text x="655" y="412" font-size="10" fill="#64748b" text-anchor="middle">never called by the test ✗</text>
<line x1="655" y1="368" x2="655" y2="336" stroke="#dc2626" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#arrR)"/>
<text x="665" y="356" font-size="11" font-weight="bold" fill="#dc2626">✗</text>
<text x="50" y="430" font-size="12" fill="#475569">Approved: Steve score: 9 / Julie score: 11 / Francis score: 11 — every run, not just a lucky roll.</text>
</svg>