DEV Community

loading...

Discussion on: Pure vs Impure Functions

Collapse
lukaszahradnik profile image
Lukáš Zahradník

A side-effect is any operation your function performs that is not related to computing the final output

This isn't exactly true. You can have side effect, that is related to computing of your output that will make the function impure.

You also call arr.map(), arr.filter(), arr.reduce(), arr.each(), arr.every() pure. Are they really pure if they have impure predicates/callbacks?

Collapse
sanspanic profile image
Sandra Spanik Author • Edited

Great, I want to be exact in the language I use so thank you for commenting :) I edited “considered pure” to “typically associated with pure functions”.

As for the definition, I found it elsewhere. Before I update it, let me try and see if I’m parsing what you’re saying correctly: you’re saying that while my definition describes some side-effects, it doesn’t describe ALL side-effects, because there are some which are indeed related to computing the final output. Is that right?

Collapse
lukaszahradnik profile image
Lukáš Zahradník

Nice.

Yes, that's what I am saying. For example fetching data and then using them for some computation.