DEV Community

Discussion on: Functional programming basics part 1: Pure function

 
ysael profile image
ysael pepin

Unfortunately the signature wont make this function pure.

What you would need in this case is composition which would allow you to compose 2 functions. I will at one point cover composition, in the mean time, you can read that great article by Eric Elliott --> medium.com/javascript-scene/master...

Thread Thread
 
tux0r profile image
tux0r

Unfortunately the signature wont make this function pure.

Why not?

Thread Thread
 
ycmjason profile image
YCM Jason

@tuxOr

There is nothing to do with the signature of a function.

A function is pure if and only if

  1. The returned value is calculated only with the arguments
  2. It does not change any thing outside of a function (side effect)

So in your example, assuming process(var1, var2) will make some side effect somewhere else in the program, it is not a pure function.

However, if process do not make any changes, then it will still be a pure function.

Thread Thread
 
tux0r profile image
tux0r

I think I understood now, thank you!