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
16 lines
1.1 KiB
Plaintext
16 lines
1.1 KiB
Plaintext
All three steps are complete. The code compiles successfully. Here's a summary of the refactoring:
|
|
|
|
---
|
|
|
|
## Final Diff for `LongRangeForecasts.java`
|
|
|
|
| Change | Description |
|
|
|--------|-------------|
|
|
| **Import** | Added `java.util.function.LongFunction` |
|
|
| **New no-arg overload** | `longRangeForecast()` — wraps the scorer in a lambda and delegates to the parameterized version |
|
|
| **Signature change** | `longRangeForecast(String quarter)` → `longRangeForecast(LongFunction<Boolean> dayOffsetToWeather)` — removed `quarter` param and its Q1/Q4 block |
|
|
| **Lambda extraction** | Removed the internal `dayOffsetToWeather` lambda definition; it's now passed as a method parameter |
|
|
| **New helper method** | `collectExpectedWeather(List<Instant>, LongFunction<Boolean>)` — extracted weather-collection loop, receives the dependency-injected lambda |
|
|
|
|
The key outcome is that `Scorer` is no longer directly invoked inside `longRangeForecast`. Its behavior is injected via the `LongFunction<Boolean>` parameter, making the method testable and decoupled from the external dependency.
|