I'm trying to figure out how to do a late bind of a promise function parameter. In most cases, I like to have promise flow just be a series of function names, so that it reads like a series of steps (unless it's a one liner like below)
(adjustedDate) => { aGreatFunctionNeedingADateInput.bind(undefined,adjustedDate) }
Here's an example. The function is waiting for a date, as it's late binded input, and that input will come from some step in the promise chain before it.
let aGreatFunctionNeedingADateInput = greatFunction.bind(undefined, x, y);
somePromise().then(functionThatMightChangeDate)
.then( (adjustedDate) => {
aGreatFunctionNeedingADateInput.bind(undefined,adjustedDate)
})
.then(aGreatFunctionNeedingADateInput)
I know there's a lot of strange and potentially wrong scoping going on here, but essentially I want to bind the last argument of a promise function as a last step, in case it gets changed along the way. Let me know if this is possible.
UPDATE:
Found this example at this link: http://lhorie.github.io/mithril-blog/curry-flavored-promises.html
Which achieves a similar result except that it does the binding to a fixed value (John Doe) at creation rather than in the middle of the promise chain like I tried to do below. Similar idea but I can probably adapt it to my uses.
var createdBy = function(user, items) {
return items.filter(function(item) {
return item.createdBy == user
});
};
m.request({method: "GET", url: "/api/projects"})
.then(pastItems) // filter past projects
.then(createdBy.bind(this, "John Doe")) // filter projects created by john doe
.then(log) // log past projects created by john doe