Pure function

In computer programming, a pure function is a function that has the following properties: the function return values are identical for identical arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams, i.e., referential transparency), and the function has no side effects (no mutation of non-local variables, mutable reference arguments or input/output streams). == Examples == === Pure functions === The following examples of C++ functions are pure: === Impure functions === The following C++ functions are impure as they lack the above property 1: The following C++ functions are impure as they lack the above property 2: The following C++ functions are impure as they lack both the above properties 1 and 2: == I/O in pure functions == I/O is inherently impure: input operations undermine referential transparency, and output operations create side effects.

Source: Wikipedia — Pure function (CC BY-SA 4.0)

Pure function

In computer programming, a pure function is a function that has the following properties: the function return values are identical for identical arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams, i.e., referential transparency), and the function has no side effects (no mutation of non-local variables, mutable reference arguments or input/output streams). == Examples == === Pure functions === The following examples of C++ functions are pure: === Impure functions === The following C++ functions are impure as they lack the above property 1: The following C++ functions are impure as they lack the above property 2: The following C++ functions are impure as they lack both the above properties 1 and 2: == I/O in pure functions == I/O is inherently impure: input operations undermine referential transparency, and output operations create side effects.

Source: Wikipedia "Pure function" · CC BY-SA 4.0

Share this article: X · Bluesky
Privacy Policy