I am trying to figure out if it's possible to use promises instead of a standard callback in a recursive function.
The way I have it now:
function recursive(data, cb){
(function promiseProvider(data){
return newThenable(data).then(function(val){
if(val.a){
cb(null, val);
}
else {
return promiseProvider(val);
}
});
})(data);
}
This works, but I can't figure out how I could make a pure promise implementation.
Perhaps this would work?
function recursive(data){
return newThenable(data).then(function(val){
if(val.a){
return // <<< ???
}
else {
return recursive(val);
}
});
}
However, that doesn't work.