4.12 Functional Programming Flashcards
What is the Domain?
1) The Domain is the set from which the functions input values are chosen
What is the Co-Domain?
1) The Co-Domain is the set from which the functions output values are chosen
What type of object is a function?
1) A function is a first-class object
What are the characteristics of a First-Class Object?
1) Appear in Expressions
2) Assigned to a variable
3) Assigned as arguments
4) Returned in function calls
What is Function Application?
1) Function Application occurs when a function is applied to its arguments
What is the Composition of Functions?
1) The combination of two functions to get a new function
What is a High-Order Function?
1) A higher-order function takes a function as an argument or returns a function as a result or does both
What is a Map?
1) A Map takes in two arguments as inputs
- A Function
- A List
2) The Function is applied to each item of the list to produce a function output with new list
What is the result of the following:
Map (5) [2,5,7,8,9]
[10,25,35,40,45]
What is a Filter?
1) A Filter takes in two arguments as inputs
- A predicate (to define a boolean condition)
- A-List
2) A Function is applied to each item in the list and it returns a new list of each item that matches the predicate
What is the result of the following:
Filter (>6) [2,5,6,8,9]
[8,9]
What is A Fold (Recursive function)
1) Applies a function to each item of a list to produce a single value
2) An initial value is also supplied which will be recursively combined with the next item and so on
What is the result of the following:
Fold (+)0[2,3,4,5]
[2,5,9,14]
How is a list represented?
1) A List is represented as a concatenation of a head and a tail
How are the head and tail split up in a list?
[a,[b,c,d,e]]
a = head
b,c,d,e = tail of a list
Can a list be empty?
Yes
Explain what the following operation does?
tail(list)
Returns a new list containing all but the first element of the original list
Explain what the following does?
head(list)
Returns the first element in a list
Explain what the following does?
empty(list)
Returns True if a list is empty otherwise False
Explain what the following does?
length(list)
Returns the number of elements in a list
Explain what the following does?
‘ : ‘ list constructor
Adds the items to the beginning of a list
Explain what the following does?
prepend
Adds an item to the start of the list
Explain what the following does?
append
Adds an item to the end of the list
What type of list is this?
[]
Empty List