What are Pure Functions?

The concept of pure functions explained in under 100 words. #under100

What are Pure Functions?

A pure function is a deterministic method with no side effects.

Being deterministic means that a given set of inputs will always produce the same outputs, making them easy to test.

And having no side effects means that you can safely call a pure function without having to worry about the effect it might have on the rest of your application.

Whenever possible, write your application's complex logic as pure functions.  This allows you to focus on solving (and testing) those problems without worrying how it will affect everything else.

Further Reading

See section 13.1.3, "Referential Transparency," in Code That Fits in Your Head, by Mark Seemann.

All original code samples by Mike Wolfe are licensed under CC BY 4.0