Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda