Applying Two Transformations in One Pass

Two item-by-item transformations can be composed into one pass when they do not depend on separate passes or their observable effects.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Trace a small sequence
  2. Check what gets eliminated

Trace a small sequence

Doubling 1, 4, and 7 gives 2, 8, and 14. Adding one gives 3, 9, and 15. Applying \(2x+1\) per item yields the same list. This follows composition order.

Check what gets eliminated

A fused loop can avoid retaining the intermediate sequence. If the original transformations record diagnostic effects, a fused pass may change their order. Pure functions explain when the intermediate observations are absent.[1]

References

  1. Python Software Foundation, Functional Programming HOWTO ↩