DEV Community

Discussion on: ✔||🤢 Commit or Vomit | function currying 🍛

Collapse
 
avaq profile image
Aldwin Vlasblom

As a user of Sanctuary (the more opionated and strict alternative to Ramda), I use almost exclusively curried functions. To make this style of programming more readable, I use the coding style described here: github.com/sanctuary-js/sanctuary/...

It may seem jarring at first, but after working with it for some time you might find yourself like me, unwilling to go back; Turns out having each argument between parens makes multi-cursor editing a bliss: editors always have great support for parens-based selection and jumping and stuff. But more importantly, the utility gained from being able to use composition and other function combinators is huge.

Collapse
 
jmdejager profile image
🐤🥇 Jasper de Jager

Thanks for sharing!

Collapse
 
avaq profile image
Aldwin Vlasblom • Edited

Applying the style mentioned above, your snippet would look like:

const multiply = a => b => c => a * b * c
console.log (multiply (1) (2) (3)) // 6
Enter fullscreen mode Exit fullscreen mode

It's a minor change, but for many that breathing room makes all the difference, especially in larger bodies of code.