Functional Programming Flashcards

1
Q

What is functional programming?

A

Functional programming (often abbreviated FP) is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects. Functions are first class citizens of such languages.

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

Which is imperative and which is declarative?

A

FP - Declarative and OOP - Imperative

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

Where does application state reside in FP vs OOP?

A

Application state flows through pure functions, as opposed to OOP where the state is usually shared and colocated with methods in objects.

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

Examples of some functional languages

A

LISP, Erlang, Haskell, F#, Clojure,

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

A pure function ____

A
  • Given same input always returns same value

- Has no side effects

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

Function composition is ______

A

Is process of combining two or more functions to produce new function or produce some output.
f(g(x))

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

Shared state is ______

A

Any variable, object or memory that is shared scope or is a property of object being passed between scopes.

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

Problems with shared state

A
  • To understand the behavior of function you need to know the history of every shared variable that function uses or affects
  • Race condition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Examples of side effects

A
  • Changing global variable or shared variable
  • Logging to console
  • Writing to file
  • Writing to network
  • Triggering any external process
  • Calling other function that has side effects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are higher order functions?

A

HOF is any function which takes function as argument, returns a function or both. They are at higher abstraction levels.
Eg. Monads, Promise, Async etc

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