functionally
Advanced tools
Comparing version 0.4.1 to 0.5.0
17
index.js
@@ -0,1 +1,4 @@ | ||
var setImmediate = function(fn){ | ||
setTimeout(fn, 0) | ||
} | ||
/** | ||
@@ -76,3 +79,3 @@ * Utility methods for working with functions. | ||
find = curry(function(fn, target){ | ||
find = curry(function(fn, target, onFound){ | ||
if (typeof target.find == 'function'){ | ||
@@ -82,2 +85,8 @@ return target.find(fn) | ||
onFound = typeof onFound == 'function'? | ||
onFound: | ||
function(found, key, target){ | ||
return found | ||
} | ||
if (Array.isArray(target)){ | ||
@@ -91,3 +100,3 @@ var i = 0 | ||
if (fn(it, i, target)){ | ||
return it | ||
return onFound(it, i, target) | ||
} | ||
@@ -111,7 +120,7 @@ } | ||
if (fn(it, k, target)){ | ||
return it | ||
return onFound(it, k, target) | ||
} | ||
} | ||
} | ||
}), | ||
}, 2), | ||
@@ -118,0 +127,0 @@ bindFunctionsOf = function(obj) { |
{ | ||
"name": "functionally", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
describe('Find', function(){ | ||
var should = require('should') | ||
var find = require('../index').find | ||
@@ -52,2 +54,12 @@ | ||
}) | ||
it('should work with onFound', function(){ | ||
var index = find(function(n){ | ||
return n == 4 | ||
}, [5,4,7,9], function(n, i){ | ||
return i | ||
}) | ||
should(index).equal(1) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
67274
783
33