4.12: section 12: OOP and functional programming Flashcards
define function application
process of giving particular inputs to a function
what is function type
f: A ->B
f = function
A = argument type: set of inputs =domain
B = result type
set of outputs = co-domain
A and B must be subsets of objects in some data type
how many arguments can functions take
- although it seems multiple functions are being passed through only 1 is actually being applied
- instead the result and function are passed as inputs
define partial function application
takes advantage of the inability of a function to take more than one input
-one of the arguments is fixed leading to a more restricted specialized function
define composition functions
operation functional composition combines two functions to get a new function.
what is a high order function
A function is higher-order if it takes a function as an argument or returns a function as a result, or does both.
what is the map function
a higher-order function that applies a given function to each element of a list, returning a list of results.
what is a filter function
a higher-order function that processes a data structure, typically a list, in some order to produce a new data structure containing exactly those elements of the original data structure that match a given condition.
what is the reduce or fold function
a higher-order function which reduces a list of values to a single value by repeatedly applying a combining function to the list values.
-can be started from the left or right of the list
what is the head and tail of a list
head: first element in a list
tail: all remaining elements
how do you return the head of a list
head list_Name
how do you return the tail of a list
tail list_Name
how do you test for a empty list
null list_Name
how do create an empty list
list_Name = []
how do you return a list length
length list_Name