-
-
Save ciscoheat/e1b27e45b7c2fe09a42b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The following will be macromagically transformed... | |
class LazyExample implements Lazy | |
{ | |
var values:Array<Int>; | |
public function new() | |
{ | |
this.values = [3, 5, 1, 7]; | |
} | |
@lazy public var sum : Int = | |
{ | |
var result = 0; | |
for (value in values) result += value; | |
return result; | |
} | |
} | |
// ...into this: | |
class LazyExample implements Lazy | |
{ | |
var values:Array<Int>; | |
public function new() | |
{ | |
this.values = [3, 5, 1, 7]; | |
} | |
private var _sum : Null<Int>; | |
public var sum(get, default) : Int; | |
public function get_sum() : Int | |
{ | |
if (_sum != null) return _sum; | |
var result = 0; | |
for (value in values) result += value; | |
return _sum = result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment