0.0.4 • Published 7 years ago

sweet-algebras v0.0.4

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

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
0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago