https://github.com/azer/juxt.js
Take a set of functions, return a function that is the juxtaposition of those functions.
https://github.com/azer/juxt.js
Last synced: 11 months ago
JSON representation
Take a set of functions, return a function that is the juxtaposition of those functions.
- Host: GitHub
- URL: https://github.com/azer/juxt.js
- Owner: azer
- Created: 2012-12-15T07:42:34.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-05-14T23:42:14.000Z (about 13 years ago)
- Last Synced: 2025-04-09T07:52:05.157Z (about 1 year ago)
- Language: JavaScript
- Size: 109 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Install
```bash
$ npm install juxt # or wget https://raw.github.com/azer/juxt.js/master/juxt.js
```
## Manual
Take a set of functions, return a function that is the juxtaposition of those
functions. The returned function takes a variable number of arguments and
returns a list containing the result of applying each fn to the arguments.
```javascript
function inc1(n) { return n+1 };
function inc2(n) { return n+2 };
function inc3(n) { return n+3 };
juxt(inc1, inc2, inc3)(314); // returns [315, 316, 317]
```
#### Async
```javascript
juxt.async(searchGoogle, searchDDG, searchBing)("hello world", function(error, results){
if(error) throw error;
results[0] // google
results[1] // duck duck go
results[2] // bing
});
```
Objects can be used, as well;
```js
function turkish(word, callback){ /* some magic here */ }
function french(word, callback){ /* some magic here */ }
function polish(word, callback){ /* some magic here */ }
juxt.async({ 'tr': turkish, 'fr': french, 'pl': polish })("hello", function(error, results){
assert.equal(results.tr, "merhaba");
assert.equal(results.fr, "bonjour");
assert.equal(results.pl, "cześć");
});
```