@@ -331,19 +331,29 @@ const CPS = cpsFn => {
331331/* ------- CPS utils ------ */
332332
333333/**
334- * Convert NodeJS Api function to CPS factory
334+ * Convert NodeJS function to CPS factory
335335 *
336- * @param {Function } nodeApi - function with Node style callback `cb` as last argument:
337- * cb(error, result)
338- * @returns {Function } node2cps(nodeApi ) - CPS factory function taking all args but last
339- * that returns CPS function with 2 callbacks similar to Promise
336+ * @param {Function } nodeF - function with Node style callback `cb` as last argument:
337+ * cb(error, result)
338+ * @returns {Function } node2cps(nodeF ) - CPS factory function taking all args but last
339+ * that returns CPS function with 2 callbacks similar to Promise
340340 */
341- const node2cps = nodeApi => ( ...args ) => CPS (
342- ( onRes , onErr ) => nodeApi ( ...args , ( e , ...x ) => e ? onErr ( e ) : onRes ( ...x ) )
341+ const node2cps = nodeF => ( ...args ) => CPS (
342+ ( onRes , onErr ) => nodeF ( ...args , ( e , ...x ) => e ? onErr ( e ) : onRes ( ...x ) )
343343)
344344
345+ /**
346+ * Convert Promise factory to CPS factory
347+ * makes promise lazy by defering promise creation
348+ *
349+ * @param {Function } promiseFactory - function that returns Promise
350+ * @returns {Function } promiseF2cps(promiseFactory) - CPS factory function
351+ */
352+ const promiseF2cps = promiseFactory => ( ...args ) => ( onRes , onErr ) => promiseFactory ( ...args ) . then ( onRes , onErr )
353+
354+
345355module . exports = {
346356 curry2, pipeline, pipe,
347357 of, ofN, map, chain, filter, scan, scanS, ap, lift2,
348- CPS , node2cps
358+ CPS , node2cps, promiseF2cps
349359}
0 commit comments