Pure and Impure Functions

concepts csharp

Side Effects

A function is said to have side effects if it does any of the following:

  • Mutates global state

  • Mutates its input arguments

  • Throws exceptions

  • Performs any I/O operation

Pure Functions

A pure function has the following properties:

  • Output depends entirely on the input arguments.

  • Causes no Side Effects.

Impure Functions

An impure function has the following properties:

  • Factors other than input arguments can affect the output.

  • Can cause Side Effects.