Skip to content

Instantly share code, notes, and snippets.

@back2dos
Created July 27, 2013 09:37
Show Gist options
  • Select an option

  • Save back2dos/6094394 to your computer and use it in GitHub Desktop.

Select an option

Save back2dos/6094394 to your computer and use it in GitHub Desktop.
Fun with abstracts: grouping members without overhead.
package ;
abstract Animals(ExampleData) from ExampleData {
public var dog(get, never):Animal;
inline function get_dog():Animal return this.dog;
public var cat(get, never):Animal;
inline function get_cat():Animal return this.cat;
public var cow(get, never):Animal;
inline function get_cow():Animal return this.cow;
}
package ;
abstract Example(ExampleData) {
public var animals(get, never):Animals;
public var fruit(get, never):Fruit;
inline function get_animals():Animals return this;
inline function get_fruit():Fruits return this;
}
package ;
class ExampleData {
public var dog:Animal;
public var cat:Animal;
public var cow:Animal;
public var orange:Fruit;
public var banana:Fruit;
public var apple:Fruit;
}
package ;
abstract Fruits(ExampleData) from ExampleData {
public var orange(get, never):Fruit;
inline function get_orange():Fruit return this.orange;
public var banana(get, never):Fruit;
inline function get_banana():Fruit return this.banana;
public var apple(get, never):Fruit;
inline function get_apple():Fruit return this.apple;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment