-1

I was checking the code and I saw a weird function

    const customFetch = client => (uri, options) => {
      return new Promise((resolve, reject) => {
         client(option1, option2)
      }
    }

So I was trying to create my own function like this

const suma = sum => (a, b)=>{
  return a+b;
}

And if I run it suma(1,2) it returns a function, so the only way to run this is with suma(1,2)(1,2) But dont really understand why this is useful

Christian
  • 465
  • 6
  • 21
  • Sometimes you want to pass in an argument at one point, and pass in other arguments at another point. Or sometimes you just like functional programming and curry everywhere – CertainPerformance May 25 '22 at 21:38
  • It's a arrow function that returns an arrow function. Rewritten it would be like: ` function customFetch(client) { return function (uri, options) { return /* ... */ } }` – Stephen Quan May 25 '22 at 23:10
  • In your cases, suma is a function returning a sum function. So, the correct usage would be suma()(1, 2). It is not really what you want. – Stephen Quan May 25 '22 at 23:12

0 Answers0