• Sources: primary, discussion
  • Summary: The post states the preconditions behind the idiom. A condition only leaves a loop when it is loop invariant. A selection moves below a join only when it touches one side. Filtering before mapping holds as filter p . map f == map f . filter (p . f) and pays only when p . f reduces to a cheap test on the input.
  • Why it matters: The idiom usually circulates as a bare style rule, and the stated preconditions are what separate a safe rewrite from a behaviour change.