Rewrite `distanceToIntersection` in ifs rather than monadic binding