0

I came across this Codewars question:

Your task is to write a higher order function for chaining together a list of unary functions. In other words, it should return a function that does a left fold on the given functions.

chained([a,b,c,d])(input)

Should yield the same result as

d(c(b(a(input))))

I don't really care what the answer to the problem is, I can access that on the site. What I actually need explained to me is the first function, "chained". I've never seen a function like that with 2 sets of argument in separate parenthesis, so I imagine I'm interpreting it incorrectly.. what does that mean? Thanks for the help

2 Answers 2

1

It is not a function with two sets of parameters, but a function that returns another function, executing the functions given as parameters one after the other.

Maybe it's clearer if you separate the line into two lines:

f = chained([a,b,c,d]) # call `chained` with functions as parameters
f(input)               # call result of `chained`, which is another function
Sign up to request clarification or add additional context in comments.

Comments

0

As stated in the question chained is a higher order function - it will take one argument - list of functions and will return/yield a function. That function is called by passing one argument - another function, in this case input.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.