Skip to content

jmars/algebraic-data-traits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published