Code Monkey home page Code Monkey logo

haxe-traits's People

Contributors

realyuniquename avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

haxe-traits's Issues

Problem with some circular dependencies

Reference Gist

Seems that if you import an "interface A"(IEntity) that has a variable of type "class B"(EntityData) that has a function with return type "class C"(Entity) and "class C" implements the "interface A", then variables from "interface A" simply aren't copied to "class C" or something like this.

The same if you import "Class C" and then "Interface A".

But no problems for imports "Class C" or "Interface A" and "Class C"

Trait extends trait

interface TSpeaker extends ITrait {
    public function say(msg:String) trace(msg);
}

interface TScreamer extends TSpeaker {
    public function scream(msg:String) this.say(msg.toUpperCase() + "!!!!!!");
}

Access what traits a class has

Hello! How may I access (in code) if a class is implementing a specific trait?

For instance:
if (Car.hasTrait(FastEngine)){
Car.DriveFast();
}

I was also just wondering if this is stable enough to use in a full project, thanks! : ) ๐Ÿ‘
Edit:Sorry I don't know markdown to make that code look pretty! ๐Ÿ˜Ÿ

Traits intersection

interface TListener extends ITrait {
    var brain : Brain;

    public function update(){
        brain.process( listen() );
    }

    public function listen() : BrainInfo { 
        /* translate surrounding sounds to info undertandable by brain */
    }
}


interface TWatcher extends ITrait {
    var brain : Brain;

    public function update(){
        brain.process( watch() );
    }

    public function watch() : BrainInfo { 
        /* translate what i see to info understandable by brain */
    }
}


class Human extends Lifeform implements TWatcher, implements TListener {
    /**
    * This should be auto-generated if `update()` method is not defined by programmer
    */
    override public function update(){
        super.update();
        //this order should reflect `implements` directives order
        traits.Trait.parent(TWatcher).update();
        traits.Trait.parent(TListener).update();
    }
}

"Using" directive

Deal with using and such:

using Lambda;

interface TFoo implements ITrait {
    function bar(a:Iterable<String>) return a.has("foo");
}

class MyFoo implements TFoo {}

Fields initialization

interface TFoo extends ITrait {
    /* these expressions should be added to descendant's constructor */
    var deg2rad : Float = Math.PI / 180;
    var bar : Bar = new Bar();   
}

class Foo extends Some implements TFoo {
    /**
    * This should be auto-generated
    */
    public function new() {
        super();
        this.deg2rad = Math.PI / 180;
        this.bar = new Bar();
    }
}

Type parameters

Substitute type parameters (tink_lang in fact already does this);

interface TFoo<T> implements ITrait {
    function first(a:Iterable<T>):T return a.iterator.next();
}
class MyFoo implements TFoo<Int> {}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.