https://github.com/smallhelm/contra-find
Using contra, asynchronously find a value in a collection that matches a condition.
https://github.com/smallhelm/contra-find
Last synced: 7 months ago
JSON representation
Using contra, asynchronously find a value in a collection that matches a condition.
- Host: GitHub
- URL: https://github.com/smallhelm/contra-find
- Owner: smallhelm
- License: mit
- Created: 2016-06-29T19:39:03.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-29T20:00:48.000Z (almost 10 years ago)
- Last Synced: 2025-01-31T12:49:38.044Z (over 1 year ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# contra-find
[](https://travis-ci.org/smallhelm/contra-find)
Using contra, asynchronously find a value in a collection that matches a condition.
```js
var λ = require('contra');
var find = require('contra-find');
var items = [
[1, 2],
[2, 3],
[3, 4],
[4, 5],
[5, 6]
];
find(λ, items, function(item, next){
console.log('item :', item);
process.nextTick(function(){
console.log('check:', item);
next(undefined, item[0] === 3);
});
}, function(err, item){
console.log('item found!', item);
});
```
output
```
item : [ 1, 2 ]
check: [ 1, 2 ]
item : [ 2, 3 ]
check: [ 2, 3 ]
item : [ 3, 4 ]
check: [ 3, 4 ]
item found! [ 3, 4 ]
```
Notice that it iterates in series and stops as soon as the item is found.
## License
MIT