Functional Programming and Lambda Expressions Flashcards

1
Q

What are lambda expressions?

A

Expressions that use behaviour/methods as parameters.

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

How can lambdas be declared?

A

anonymously (numbers.forEach(n -> System.out.println(n));) or explicitly (Consumer<Integer> printInts = i -> System.out.println(i); numbers.forEach(printInts);)</Integer>

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

How do anonymously declared lambdas look like?

A

parameter -> expression ||
parameter -> {block} ||
(parameter1, parameter2) -> expression ||
(parameter1, parameter2) -> { block }

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

What are similar to lambda expressions and why?

A

Static method references, because they allow class methods to be passed as parameters.(numbers.forEach(Printer::printInts); or Printer p = new Printer();
numbers.forEach(p::printInts);)

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

Why is FunProg used in Java?

A
  • centered around chaining functions
  • helps with lazy evaluation and parallelization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some use cases of FunProg in Java?

A
  • distributed computing
  • data processing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the main elements of functional programming in Java?

A

Functional programming in java takes advantage of the Stream API to allow sequential or parallel chaining of functions, which are evaluated lazily. Also, lambda expressions or methods references are often used to pass operations as parameters.
(Pure functions - they have no sides effects, immutability - do not modify input, chaining functions, recursion- actions are broadcast throughout the chain)

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