Functional Programming Flashcards
What is functional programming?
Using functions as the primary building blocks and avoiding using mutable state.
What are the pros of functional programming over imperative programming?
Powerful abstraction
expressive and concise code
easier to test
Code optimization
What is imperative programming?
Code that describes HOW something should happen, involving explicit instructions at each step.
What is declarative programming?
Focuses on WHAT should happen, abstracting the control flow.
What is function chaining?
The output of one function serves as the input to another.
What is a BiFunction?
A two argument method in FP.
What is a consumer?
A void function in FPWhat
is a predicate?
A Boolean function in FP
what is a Supplier?
Object function in FP
What is the structure of a BiFunction that takes two integers and returns a third?
BiFunction <int, int, int> functionName = (arg1, arg2) -> expression;
ex:
BiFunction<int, int, int> calcArea = (length, width) -> length*width;
How do you use a BiFunction?
With the ‘apply’ keyword.
ex: area = calcArea.apply(3,5)
How do you use a consumer?
With the ‘accept’ keyword.
How do you use a predicate?
With the ‘test’ keyword.
How do you use a supplier?
With the ‘get’ keyword.