summaryrefslogtreecommitdiff
path: root/lib/internal/filter.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/filter.js')
-rw-r--r--lib/internal/filter.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/internal/filter.js b/lib/internal/filter.js
new file mode 100644
index 0000000..8b1de9f
--- /dev/null
+++ b/lib/internal/filter.js
@@ -0,0 +1,30 @@
+'use strict';
+
+import arrayMap from 'lodash/_arrayMap';
+import property from 'lodash/_baseProperty';
+
+export default function _filter(eachfn, arr, iterator, callback) {
+ var results = [];
+ eachfn(arr, function (x, index, callback) {
+ iterator(x, function (err, v) {
+ if (err) {
+ callback(err);
+ }
+ else {
+ if (v) {
+ results.push({index: index, value: x});
+ }
+ callback();
+ }
+ });
+ }, function (err) {
+ if (err) {
+ callback(err);
+ }
+ else {
+ callback(null, arrayMap(results.sort(function (a, b) {
+ return a.index - b.index;
+ }), property('value')));
+ }
+ });
+}