{"action":"created","issue":{"url":"https://api.github.com/repos/MoOx/reduce-function-call/issues/2","labels_url":"https://api.github.com/repos/MoOx/reduce-function-call/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/MoOx/reduce-function-call/issues/2/comments","events_url":"https://api.github.com/repos/MoOx/reduce-function-call/issues/2/events","html_url":"https://github.com/MoOx/reduce-function-call/pull/2","id":88762106,"number":2,"title":"Start promises refactor.","user":{"login":"ben-eb","id":1282980,"avatar_url":"https://avatars.githubusercontent.com/u/1282980?v=3","gravatar_id":"","url":"https://api.github.com/users/ben-eb","html_url":"https://github.com/ben-eb","followers_url":"https://api.github.com/users/ben-eb/followers","following_url":"https://api.github.com/users/ben-eb/following{/other_user}","gists_url":"https://api.github.com/users/ben-eb/gists{/gist_id}","starred_url":"https://api.github.com/users/ben-eb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ben-eb/subscriptions","organizations_url":"https://api.github.com/users/ben-eb/orgs","repos_url":"https://api.github.com/users/ben-eb/repos","events_url":"https://api.github.com/users/ben-eb/events{/privacy}","received_events_url":"https://api.github.com/users/ben-eb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-16T15:35:50Z","updated_at":"2015-06-16T15:45:44Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/MoOx/reduce-function-call/pulls/2","html_url":"https://github.com/MoOx/reduce-function-call/pull/2","diff_url":"https://github.com/MoOx/reduce-function-call/pull/2.diff","patch_url":"https://github.com/MoOx/reduce-function-call/pull/2.patch"},"body":"#1"},"comment":{"url":"https://api.github.com/repos/MoOx/reduce-function-call/issues/comments/112475985","html_url":"https://github.com/MoOx/reduce-function-call/pull/2#issuecomment-112475985","issue_url":"https://api.github.com/repos/MoOx/reduce-function-call/issues/2","id":112475985,"user":{"login":"ben-eb","id":1282980,"avatar_url":"https://avatars.githubusercontent.com/u/1282980?v=3","gravatar_id":"","url":"https://api.github.com/users/ben-eb","html_url":"https://github.com/ben-eb","followers_url":"https://api.github.com/users/ben-eb/followers","following_url":"https://api.github.com/users/ben-eb/following{/other_user}","gists_url":"https://api.github.com/users/ben-eb/gists{/gist_id}","starred_url":"https://api.github.com/users/ben-eb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ben-eb/subscriptions","organizations_url":"https://api.github.com/users/ben-eb/orgs","repos_url":"https://api.github.com/users/ben-eb/repos","events_url":"https://api.github.com/users/ben-eb/events{/privacy}","received_events_url":"https://api.github.com/users/ben-eb/received_events","type":"User","site_admin":false},"created_at":"2015-06-16T15:45:44Z","updated_at":"2015-06-16T15:45:44Z","body":"Also, here's where I got to with trying to (unsuccessfully) reimplement recursion:\r\n\r\n```js\r\nfunction reduceFunctionCall(string, regex, callback) {\r\n  return new Promise(function(resolve) {\r\n    function recurse(str) {\r\n      var calls = getFunctionCalls(str, regex)\r\n      if (!calls.length) {\r\n        return resolve(string)\r\n      }\r\n\r\n      calls.forEach(function(call) {\r\n        var transform = callback(call.matches.body, call.functionIdentifier, string)\r\n        Promise.resolve(transform).then(function(replacement) {\r\n          var target = call.functionIdentifier + \"(\" + call.matches.body + \")\"\r\n          string = string.replace(target, replacement)\r\n          recurse(call.matches.body)\r\n        })\r\n      })\r\n    }\r\n\r\n    recurse(string)\r\n  })\r\n}\r\n```"}}