From the course: Advanced C#: Functional Programming Patterns

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Function categories

Function categories

In functional programming, we can categorize functions based on their behavior and effects. We looked briefly at some of these terms in the last chapter. Here are the main categories. A pure function always produces the same output given the same input with no side effects. They don't modify any external state or rely on anything other than their input parameters. An impure function can be considered the opposite of a pure function. It may produce different outputs even with the same input due to reliance on external state or randomness. It may cause side effects such as modifying variables, performing I/O operations like reading and writing files, or interacting with a database. Sometimes we must write impure functions, especially when doing I/O work. But the key takeaway for us is that we need to know the difference. Always strive for pure functions where possible and isolate the I/O functions from the pure ones. An effectful function is a function that produces side effects, hence…

Contents