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

195
Views
Can we pass objects to function parameters in functional programming?

I have been mostly writing Object-oriented code in my day to day work and have little experience with functional programming.

In JavaScript/typescript code, we can definitely pass objects as parameters to functions. My question is whether passing objects to functions violates the functional programming paradigm as I am mixing object oriented code with functional style programming. (Even though The object passed into the function does not get mutated).

For example, if I have a function f(x,y) => z where x is an object that defines some interface. Object x makes a network call to access some resource which is used to compute z. We can say that such a function still adheres to the functional programming concept of it having no side effects and it being pure even though there is mixing of OO code in the function parameter ?

Hope my question was clear.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

if I have a function f(x,y) => z where x is an object that defines some interface. Object x makes a network call to access some resource which is used to compute z.

If x makes a network call and uses the result to compute z, then it's (by most definitions) non-deterministic (since it performs I/O) and thereby not a pure function. This further means that f is impure, too. I don't consider that FP. Rather, it's an attempt at Dependency Injection.

This doesn't mean, however, that you can't pass 'data structures' as parameters - they just have to be immutable or other pure functions.

If, instead, object x implemented an interface that defines a pure function (an algorithm, say), you can pass it as a parameter, use the pure function, and the function that uses the 'object' might still be pure.

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!