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.name, 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]