Guard flattening: the flattened version
The complete source of forAI_guard_flattening_after.ek9, compiled by the EK9 compiler. Shown on forAI.html.
#!ek9 defines module site.forAI.guardsafter defines class Customer credit as Boolean: false Customer() -> credit as Boolean this.credit :=: credit hasCredit() as pure <- rtn as Boolean: credit default operator ? Order reference as String: String() customer as Customer: Customer() Order() -> reference as String customer as Customer this.reference :=: reference this.customer: customer id() as pure <- rtn as String: reference isValid() as pure <- rtn as Boolean: reference? getCustomer() as pure <- rtn as Customer: customer default operator ? defines function processOrder() -> order as Order <- result as String: String() if validateOrder(order) result: "Processing " + order.id() validateOrder() as pure -> order as Order <- valid as Boolean: false if order? and order.isValid() if customer <- order.getCustomer() with customer.hasCredit() valid: true defines program ProcessOne() stdout <- Stdout() stdout.println(processOrder(Order("A-1", Customer(true))))
Download forAI_guard_flattening_after.ek9
Output
Processing A-1