// Return promise for given async function

'use strict';

var f      = require('es5-ext/lib/Function/functionalize')
  , concat = require('es5-ext/lib/List/concat').call
  , slice  = require('es5-ext/lib/List/slice/call')

  , deferred  = require('./deferred')

  , apply;

apply = function (fn, scope, args, resolve) {
	fn.apply(scope, concat(args, function (error, result) {
		if (error == null) {
			resolve((arguments.length > 2) ? slice(arguments, 1) : result);
		} else {
			resolve(error);
		}
	}));
}

exports = module.exports = f(function () {
	var d = deferred();
	apply(this, null, arguments, d.resolve);
	return d.promise;
});

exports._apply = apply;
// Return promise for given async function

'use strict';

var f       = require('es5-ext/lib/Function/functionalize')
  , slice   = require('es5-ext/lib/List/slice/call')
  , toArray = require('es5-ext/lib/List/to-array').call

  , deferred  = require('./deferred')

  , apply;

apply = function (fn, scope, args, resolve) {
	fn.apply(scope, toArray(args).concat(function (error, result) {
		if (error == null) {
			resolve((arguments.length > 2) ? slice(arguments, 1) : result);
		} else {
			resolve(error);
		}
	}));
}

exports = module.exports = f(function () {
	var d = deferred();
	apply(this, null, arguments, d.resolve);
	return d.promise;
});

exports._apply = apply;
Update up to changes in es5-ext
Update up to changes in es5-ext
