Functional Programming Flashcards

1
Q

What is functional programming?

A

Using functions as the primary building blocks and avoiding using mutable state.

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

What are the pros of functional programming over imperative programming?

A

Powerful abstraction
expressive and concise code
easier to test
Code optimization

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

What is imperative programming?

A

Code that describes HOW something should happen, involving explicit instructions at each step.

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

What is declarative programming?

A

Focuses on WHAT should happen, abstracting the control flow.

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

What is function chaining?

A

The output of one function serves as the input to another.

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

What is a BiFunction?

A

A two argument method in FP.

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

What is a consumer?

A

A void function in FPWhat

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

is a predicate?

A

A Boolean function in FP

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

what is a Supplier?

A

Object function in FP

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

What is the structure of a BiFunction that takes two integers and returns a third?

A

BiFunction <int, int, int> functionName = (arg1, arg2) -> expression;

ex:
BiFunction<int, int, int> calcArea = (length, width) -> length*width;

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

How do you use a BiFunction?

A

With the ‘apply’ keyword.
ex: area = calcArea.apply(3,5)

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

How do you use a consumer?

A

With the ‘accept’ keyword.

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

How do you use a predicate?

A

With the ‘test’ keyword.

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

How do you use a supplier?

A

With the ‘get’ keyword.

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