You are on page 1of 1

programming paradigm in which we try to bind everything in pure mathematical

functions style
Functional programming is a programming style that focuses on using functions to
solve problems. In simple terms, it treats computations as the evaluation of
mathematical functions, just like how you might use a calculator to perform
calculations.

A pure function is a function that, given the same input, always produces the same
output and has no side effects (i.e., it doesn't modify external state). It only
depends on its input and doesn't interact with global variables or other external
data.

No Side Effects: Pure functions should not have any observable side effects,
including print statements or any other actions that interact with the external
world.

No Exceptions: Pure functions should not throw exceptions or handle errors


directly. They should communicate errors through their return values or functional
constructs like Maybe/Option types.

Immutability: Pure functions should be immutable, meaning they should not modify
the data they receive as arguments. Instead, they should create new variables or
data structures with updated values and return them as the result.

Deterministic: Pure functions should be deterministic, meaning that given the same
input, they always produce the same output. There should be no randomness or time-
dependent behavior.

Pure Functions:
Pure functions are functions that have two main characteristics:

They always produce the same output for the same given input.
They do not cause any side effects, such as modifying external state or variables.
In other words, pure functions are predictable and don't change anything outside of
their scope. They are a fundamental concept in functional programming and make code
easier to reason about and test.
No Side Effects:
Side effects refer to any observable change or interaction that a function has with
the external world beyond its return value. In functional programming, functions
are designed to have no side effects. They do not modify global variables, perform
I/O operations like writing to files, or display output. Instead, they focus solely
on transforming input data to produce a result without affecting anything else in
the program.

Recursion:
Recursion is a programming technique where a function calls itself to solve a
problem by breaking it down into smaller, similar subproblems. It is an alternative
to iterative loops commonly used in imperative programming. Recursive functions
have a base case that stops the recursion and prevents infinite loops. Recursion is
particularly favored in functional programming because it aligns well with the
principles of immutability and pure functions, making it a powerful tool for
solving complex problems in an elegant and concise manner.

You might also like