Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.0.3 - add some mapP methods. Specs and descriptions pushing soon
- Loading branch information
1 parent
b4b555c
commit e95ffe4
Showing
5 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
var R = require('ramda'), | ||
Q = require('q'); | ||
|
||
var mapPairs = require('./mapPairs.js'); | ||
|
||
// (a -> Promise b) -> [(c, a)] -> Promise [(c, b)] | ||
var mapPairsP = R.curry(function(f, pairs) { | ||
var pairsWithPromiseAsSecondValue = mapPairs(f, pairs), | ||
pairPromises = pairsWithPromiseAsSecondValue, | ||
promiseOfPairs = Q.all(pairPromises); | ||
return promiseOfPairs; | ||
}); | ||
|
||
// (a -> Promise b) -> {c: a} -> Promise {c: b} | ||
var mapObjP = R.curry(function(f, obj) { | ||
var pairs = R.toPairs(obj); | ||
return mapPairsP(f, pairs).then(R.fromPairs); | ||
}); | ||
|
||
module.exports = mapObjP; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
var R = require('ramda'), | ||
Q = require('q'); | ||
|
||
|
||
// (a -> Promise b) -> [a] -> Promise [b] | ||
var mapP = R.curry(function(f, vs) { | ||
return Q.all(R.map(f, vs)); | ||
}); | ||
|
||
module.exports = mapP; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
var R = require('ramda'), | ||
Q = require('q'); | ||
|
||
// (a -> b) -> (c, a) -> (c, b) | ||
var callOnPair = R.curry(function(f, pair) { | ||
return [pair[0], f(pair[1])]; | ||
}); | ||
|
||
// (a -> b) -> [(c, a)] -> [(c, b)] | ||
var mapPairs = R.curry(function(f, pairs) { | ||
return R.map(callOnPair(f), pairs); | ||
}); | ||
|
||
module.exports = mapPairs; |
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