algebraic-data-traits

0.0.1 • Public • Published

Writing Java in Javascript considered harmful

I made this because I am tired of seeing this:

function NotReallyAClass() {
    this._notReallyPrivate = 'bar';
    return this
}
 
NotReallyAClass.prototype = new SomeGodClass();
 
NotReallyAClass.prototype.crash = function () {
    ...
}

Stop it!

Usage

npm install -g sweet.js
npm install jmars/algebraic-data-traits
sjs -m adt/macros -m sparkler/macros -o index.js index.sjs

Dependencies

trait Speaks {
    log(str) {
        console.log(str)
    }
}
 
trait Barks {
    requires log
 
    bark() {
        this.log('WOOF!')
    }
}
 
data Animal {
    Dog {
        name: String
    },
    Cat {
        name: String
    }
}
 
impl Dog {
    mixin Speaks
    mixin Barks
}
 
impl Cat {
    requires log
 
    mixin Speaks
    
    meow() {
        this.log('MEOW!')
    }
}
 
var fluffy = Cat.create({name:'fluffy'});
fluffy.meow() // MEOW!
 
// And sparkler.js compatible
fluffy match {
    case Cat{name} => console.log(name) // fluffy
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    0

Package Sidebar

Install

npm i algebraic-data-traits

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • jmars