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

April 23, 2019 by Callibrity Expert

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.

 

 

Callibrity Expert
Callibrity Expert Callibrity is a software consultancy specializing in software engineering, digital transformation, cloud strategy, and data-driven insights. Our national reach serves clients on their digital journey to solve complex problems and create innovative solutions for ever-changing business models. Our technology experience covers a diverse set of industries with a focus on middle-market and enterprise companies.