Pure functions
The definition of a pure function says that, if the return value of a function is completely dependent on its arguments/parameters, then this function may be referred to as a pure function. So, if we declare a function as fun func1(x:Int):Int, then its return value will be strictly dependent on its argument, x; say, if you call func1 with a value of 3 N times, then, for every call, its return value will be the same.
The definition also says that a pure function should not actively or passively cause side effects, that is, it should not directly cause side effects, nor should it call any other function that causes side effects.
A pure function can be either a lambda or a named function.
So, why are they called pure functions? ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access