Nondeterminism means identical inputs can produce different outputs because execution depends on hidden mutable state, time, randomness, identity, external services, or other changing conditions. A function that reads the current date or calls a database is not determined by its visible arguments alone. section 6.1.1
Nondeterminism makes code harder to reason about and test because behavior depends on dependencies outside the function. Separate obtaining data from transforming it: pass values such as the current date and payment terms into a deterministic function, then test that function directly. section 6.1.1
Making a due-date calculation deterministic
A due-date method that calls LocalDate.now() and contractsClient.getTerms(...) mixes calculation with environmental access. Refactoring it to accept LocalDate and PaymentTerms makes the result depend only on explicit inputs, allowing a small test with a fixed date and NET_30 terms. section 6.1.1
Use these distinctions when organizing implementation:
- Treat deterministic functions as a core that depends only on other deterministic functions. section 6.2
- Place database calls, random-number generation, service calls, and environment access outside that core. section 6.2
- Accept that practical code may contain theoretical nondeterminism through mutable identity objects; treat them as data when rare mutation risks are negligible. section 6.1.7
Listing 6.28 The simplified view of how data flows through our program
NOTES.md ------------------------------------------------------------------- // step 1: collect the past due List<Invoice> -> List<PastDue> // Step 2: use those to build the draft List<PastDue> -> LateFee<Draft> // Step 3: decide what to do with the draft LateFee<Draft> -> (Billable OR NotBillable OR NeedsReview // then depending on what we decided, either: // Step 4.1: submit billable items Billable -> (LateFee<Billed> OR LateFee<Rejected>) // OR Step 4.2: Start the approval process for those that need it NeedsReviewed -> LateFee<InReview> // OR Step 4.3: keep the non-billable data for posterity NotBillable -> LateFee<Rejected>
Trace a late-fee workflow from collected invoices through draft construction, assessment, billing, approval, or rejection, and identify where deterministic transformations meet external effects. section 6.2




