Understanding and using Streams in JavaScript


Introduction What do you think of the following code snippet? Isn't it beautifully succinct and neat? It reads just like English! That's the power of streams. Streams are just like lists but offer more capabilities because they simultaneously abstract data and computation. Streams vs Lists/Arrays? Let's take a scenario from Mathematics, how would you model the infinite set of … Continue reading Understanding and using Streams in JavaScript

How to implement the Y-combinator in JavaScript


This post provides a very simple step-by-step implementation of the Y-combinator in JavaScript. You should be able to implement the Y-combinator in your language of choice after reading this post; as you'll see - it's that easy. What is a combinator? According to wikipedia, A combinator is a particular type of higher-order function that may be used … Continue reading How to implement the Y-combinator in JavaScript

SICP Section 1.3 : Thoughts and Concepts


This section exposed me to the full power and beauty of functional programming. The expressiveness of using functions as values is awesome. For example, a sum of cubes function can use a sum function which itself relies on a reduce function. Think of higher order differentiation in mathematics and you do get the idea. An interesting concept involves … Continue reading SICP Section 1.3 : Thoughts and Concepts

JavaScript’s Array.prototype.reduce()


Programming involves manipulating collections of various things. Operations on collections include aggregating values, conversion into other formats and data replacement. Let's take a sum of array elements using the typical imperative style. Here's another example to flatten a 2-d array. One liner (inpiration) Both code snippets can be written more succinctly using the fold concept from functional programming. The snippets … Continue reading JavaScript’s Array.prototype.reduce()

Understanding Partial Application and Currying


Partial application and currying are two popular concepts from functional programming and help cut code replication in certain scenarios. This article assumes an understanding of the JavaScript bind function; binding is related to partial application in JavaScript. Partial Application In pure functional languages, functions are not 'invoked', rather a set of arguments is 'applied' to them. Now, if all … Continue reading Understanding Partial Application and Currying

Understanding Tail Recursion


A tail call is the last call executed in a function; if a tail call leads to the parent function being invoked again, then the function is tail recursive. In the first function - foo; the baz() function is a tail call while in foo2, the baz and biz are tail calls because both are the … Continue reading Understanding Tail Recursion

The JavaScript Function


JavaScript is a functional programming language and it is essential to truly understand functions to achieve mastery of the language. In JavaScript, functions are pretty much at the same level as objects: you can assign functions to variables, access function properties, pass them in as parameters to other functions or invoke them using the function operator. … Continue reading The JavaScript Function

A peek into JavaScript’s Array.prototype.map and jQuery.map


The map function comes from JavaScript's functional programming roots: it applies a function to every array element and returns a new array of the results without mutating the original array. So lets look at the native JS and jQuery map implementations. Array.prototype.map The signature for the native JS implementation is: The callback is the transforming … Continue reading A peek into JavaScript’s Array.prototype.map and jQuery.map

JavaScript: The functional Programming Parts


Yes, a lot of people think JavaScript is just another object-oriented language but the language differs in many ways from the Java/C++ class of programming languages. For example, JavaScript uses prototypical inheritance versus the classical inheritance favoured by OO languages; this makes it easier to get on new behaviours... and also makes it really really easy … Continue reading JavaScript: The functional Programming Parts

Functional Programming & ME


After finishing Rebecca Murphy's jqfundamentals and finding it to be quite an enjoyable and smooth read, I decided to learn JavaScript; I scanned my languages-to-learn list and quickly brought JavaScript to the front ahead of the others: Python/C/C++/C#/Ruby/Bash. One of the motivating factors was the fact that JavaScript supports functional programming; a paradigm I have … Continue reading Functional Programming & ME