The problem is this: I have a list of questions, each of which has an associated policy. For a particular user, I need to check the policy to see if it’s appropriate to ask the question for this user.
So, policy evaluation is per user and per question. However, my API offers the ability to get all relevant questions for a particular user. So every time, I need to evaluate policy for a set of questions. Each policy evaluation may involve an async call to the data store. The policy evaluation function for a particular user and question returns a boolean, like this:
iterator argument to
filterSeries takes a single argument (i.e. the question). I could work around this by making the
arr argument an array of objects with both a user and a question but that’s inefficient and inelegant.
A much more elegant solution is to use closures to produce just the iterator function I want: one for a particular user.
Now, I can call this function to produce the iterator when I need it: