DEV Community

loading...

Discussion on: βœ”||🀒 Commit or Vomit | function currying πŸ›

Collapse
jackmellis profile image
Jack • Edited

Currying is confusing at first but incredibly useful in the right circumstances. Doing a lot of FP it's become the norm until a new starter joins and I have to explain it again, it's weird how gross things become normal.

Currying definitely looks less gross to me when you use braceless arrow functions though.

Also this example is technically not currying, it's higher order functions. Currying is where you have a function with n parameters, and wrap it in a function that can take 0-n parameters and returns a new function until it has all n parameters. For example:

const multiply = curry((a, b, c) => {
  return a * b * c
})

multiply(1, 2, 3)
multiply(1, 2)(3)
multiply(1)(2)(3)
Enter fullscreen mode Exit fullscreen mode

I realise as I'm typing this my explanation is quite convoluted but hopefully it makes sense!

Collapse
jmdejager profile image
🐀πŸ₯‡ Jasper de Jager Author

It does make sense! Thank you ☺️