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 Functional Programming

Patterns for the Non-Mathematician with Brian Lonsdorf

Patterns for the Non-Mathematician with Brian Lonsdorf Lenses Using lenses for composable/polymorphic model manipulation. E.g., var user = {id:1, name:{first:'doris', last:'day'}} var L = makeLenses(['name', 'first']) var firstNameChar = compose(, L.first, _1) over(firstNameChar, toUpperCase, user) //=> {id:1, name:{first:'Doris', last:'day'}} Maybe Use Maybe (Haskell) types (Option types in bilby.js / Scala style) to make composition easier. This works with fmap (functor maps). Returns resultant option. Error Handling (Either) Either('need an int', 3) //=> Right(3) Either('need an int', undefined) //=> Left('need an int') fmap(function(x){return x+1;}, Right(2)) //=> Right(3) fmap(function(x){return x+1;}, Left('need an int')) //=> Left('need an int') compose(fmap(f), Either(error)) Future Values I’ll have to come back to this one later when I use it more. [Read More]