It’s Endomorphin’ Time! Composure in JavaScript, from Functions to Monads


23 April 2019 by Jake Witcher

One of the greatest tools in the functional programmer’s tool belt is the notion of composure. It’s a pattern that allows you to take two things and combine them, like LEGO pieces or the segmented tracks of a train set, and join them together in a myriad of ways with different structures or pathways each time. Combined with functors and monads, this very simple concept can be used not only to transform data in complex ways, but also ensure its validity and handle errors and invalid input effortlessly without ever causing your program to crash.

This talk will start with the basic building blocks of function composition— pure, endomorphic functions— and then discuss how curry and compose assist in combining these blocks. It will illustrate how functors can be used when the presence or type of input is uncertain, how monads can provide multiple validity checks without breaking a sweat, and how map and chain let us continue to compose away effortlessly under these circumstances.

Examples will be in JavaScript and will utilize the Ramda library for helper functions and monads, however, this talk will also take a look at how these things work internally so as to demonstrate not only how to use these tools, but also how they work. Understanding and utilizing composure to solve real-world problems in programming will produce code that is clean, agile, and reliable. These benefits are accessible to both the seasoned developer and the beginner.

Composure in JavaScript Jake W_Callibrity

 

 


Jake Witcher
Jake Witcher

Jake has 15 years of management experience and is a self-taught software developer with experience in React, JavaScript, and TypeScript. He enjoys learning new programming languages, frameworks and design patterns and is a writer and speaker. Jake spends his free time with his wife and kids, playing board games, video games, and crafting.