Return values captured or used

The complete source of quality_discarded_good.ek9, compiled by the EK9 compiler. Shown on quality.html.

#!ek9
defines module site.quality.discarded

  defines function

    calculateTotal() as pure
      -> items as List of Float
      <- total as Float: Float(length items)

    riskyParse()
      <- rtn <- Result("OK", Integer())

    demo()
      -> price as Float
      items <- List() of Float

      total <- price + 10.0               //Assign the result
      Stdout().println($total)
      price += 10.0                       //Or use a mutating operator

      orderTotal <- calculateTotal(items) //Assign the result
      Stdout().println($orderTotal)

      parseResult <- riskyParse()         //Handle the Result: check it, then take the value
      if parseResult.isOk()
        Stdout().println(parseResult.ok())

  defines program
    Discarded()
      demo(42.0)

Download quality_discarded_good.ek9

Output

52.0
0.0
OK