The importance of Pure Functions
(Corrections Please!)
Working with functions is not the only thing you need to do in order to work in a functional way. Your functions also need to be pure. But what does that mean? Well, according to Federico Kereki, you have a pure function when it meets the following criteria:
[QUOTE HERE]
Let's see an example:
[EXAMPLE HERE]
The past function is pure because it will always return the result "6" for the given arguments: "2" and "3". This function is not affecting its external context at all. Everything is happening inside of it. So we can be absolutely sure to say: It does not have side effects, therefore, the function is pure.
That's pretty much it. Your function is pure when it does not have side effects. If it does not have side effects, then your function is pure. Easy right? But what that hell is a side effect anyway? Here there's a list of possible side effects you might find around:
[LIST HERE]
And last but not least, using a function that happens to be impure. Federico says in his book that impure functions are "contagious". So if your function uses something that causes a side effect, impure your function will be. (Yoda way of speaking intended)
Cerca tra vari insegnanti di Inglese...
Correzioni · 0
Non perdere l'opportunità di imparare una lingua comodamente da casa tua. Esplora la nostra selezione di insegnanti di lingue esperti e iscriviti subito alla tua prima lezione!
Inizia a imparare oggi
