Skip to content

Instantly share code, notes, and snippets.

@ciscoheat
Forked from cambiata/gist:cfc9a48f4e24653fc95a
Last active August 29, 2015 14:02
Show Gist options
  • Save ciscoheat/e1b27e45b7c2fe09a42b to your computer and use it in GitHub Desktop.
Save ciscoheat/e1b27e45b7c2fe09a42b to your computer and use it in GitHub Desktop.
// 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