Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@deepak1556
Created December 19, 2014 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepak1556/29126acb41b7b0549f1f to your computer and use it in GitHub Desktop.
Save deepak1556/29126acb41b7b0549f1f to your computer and use it in GitHub Desktop.
notimplemented
var _slice = Array.prototype.slice;
function Maybe (fn) {
return function () {
return fn !== void 0 ? fn.apply(this, arguments) : 'Notimplemented'
}
}
function N (f) {
var name = f.name;
return function (o) {
return f.call(this, o) || Maybe(o[name]).call(o,this)
}
}
function type1 (v) {
this.v = v;
}
type1.prototype.equal = N(function equal (o) {
if (o instanceof type1) {
return this.v === o.v
}
})
function type2 (v) {
this.v = v;
}
type2.prototype.equal = function equal (o) {
if (o instanceof type2) {
return this.v === o.v
} else if (o instanceof type1) {
return this.v === o.v
}
}
a = new type1(1)
b = new type2(1)
a.equal(b) /=> true / "Not implemented" depending on b has a method equal
a.equal(a) /+> true
b.equal(b) /=> true
b.equal(a) /=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment