Pure functions, immutability, higher-order functions, currying, monads, functors, recursion and referential transparency.
39 cards · basic cards · AI-written, checked twice. Edit anything.
- What is a pure function?
Show answer
A function that always produces the same output for the same input and has no side effects.
- Name one benefit of using pure functions.
Show answer
They are easier to test, reason about, and parallelize because they have no hidden dependencies.
- What is a side effect in programming?
Show answer
Any observable change outside the function other than its return value, such as modifying global state or performing I/O.
- Define referential transparency.
Show answer
A property where an expression can be replaced with its resulting value without changing program behavior.
- Why does referential transparency matter in functional programming?
Show answer
It enables equational reasoning about code, making programs easier to understand, optimize, and refactor.
- What is immutability?
Show answer
The property that data cannot be changed after creation; instead, operations return new copies with modifications.
- Name one advantage of immutable data structures.
Show answer
They eliminate bugs from unintended mutations, simplify concurrent programming, and enable effective memoization.
- What is a higher-order function?
Show answer
A function that takes one or more functions as arguments or returns a function as its result.
- Give an example of a higher-order function that returns a function.
Show answer
A function that returns a customized function, such as a function factory or a decorator.
- What are first-class functions?
Show answer
Functions treated as values: they can be assigned to variables, passed as arguments, and returned from other functions.
- Define currying.
Show answer
The transformation of a function with multiple parameters into a series of single-parameter functions.
- What is one benefit of currying?
Show answer
It enables partial application, allowing you to create specialized functions by fixing some arguments.
- What is partial application?
Show answer
The process of fixing some arguments of a function to create a new function with fewer parameters.
- How does partial application differ from currying?
Show answer
Currying is a language feature that transforms multi-argument functions into nested single-argument functions; partial application is the practice of fixing some arguments.
- What is recursion?
Show answer
A function calling itself to solve a problem by breaking it into smaller instances of the same problem.