This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Q = require('q'); | |
/** | |
* Transforms a Promise to a Q promise | |
* @param {Promise} promise | |
* @return {Q} | |
*/ | |
function pq(promise) { | |
const deferred = Q.defer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const Q = require('q'); | |
const fn = require('fn.js'); | |
// Maps a function that returns a promise and then passes that array of promises to Q.all so they are all processed | |
const mapAll = fn.curry(fn.compose(Q.all, fn.map), 2); | |
// Returns a promise | |
function returnPromise(something) { | |
return Q().then(() => something); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Q = require('q'); | |
/** | |
* Transforms a Q Promise to a Promise | |
* @param {QPromise} qpromise | |
* @return {Promise} | |
*/ | |
function qp(qpromise) { | |
return new Promise(function(resolve, reject) { | |
qpromise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Rx = require('rx'); | |
getPages(5, 1) | |
.then(reduceToPromise) | |
.then(console.log) | |
function getPages(perPage, page) { | |
return new Promise(function(resolve, reject) { | |
resolve(getAllPages(perPage, page)); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fn = require('fn.js'); | |
const or = fn.curry((defaultValue, value) => value ? value : defaultValue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fn = require('fn.js'); | |
const has = fn.curry(function(key, object) { | |
if (!object[key]) { | |
throw new Error(`Missing key '${key}' on object`); | |
} | |
return object; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Q = require('q'); | |
/** | |
* Method to reduce observable to a promise. | |
* | |
* @param observable | |
*/ | |
function reduceToPromise(observable) { | |
return observable.reduce((acc, item) => [...acc, item], []) | |
.toPromise(Q.Promise); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const searchedBookShelf = originalBooks.reduce((searchedBook, originalBook) => { | |
if (originalBook.id === bookOnShelf.id) { | |
return originalBook.shelf; | |
} | |
return searchedBook; | |
}, null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const unique = list => list.filter((value, index, list) => list.indexOf(value) === index); | |
const sortNumber = (a, b) => a - b; | |
const expandBlock = (accum, block) => { | |
if (block.indexOf('-') === -1) { | |
accum.push(parseInt(block)); | |
return accum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const async = require('async'); | |
const pg = require('pg') | |
// QueryConnect: (QuerySource, Callback) -> Connection | |
// QueryDisconnect: Connection -> Connection | |
// getSmartQuery : (QueryConnect, QueryDisconnect, QuerySource) -> SmartQuery | |
function getSmartQuery(connect, disconnect, querySource) { | |
let conn = null; | |
function connectClient(query, _connectClient) { |
OlderNewer