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
  • Select an option

  • Save ciscoheat/e1b27e45b7c2fe09a42b to your computer and use it in GitHub Desktop.

Select an option

Save ciscoheat/e1b27e45b7c2fe09a42b to your computer and use it in GitHub Desktop.

Revisions

  1. ciscoheat revised this gist Jun 6, 2014. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions gistfile1.hx
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ class LazyExample implements Lazy
    this.values = [3, 5, 1, 7];
    }

    @lazy public function getSum():Int
    @lazy public var sum : Int =
    {
    var result = 0;
    for (value in values) result += value;
    @@ -28,15 +28,15 @@ class LazyExample implements Lazy
    this.values = [3, 5, 1, 7];
    }

    private var _sum:Null<Int>;
    public function getSum():Int
    private var _sum : Null<Int>;
    public var sum(get, default) : Int;

    public function get_sum() : Int
    {
    if (this._sum != null) return this._sum;
    if (_sum != null) return _sum;

    var result = 0;
    for (value in values) result += value;

    this._sum = result;
    return result;
    return _sum = result;
    }
    }
  2. @cambiata cambiata revised this gist Jun 6, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.hx
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ class LazyExample implements Lazy
    }
    }

    // into this:
    // ...into this:

    class LazyExample implements Lazy
    {
  3. @cambiata cambiata created this gist Jun 6, 2014.
    42 changes: 42 additions & 0 deletions gistfile1.hx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    // 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 function getSum():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 function getSum():Int
    {
    if (this._sum != null) return this._sum;

    var result = 0;
    for (value in values) result += value;

    this._sum = result;
    return result;
    }
    }