HomeChallengesRepsProblemsLeaderboardTake a challenge

Pipelines and selectors

Date and MonthDay give the right answers and are procedural inside: a while loop, ifs with early returns, a temporary variable. Rewrite them so that no method has a body block.

Intermediate10 min on the clock5 graded checks · 100 pointsDesigning an Object ModelPro
Graded by reading your code against the checklist below.

What you build

  • Make every method in Date and MonthDay expression-bodied (=>)
  • Choose between results with the ternary operator
  • Replace the while loop with a recursive private helper
  • Keep the helpers private

Done means

Date and MonthDay are expression-bodied throughout, with the loop as recursion and the branches as ternaries.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else.

  1. Every method in Date and MonthDay uses =>+25Small steps, joined up
  2. The search is recursive, with no loop+20Small steps, joined up
  3. Branching uses ?:+20Small steps, joined up
  4. The helpers are private+15Objects that protect themselves
  5. The rest of the model is unchanged+20Tell, don’t ask

What it teaches

Small steps, joined upintermediate

Four small transformations joined by a pipeline can each be tested alone; the same four welded into one loop can only be tested together, and only through their output.

The rest of Designing an Object Model