Skip to content

Commit

Permalink
switch to builder 2 + rename :)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyoder committed Sep 7, 2018
1 parent 8c89f26 commit 00de04d
Show file tree
Hide file tree
Showing 10 changed files with 869 additions and 1,316 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
build/
node_modules/
.DS_Store
node_modules
*.log
log/
logs/
10 changes: 7 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Copyright (c) 2012-2015 Panda Strike, LLC and Dan Yoder <dan@pandastrike.com>
MIT License

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
Copyright (c) 2012-2018 Panda Strike, Inc. and Dan Yoder.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Fairmont-Multimethods
# Panda Generics

Fairmont-Multimethods is a JavaScript library providing support for multimethods in JavaScript.
Panda Generics brings generics, also known as multi-methods, to JavaScript. Generics are great for functional programming because they offer multi-argument dispatch. That is, you aren't limited to an implicit first argument as you are with object-oriented methods.

## Installation

`npm i -S fairmont-multimethods`
`npm i panda-generics`

## Usage

Expand Down Expand Up @@ -41,5 +41,3 @@ equal { x: 1, y: 2 }, { x: 1, y: 2 } # => true, deep equality
equal [1..5], [1..5] # true, deep equality
equal { x: 1, y: 2}, [1..5] # false
```

[API documentation](https://github.com/pandastrike/fairmont/wiki/API-Reference#method).
86 changes: 0 additions & 86 deletions build/npm/lib/index.js

This file was deleted.

119 changes: 33 additions & 86 deletions build/npm/test/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"use strict";

var _powerAssertRecorder = function () { function PowerAssertRecorder() { this.captured = []; } PowerAssertRecorder.prototype._capt = function _capt(value, espath) { this.captured.push({ value: value, espath: espath }); return value; }; PowerAssertRecorder.prototype._expr = function _expr(value, source) { var capturedValues = this.captured; this.captured = []; return { powerAssertContext: { value: value, events: capturedValues }, source: source }; }; return PowerAssertRecorder; }();
var _assert = require("assert");

var _powerAssert = require("power-assert");

var _powerAssert2 = _interopRequireDefault(_powerAssert);
var _assert2 = _interopRequireDefault(_assert);

var _amen = require("amen");

var _lib = require("../lib");
var _src = require("../src");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

Expand All @@ -20,143 +18,92 @@ var eq, isEqual, isFunction, isKind, isNumber, isString, isType, lte;

_asyncToGenerator(function* () {
return (0, _amen.print)((yield (0, _amen.test)("Multimethods", [(0, _amen.test)("Fibonacci function", function () {
var _rec = new _powerAssertRecorder();

var fib;
fib = _lib.Method.create({
fib = _src.Method.create({
description: "Fibonacci sequence",
default: function () {
throw new TypeError("Operand must be a postive integer");
}
});
_lib.Method.define(fib, isType(Number), function (n) {
_src.Method.define(fib, isType(Number), function (n) {
return fib(n - 1) + fib(n - 2);
});
_lib.Method.define(fib, eq(1), function () {
_src.Method.define(fib, eq(1), function () {
return 1;
});
_lib.Method.define(fib, eq(2), function () {
_src.Method.define(fib, eq(2), function () {
return 1;
});
return (0, _powerAssert2.default)(_rec._expr(_rec._capt(_rec._capt(fib(5), "arguments/0/left") === 5, "arguments/0"), {
content: "assert(fib(5) === 5)",
filepath: "index.coffee",
line: 21
}));
return (0, _assert2.default)(fib(5) === 5);
}), (0, _amen.test)("Polymorphic dispatch", function () {
var _rec2 = new _powerAssertRecorder(),
_rec3 = new _powerAssertRecorder(),
_rec4 = new _powerAssertRecorder();

var A, B, a, b, foo;
A = class A {};
B = class B extends A {};
a = new A();
b = new B();
foo = _lib.Method.create();
_lib.Method.define(foo, isKind(A), function () {
foo = _src.Method.create();
_src.Method.define(foo, isKind(A), function () {
return "foo: A";
});
_lib.Method.define(foo, isType(B), function () {
_src.Method.define(foo, isType(B), function () {
return "foo: B";
});
_lib.Method.define(foo, isKind(A), isKind(B), function () {
_src.Method.define(foo, isKind(A), isKind(B), function () {
return "foo: A + B";
});
_lib.Method.define(foo, isKind(B), isKind(A), function () {
_src.Method.define(foo, isKind(B), isKind(A), function () {
return "foo: B + A";
});
_lib.Method.define(foo, eq(a), eq(b), function () {
_src.Method.define(foo, eq(a), eq(b), function () {
return "foo: a + b";
});
(0, _powerAssert2.default)(_rec2._expr(_rec2._capt(_rec2._capt(foo(_rec2._capt(b, "arguments/0/left/arguments/0")), "arguments/0/left") === "foo: B", "arguments/0"), {
content: "assert(foo(b) === \"foo: B\")",
filepath: "index.coffee",
line: 38
}));
(0, _powerAssert2.default)(_rec3._expr(_rec3._capt(_rec3._capt(foo(_rec3._capt(a, "arguments/0/left/arguments/0"), _rec3._capt(b, "arguments/0/left/arguments/1")), "arguments/0/left") === "foo: a + b", "arguments/0"), {
content: "assert(foo(a, b) === \"foo: a + b\")",
filepath: "index.coffee",
line: 39
}));
(0, _powerAssert2.default)(_rec4._expr(_rec4._capt(_rec4._capt(foo(_rec4._capt(b, "arguments/0/left/arguments/0"), _rec4._capt(a, "arguments/0/left/arguments/1")), "arguments/0/left") === "foo: B + A", "arguments/0"), {
content: "assert(foo(b, a) === \"foo: B + A\")",
filepath: "index.coffee",
line: 40
}));
return _powerAssert2.default.throws(function () {
(0, _assert2.default)(foo(b) === "foo: B");
(0, _assert2.default)(foo(a, b) === "foo: a + b");
(0, _assert2.default)(foo(b, a) === "foo: B + A");
return _assert2.default.throws(function () {
return foo(b, a, b);
});
}), (0, _amen.test)("Variadic arguments", function () {
var _rec5 = new _powerAssertRecorder();

var bar;
bar = _lib.Method.create();
_lib.Method.define(bar, String, function () {
bar = _src.Method.create();
_src.Method.define(bar, String, function () {
return true;
}, function (x, ...a) {
return a[0];
});
_lib.Method.define(bar, Number, function () {
_src.Method.define(bar, Number, function () {
return true;
}, function (x, ...a) {
return x;
});
return (0, _powerAssert2.default)(_rec5._expr(_rec5._capt(_rec5._capt(bar("foo", 1, 2, 3), "arguments/0/left") === 1, "arguments/0"), {
content: "assert(bar(\"foo\", 1, 2, 3) === 1)",
filepath: "index.coffee",
line: 50
}));
return (0, _assert2.default)(bar("foo", 1, 2, 3) === 1);
}), (0, _amen.test)("Predicate functions", function () {
var _rec6 = new _powerAssertRecorder(),
_rec7 = new _powerAssertRecorder();

var baz;
baz = _lib.Method.create();
_lib.Method.define(baz, function (x) {
baz = _src.Method.create();
_src.Method.define(baz, function (x) {
return x !== 7;
}, function () {
return false;
});
_lib.Method.define(baz, function (x) {
_src.Method.define(baz, function (x) {
return x === 7;
}, function (x) {
return true;
});
(0, _powerAssert2.default)(_rec6._expr(_rec6._capt(baz(7), "arguments/0"), {
content: "assert(baz(7))",
filepath: "index.coffee",
line: 58
}));
return (0, _powerAssert2.default)(_rec7._expr(_rec7._capt(!_rec7._capt(baz(6), "arguments/0/argument"), "arguments/0"), {
content: "assert(!baz(6))",
filepath: "index.coffee",
line: 59
}));
(0, _assert2.default)(baz(7));
return (0, _assert2.default)(!baz(6));
}), (0, _amen.test)("Multimethods are functions", function () {
var _rec8 = new _powerAssertRecorder();

return (0, _powerAssert2.default)(_rec8._expr(_rec8._capt(isFunction(_rec8._capt(_rec8._capt(_lib.Method, "arguments/0/arguments/0/callee/object").create(), "arguments/0/arguments/0")), "arguments/0"), {
content: "assert(isFunction(Method.create()))",
filepath: "index.coffee",
line: 62
}));
return (0, _assert2.default)(isFunction(_src.Method.create()));
}), (0, _amen.test)("Lookups", function () {
var _rec9 = new _powerAssertRecorder();

var f, foo;
foo = _lib.Method.create();
_lib.Method.define(foo, isNumber, function (x) {
foo = _src.Method.create();
_src.Method.define(foo, isNumber, function (x) {
return x + x;
});
_lib.Method.define(foo, isString, function (x) {
_src.Method.define(foo, isString, function (x) {
return false;
});
f = _lib.Method.lookup(foo, [7]);
return (0, _powerAssert2.default)(_rec9._expr(_rec9._capt(_rec9._capt(f(7), "arguments/0/left") === 14, "arguments/0"), {
content: "assert(f(7) === 14)",
filepath: "index.coffee",
line: 72
}));
f = _src.Method.lookup(foo, [7]);
return (0, _assert2.default)(f(7) === 14);
})])));
})();
2 changes: 1 addition & 1 deletion gulpfile.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tools = require "fairmont-build-tools"
tools = require "panda-builder"
{target} = tools require "gulp"

target "npm"
Loading

0 comments on commit 00de04d

Please sign in to comment.