12 - Fundamentals of Functional Programming Flashcards
Explain the purpose of the fold function in a functional programming language.
It reduces a list of values to a single value by applying a combining function.
Explain what a higher-order function is.
A function that takes a function as an argument or returns a function as a result.
What is map?
A higher-order function that applies a given function to each element of a list, returning a list of results.
eg. map (*2) [1,2,3] outputs [2,4,6]
What is 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.
eg. filter (<5) [1,4,6] outputs [1,4]
What is fold?
A higher-order function which reduces a list of values to a single value by repeatedly applying a combining function to the list of values.
What is the head of a list?
The first element in the list
eg the head of [1,2,3] is 1
What is the tail of a list?
A list containing each element other than the first element of the list
eg the tail of [1,2,3] is [2,3]