A resource constructs a Stream by acquiring a value and pairing it with a release action. Cleanup runs when production is exhausted, consumption stops early, or evaluation fails. section 15.3.3
Resource safety follows three termination cases:
- Close the resource when the producer has no more values. section 15.3.3
- Close it when a consumer such as take(5) stops before exhaustion. section 15.3.3
- Close it after abnormal termination, while preserving the failure. section 15.3.3
Files and writers
A file stream acquires Source.fromFile and releases it with close(); a writer uses the same pattern. Lines can then be transformed and written compositionally.
