Fundamentals of Functional Programming

Cards (37)

  • What are the features of functional programming?
    • Statelessness and Immutability
    • Functions are used as the fundamental building blocks
    • No side affects
  • What is a function
    a rule that for each element of some set A of inputs, assigns an output chosen from a set B but without necessarily using every member of B.
  • What is a domain?
    A domain is a set from which the function's input values are chosen
  • What is a co-domain
    a set from which the functions outputs values are chosen
  • What is a first class object?
    something that:
    • Can be assigned to a variable
    • appear in an expression
    • be assigned as an argument
    • be returned in a function call
  • Give some examples of first class objects?
    • integers
    • floats
    • characters
    • strings
  • What does it mean when functions are refered to as statelesss
    • do not rely on or alter any state outside of their scope
  • What is immutability?
    • once a data structure is created, it cannot be changed
  • What is functional programming?
    A programming paradigm based on functions
  • What defines a higher order function?
    It takes or returns a function
  • What does the map function do?
    Applies a function to a list of elements
  • If you want to subtract 2 from each element in a list, which function would you use?
    Map function
  • What is the purpose of the filter function?
    Returns elements that meet a specific condition
  • If you want to keep only elements greater than 1 from a list, which function would you use?
    Filter function
  • What does folding a list do?
    Reduces the list to a single value
  • What is another name for folding?
    Reducing
  • What does the fold function require?
    An operator, a starting number, and a list
  • What type of fold will you be asked questions about?
    Fold left
  • What is the specification for functional language programs?
    Show experience of constructing simple programs
  • What is a higher-order function?

    A function that takes or returns another function
  • What does the map function return?
    A list of results after applying a function
  • What does the filter function produce?
    A new data structure with matching elements
  • What does the reduce or fold function do?
    Reduces a list to a single value
  • What is the main focus of the fold function?
    To apply a combining function repeatedly
  • What is the difference between fold left and fold right?
    It determines how recursion works
  • What is the expected knowledge for using higher-order functions?
    Experience with map, filter, and fold
  • What are the key characteristics of higher-order functions?
    • Take a function as an argument
    • Return a function as a result
    • Do both of the above
  • What are the steps involved in using the map function?
    1. Provide a function to apply
    2. Provide a list of elements
    3. Return a new list with results
  • What are the steps involved in using the filter function?
    1. Provide a condition to check
    2. Provide a list of elements
    3. Return a new list with matching elements
  • What are the steps involved in using the fold function?
    1. Provide an operator (e.g., +, -)
    2. Provide a starting number
    3. Provide a list of values
    4. Return a single reduced value
  • What is the difference between fold left and fold right?
    • Fold left processes elements from the start
    • Fold right processes elements from the end
  • What is the composition of functions?

    • the idea that you can combine two functions in order to get a new function
  • What is function application?
    • the process of giving particular inputs to a function
  • What is partial function application
    • is the process of decomposing multi-arguments functions into smaller functions with less arguments
  • Why can functional programming easily take advantage of parallel processing
    its focus on immutability, pure functions, and the absence of shared mutable state
  • Explain the purpose of fold/reduce in functional programming?
    • Fold takes a list of values and returns a single value by applying combining function
  • Explain how the function map double [1,2,3,4] works (double x :: x*2)
    • the map applies the double function to each list item
    • the map applies double first the head of the list and then a recursive call is made on the tail of the list