sweet-algebras

0.0.4 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i sweet-algebras

Weekly Downloads

3

Version

0.0.4

License

ISC

Last publish

Collaborators

  • disnet
  • michaelficarra