Created
October 10, 2012 02:23
-
-
Save puffnfresh/3862789 to your computer and use it in GitHub Desktop.
Safe ad-hoc polymorphism in JavaScript via bilby.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lib = require('./lib'), | |
λ = lib.method('show', lib.isNumber, function(n) { | |
return n.toString(2); | |
}); | |
exports.showBinaryTimesTwo = λ.bind(λ.showTimesTwo)(λ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bilby = require('bilby'); | |
module.exports = bilby.property('showTimesTwo', function(n) { | |
return this.show(n) + ' + ' + this.show(n) + ' = ' + this.show(n + n); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var binary = require('./binary'), | |
words = require('./words'); | |
console.log(binary.showBinaryTimesTwo(1) + ' and ' + words.showWordTimesTwo(100)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lib = require('./lib'), | |
λ = lib.method('show', lib.isNumber, function(n) { | |
return n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : 'some number'; | |
}); | |
exports.showWordTimesTwo = λ.bind(λ.showTimesTwo)(λ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment