Rename split-loop-with-lambda to slice-with-lambda
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
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<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="arrP" 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="#9333ea"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="760" height="460" fill="#ffffff"/>
|
||||
<text x="24" y="34" font-size="20" font-weight="bold" fill="#0f172a">Step 1 — extract the pricing call into a lambda, and slide it</text>
|
||||
<text x="24" y="56" font-size="13" fill="#9333ea" font-weight="bold">One expression, nothing else in the way. priceList is a field, so the lambda slides all the way to the top.</text>
|
||||
|
||||
<!-- method -->
|
||||
<rect x="60" y="74" width="400" height="330" rx="10" fill="#f8fafc" stroke="#64748b" stroke-width="1.5"/>
|
||||
<text x="76" y="98" font-size="14" font-weight="bold" fill="#0f172a">ShoppingListTotal(buyerName)</text>
|
||||
|
||||
<!-- lambda at top -->
|
||||
<rect x="80" y="110" width="360" height="82" rx="8" fill="#faf5ff" stroke="#9333ea" stroke-width="1.5"/>
|
||||
<text x="94" y="136" font-size="12" font-weight="bold" fill="#9333ea">λ priceFor</text>
|
||||
<text x="94" y="162" font-size="11" font-family="Menlo, Consolas, monospace" fill="#dc2626">Func<IceCream,int> =</text>
|
||||
<text x="94" y="180" font-size="11" font-family="Menlo, Consolas, monospace" fill="#dc2626"> flavour => priceList.PriceFor(flavour);</text>
|
||||
|
||||
<text x="80" y="200" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">buyer = ByName(buyerName)</text>
|
||||
|
||||
<!-- loop -->
|
||||
<rect x="80" y="214" width="360" height="120" rx="8" fill="#eef2ff" stroke="#818cf8"/>
|
||||
<text x="94" y="240" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">foreach (var flavour : buyer.Favourites)</text>
|
||||
<text x="94" y="270" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">total += buyer.ScoopsOf(flavour) *</text>
|
||||
<text x="94" y="290" font-size="11" font-family="Menlo, Consolas, monospace" font-weight="bold" fill="#6b21a8"> priceFor(flavour);</text>
|
||||
<text x="94" y="318" font-size="10" fill="#64748b">invocation stays exactly where the code was</text>
|
||||
|
||||
<!-- ghost -->
|
||||
<rect x="94" y="352" width="330" height="26" rx="6" fill="none" stroke="#9333ea" stroke-width="1" stroke-dasharray="4 3"/>
|
||||
<text x="106" y="370" font-size="10" fill="#9333ea" font-style="italic">λ used to be defined right here</text>
|
||||
|
||||
<text x="80" y="398" font-size="11" font-family="Menlo, Consolas, monospace" fill="#1e1b4b">return total;</text>
|
||||
|
||||
<!-- slide arrow -->
|
||||
<line x1="260" y1="350" x2="260" y2="196" stroke="#9333ea" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#arrP)"/>
|
||||
<text x="270" y="205" font-size="12" font-weight="bold" fill="#9333ea">slide</text>
|
||||
|
||||
<!-- PriceList -->
|
||||
<rect x="580" y="130" width="150" height="90" rx="8" fill="#fef2f2" stroke="#dc2626" stroke-width="1.5"/>
|
||||
<text x="655" y="160" font-size="14" font-weight="bold" fill="#dc2626" text-anchor="middle">PriceList</text>
|
||||
<text x="655" y="180" font-size="11" fill="#7f1d1d" text-anchor="middle">still called —</text>
|
||||
<text x="655" y="196" font-size="11" fill="#7f1d1d" text-anchor="middle">but only via the λ now</text>
|
||||
|
||||
<line x1="444" y1="142" x2="572" y2="162" stroke="#dc2626" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#arrR)"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.5 KiB |
Reference in New Issue
Block a user