Match Expression for JavaScript?

Sometimes (or rather most of the time) it would be nice to have more concise code in JavaScript. I was working with a function that needed quite a bit of if statements. if was awfully cluttered. I had looked at bilby.js examples and hadn’t realized that you can do multiple ternary expressions in a row. So, instead of, if (0){ return 0 } else if (1){ if (2) { return 1 } else if (3) { return 2 } else { return 3 } } else { return 4 } You can do, [Read More]

Prototypes & Compositions with Objects

I was trying to figure out the best way to have functions be both compatible with an object oriented paradigm and a functional oriented paradigm when working on objects. My implementations are probably naive, but instructive nevertheless. It seems that lo-dash and other libraries have done a good job bridging those worlds. Let’s say you have an object O such that function O(a, b){ this.a = a this.b = b } var o = function(a, b){ return new O(a, b) } Now, you want to extend the object but you also want the option to use the object in a more fuctional way with compose. [Read More]

Notes on Monads, Monoids, and Make Believe

with Brian Lonsdorf

with Brian Lonsdorf Working with Objects the better way var SSN = Constructor(function(number, current_user){ this.number = number this.user = current_user }) SSN.prototype = { fmap: function(f){ if(this.user.is_admin) return SSN(f(this.number), this.user) } } social.fmap(replace('-', '')) //=> SSN('123456789', user) social.fmap(function(number){return number.reverse()}) //=> SSN('1234-56-789', user) the functor way Note: Functor function defined. var AdminAccess = Constructor(function(val, current_user){ this.val = val this.user = current_user }) Functor(AdminAccess, { fmap: function(f){ if(this.user.is_admin) return AdminAccess(f(this.val), this. [Read More]