Functional Programming - Understand Functional Programming Terminology

Tell us what’s happening:

Does my understanding about first class, higher order and lambda correct base on the comments I make on this problem?

Just making sure to understand it well, thanks for replies.

Your code so far

//This are lambda
const prepareGreenTea = () => 'greenTea';
const prepareBlackTea = () => 'blackTea';

//This one is a first class since it was declared as a variable
const getTea = (prepareTea, numOfCups) => {
  const teaCups = [];

  for(let cups = 1; cups <= numOfCups; cups += 1) {
    const teaCup = prepareTea();
    teaCups.push(teaCup);
  }
  return teaCups;
};

//Then this one is higher order functions as the getTea function accepts a function as an argument
const tea4GreenTeamFCC = getTea(prepareGreenTea, 27);
const tea4BlackTeamFCC = getTea(prepareBlackTea, 27);


console.log(
  tea4GreenTeamFCC,
  tea4BlackTeamFCC
);

Challenge: Functional Programming - Understand Functional Programming Terminology

AFAIK, a lambda function is an anonymous function, so usually they are callback functions but they are used only once and without an assigned name.

In terms of a first-class functions, it simply means that a language (such as JavaScript) provides a behavior to its functions very much like how we intend to use a variable, i.e. assign it to a variable, argument to a function, or return it as value from a function call.

1 Like

For the higher-order function, you got it correctly, because a higher-order function is a function that accepts one/more functions as an argument and/or return it as a value after a function call.

1 Like

Thank you for replying @arantebillywilson! It’s a little bit confusing but this is surely why I need to read more about this topic and look some examples. Thank you, I appreciate it! :heart:

1 Like

Just keep it up! This is the very reason why this community exists.

1 Like