Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Can curry functions be executed half way?

Lets say I have a function like this:

function foo(){
  return () => {
    return "bar"
  }
}

foo()() // => "bar"

Is there a way for this to return something other than a function without the use of a parameter?

foo()() // => "bar"
foo()   // => "foo"
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No. If the value returned must be callable later, then it has to be a function - no exceptions.

You could put a property on the function, though.

function foo(){
  return Object.assign(
    () => {
      return "bar"
    },
    { prop: 'bar' }
  );
}

console.log(foo()());
console.log(foo().prop);

Or return both a function and something else.

function foo(){
  return [
    () => {
      return "bar"
    },
    'bar'
  ];
}

const [fn, val] = foo();
console.log(fn());
console.log(val);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!