Skip to content

Using contra, asynchronously find a value in a collection that matches a condition.

License

Notifications You must be signed in to change notification settings

smallhelm/contra-find

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

contra-find

build status

Using contra, asynchronously find a value in a collection that matches a condition.

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

About

Using contra, asynchronously find a value in a collection that matches a condition.

Resources

License

Stars

Watchers

Forks

Packages

No packages published