r/functionalprogramming • u/Ok_Wishbone_5018 • Nov 20 '23
Question Is the code still functional programming?
If i declare a variable inside a function and mutate it, is it still considered functional?
For example, if i write a function to find the max of an array with a for loop and a max value and return that max value the function is still pure. It doesn't have any side effects, since the max variable is not global but it does contraddict the principle of immutability of data. So my question is, can you use for loops and variables inside of functions or not?
(ik of another way of getting the result using functions like reduce in javascript, thats not the point of the question)
View all comments
Show parent comment
2
u/vallyscode Nov 20 '23
What is there will be some private functions defined inside, according to them mutations will happen outside of their scope, does that still count?