12: Fundamentals of Functional Programming Flashcards
f: A → B
Function type is A → B, A is the argument type and the domain and B is the result type and the co-domain
The domain and co-domain are always ____
Subsets of objects in some data type
First-Class Object
A function in functional programming and in imperative programming languages that support such objects
First-Class Objects May (4)
- Appear in expressions
- Be assigned to a variable
- Be assigned as arguments
- Be returned in function calls
Partial Function Application
Where a function, taking multiple arguments, is parsed less arguments so returns a function, which takes the missing arguments, before returning a value
Partial Function Notation (5)
- The function add takes two integers as arguments and gives an integer as a result
- add: integer → (integer → integer)
- add 4 returns a function, which when applied to another integer, adds 4 to that integer
- The brackets may be dropped: add: integer → integer → integer
- The function add is now viewed as taking one argument after another and returning a result of data type integer
Composition of Functions (4)
- The operation functional composition combines two functions to get a new function
- Given two functions:
f: A → B
g: B → C - The function g ⚬ f, called the composition of g and f, is a function whose domain is A and co-domain is C
- f is applied first and then g is applied to the result returned by f
Head
The first element of a list
Tail
The list of all elements apart from the head
Prepend
Adds a single item, of the same data type as those in the list, to the start of the list
Append
Adds a list of items, with the same data type as those in the other list, to the end of the other list
Higher-Order Function
A function that takes a function as an argument or returns a function as a result, or does both
Map
A higher-order function that applies a given function to each element of a list, returning a list of results
Filter
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.
Reduce / Fold
A higher-order function which reduces a list of values to a single value by repeatedly applying a combining function to the list values