Functional Programming Flashcards

(7 cards)

1
Q

What does closure mean in programming?

A

A closure is a function that remembers and can access variables from its outer (enclosing) scope, even after that outer function has finished executing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a higher-order function in functional programming?

A

A higher-order function is a function that either:
1. Takes one or more functions as arguments, or
2. Returns a function as its result.

Higher-order functions let you write more flexible, reusable, and declarative code, e.g. map(), filter(), reduce(), forEach().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are pure and impure functions?

A

A pure function is a function that:
1. Always returns the same output for the same input (deterministic).
2. Has no side effects — it doesn’t modify anything outside its scope (no changing external variables, no I/O operations, no mutations).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is idempotency, and where is it used?

A

Idempotency is a property of certain operations where performing the same operation multiple times has the same effect as performing it once, e.g. GET, PUT, DELETE are idempotent but POST is not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a monad in programming?

A

A monad is an abstraction that allows you to chain operations together while handling contextual concerns (like handling possible failure, asynchronous values, or side effects) in a clean, composable way, e.g. Promises, arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you know if a function is composite?

A
  1. If a function calls one or more functions internally and passes results from one to the other, it’s likely composite.
  2. If a function is defined using composition helpers or chaining, like:
    const h = x => f(g(x));
  3. Or using utility libraries (like lodash/fp or Ramda) with compose or pipe.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When is function currying used?

A

Currying transforms a function that takes multiple arguments into a sequence of functions, each taking a single argument.

  1. Partial Application: To reuse specialized versions of generic functions.
  2. Functional Composition: To improve code modularity and readability.
  3. Event Handling / Callbacks: To preset parameters for callbacks or event handlers in a clean way.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly