<commit_before>var r = require('ramda');
var q = require('q');

var pCall  = r.bind(q.fcall, q);
var All    = r.bind(q.all, q);
var asList = function (x) { return [].concat(x) };

var args2List = function (x) { return Array.prototype.slice.call(x); };

var asPThunk          = r.ifElse(r.is(Function), r.identity, r.always);
var mapListToPThunks  = r.pipe(asList, r.map(asPThunk))     ;
var mapListToPromises = r.pipe(mapListToPThunks, r.map(pCall));

var mapListToPromiseSeq = function (seqList) {
	var pThunks = mapListToPThunks(seqList);
	return r.reduce(function (floChain, fn) {
		return floChain.then(fn);
	}, q(r.head(pThunks)()), r.tail(pThunks));
};

var isCondFlo    = r.pipe(r.head, r.isArrayLike);
var isPartialFlo = r.pipe(r.head, r.is(Function));

var identityFlo = function (pEntity) {
	return function (initVal) {
		return q(initVal).then(asPThunk(pEntity));
	};
};

var partialFlo = function (partialForm) {
	return function (initVal) {
		var fn            = r.head(partialForm);
		var fnPartialArgs = r.tail(partialForm);
		var fnPArgs       = r.append(initVal, mapListToPromises(fnPartialArgs));
		return All(fnPArgs).spread(fn);
	};
};

//var condFlo = function (form) {
//	// TODO.
//};

var specialFormFlo = r.cond([
	[isPartialFlo, partialFlo]
	//[isCondFlo, condFlo]
]);

var isSpecialFormFlo = r.both(r.isArrayLike, r.pipe(r.nth(0), r.either(r.isArrayLike, r.is(Function))));
var isIdentityFlo    = r.either(r.is(Function), r.complement(isSpecialFormFlo));

var floForms = [
	[isIdentityFlo, identityFlo],
	[isSpecialFormFlo, specialFormFlo]
];

var mapToPfloForms = r.map(r.cond(floForms));

module.exports = function pflo () {
	return r.pipe(
		args2List,
		mapToPfloForms,
		mapListToPromiseSeq
	)(arguments);
};<commit_msg>partial forms now support placeholder syntax<commit_after>var r = require('ramda');
var q = require('q');

var pCall  = r.bind(q.fcall, q);
var All    = r.bind(q.all, q);
var asList = function (x) { return [].concat(x) };

var args2List = function (x) { return Array.prototype.slice.call(x); };

var asPThunk          = r.ifElse(r.is(Function), r.identity, r.always);
var mapListToPThunks  = r.pipe(asList, r.map(asPThunk))     ;
var mapListToPromises = r.pipe(mapListToPThunks, r.map(pCall));

var mapListToPromiseSeq = function (seqList) {
	var pThunks = mapListToPThunks(seqList);
	return r.reduce(function (floChain, fn) {
		return floChain.then(fn);
	}, q(r.head(pThunks)()), r.tail(pThunks));
};

//var isCondFlo    = r.pipe(r.head, r.isArrayLike);
var isPartialFlo = r.pipe(r.head, r.is(Function));

var identityFlo = function (pEntity) {
	return function (initVal) {
		return q(initVal).then(asPThunk(pEntity));
	};
};

var partialFlo = (function () {
	var updateArgsWithPartialVal = function (placeHolderIdx, partialVal, fnPartialArgs) {
		var pArgsMinusPlaceholder = r.remove(placeHolderIdx, 1, fnPartialArgs);
		return r.insert(placeHolderIdx, partialVal, mapListToPromises(pArgsMinusPlaceholder));
	};

	var appendPartialValToArgs = function (partialVal, fnPartialArgs) {
		return r.append(partialVal, mapListToPromises(fnPartialArgs));
	};
	
	return function (partialForm) {
		return function (partialVal) {
			var fn             = r.head(partialForm);
			var fnPartialArgs  = r.tail(partialForm);
			var placeHolderIdx = r.findIndex(r.equals('__'), fnPartialArgs);
			var hasPlaceholder = r.gt(placeHolderIdx, -1);
			var finalArgs = hasPlaceholder ? updateArgsWithPartialVal(placeHolderIdx, partialVal, fnPartialArgs) : appendPartialValToArgs(partialVal, fnPartialArgs);
			return All(finalArgs).spread(fn);
		}
	};
}());

var specialFormFlo = r.cond([
	[isPartialFlo, partialFlo]
]);

var isSpecialFormFlo = r.both(r.isArrayLike, r.pipe(r.nth(0), r.either(r.isArrayLike, r.is(Function))));
var isIdentityFlo    = r.either(r.is(Function), r.complement(isSpecialFormFlo));

var floForms = [
	[isIdentityFlo,    identityFlo],
	[isSpecialFormFlo, specialFormFlo]
];

var mapToPfloForms = r.map(r.cond(floForms));

module.exports = function pflo () {
	return r.pipe(
		args2List,
		mapToPfloForms,
		mapListToPromiseSeq
	)(arguments);
};





{'fraction_non_alphanumeric': 0.1515225334957369, 'fraction_numerical': 0.00194884287454324, 'mean_word_length': 4.726638772663877, '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': '150445', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1521, 'n_words': 295}