<commit_before>'use strict';

var curry       = require('es5-ext/lib/Function/curry')
  , isFunction  = require('es5-ext/lib/Function/is-function')
  , noop        = require('es5-ext/lib/Function/noop')
  , sequence    = require('es5-ext/lib/Function/sequence')

  , isPromise   = require('./is-promise')

  , deferred, then, throwError, end;

then = function (ignore, callback) {
	var d = deferred();
	setTimeout(callback ?
		sequence(curry(callback, this), d.resolve) :
		d.resolve.bind(d, this), 0);
	return d.promise;
};

throwError = function () {
	throw this;
};

end = function (handler) {
	setTimeout(
		isFunction(handler) ? curry(handler, this) : throwError.bind(this), 0);
};

module.exports = function (value) {
	if (isPromise(value)) {
		return value;
	} else if (value instanceof Error) {
		return {
			then: then.bind(value),
			end: end.bind(value)
		};
	} else {
		return {
			then: then.bind(value, null),
			end: noop<commit_msg>Binding primitive to function won't work with older JS implementations.<commit_after>'use strict';

var curry       = require('es5-ext/lib/Function/curry')
  , isFunction  = require('es5-ext/lib/Function/is-function')
  , noop        = require('es5-ext/lib/Function/noop')
  , sequence    = require('es5-ext/lib/Function/sequence')

  , isPromise   = require('./is-promise')

  , deferred, then, throwError, end;

then = function (value, ignore, callback) {
	var d = deferred();
	setTimeout(callback ?
		sequence(curry(callback, value), d.resolve) :
		d.resolve.bind(d, value), 0);
	return d.promise;
};

throwError = function () {
	throw this;
};

end = function (handler) {
	setTimeout(
		isFunction(handler) ? curry(handler, this) : throwError.bind(this), 0);
};

module.exports = function (value) {
	if (isPromise(value)) {
		return value;
	} else if (value instanceof Error) {
		return {
			then: curry(then, value),
			end: end.bind(value)
		};
	} else {
		return {
			then: curry(then, value, null),
			end: noop
{'fraction_non_alphanumeric': 0.15912557193695984, 'fraction_numerical': 0.006100660904931368, 'mean_word_length': 3.708133971291866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4960186', 'n_tokens_mistral': 723, 'n_tokens_neox': 670, 'n_words': 151}