sweet-algebras
v0.0.4
Published
A implementation of emcascript-algebras with macros
Downloads
6
Readme
sweet algebras
This is an experimental implementation of emcascript algebras in Sweet.js.
Install
npm install @sweet-js/cli sweet-algrebras
Use
Import class
and interface
from the sweet-algrebras
packages:
// maybe.js
'lang sweet.js';
import { class, interface } from 'sweet-algrebras';
interface Functor {
map;
}
class Maybe implements Functor { }
class Just extends Maybe {
constructor(value) {
super();
this.value = value;
}
[Functor.map](fn) {
return new Just(fn(this.value));
}
}
class Nothing extends Maybe {
[Functor.map](fn) {
return this;
}
}
new Just(1)[Functor.map](console.log);
and compile with Sweet:
sjs maybe.js