var equal      = require('deep-equal'),
    gengisKhan = exports;

function $all(objectField, subQuery) {

}

var dispatchTable = {
  '$all': $all,
};

function parseSpecial(objectField, subQuery) {
  var matches = true;
  Object.keys(subQuery).forEach(function(subQueryKey) {
    if(dispatchTable[subQueryKey]) {
      if(!dispatchTable[subQueryKey](objectField, subQuery[subQueryKey]))
        matches = false;
      return;
    }
    throw new Error('Unknown symbol ' + subQueryKey);
  });

  return matches;
}

function filterWithQuery(query) {
  return function(object) {
    var matches = true;

    Object.keys(query).forEach(function(queryKey) {
      var queryValue = query[queryKey];

      if(typeof value === 'object') {
        if(!parseSpecial(object[queryKey], queryValue))
          matches = false;
        return;
      }

      if(!equal(query[queryKey], object[queryKey]))
        matches = false;
    });

    return matches;
  };
}

gengisKhan.match = function(objects, query) {
  if(typeof query === 'string') {
    /*
     * XXX: Yes, it's dumb. No, no way around it.
     *      Keep hatin' ◕ ◡ ◔
     */
    eval('query = ' + query);
  }

  return objects.map(filterWithQuery(query));
};


@@ -33,16 +33,52 @@
 qual'),%0A
+    _          = require('lodash'),%0A
     geng
@@ -234,69 +234,57 @@
 %7B%0A  
-var matches = true;%0A  Object.keys(subQuery).forEach(function(
+return _.every(subQuery, function(subQueryValue, 
 subQ
@@ -332,21 +332,22 @@
 ey%5D)
- %7B
 %0A      
-if(!
+return 
 disp
@@ -408,54 +408,10 @@
 ey%5D)
-)%0A        matches = false;%0A      return;%0A    %7D
+;%0A
 %0A   
@@ -470,27 +470,8 @@
  %7D);
-%0A%0A  return matches;
 %0A%7D%0A%0A
@@ -565,66 +565,39 @@
     
-Object.keys(query).forEach(function(queryKey) %7B%0A      var 
+return _.every(query, function(
 quer
@@ -606,27 +606,21 @@
 alue
- =
+,
  query
-%5BqueryKey%5D;
+Key) %7B
 %0A%0A  
@@ -663,20 +663,23 @@
         
-if(!
+return 
 parseSpe
@@ -716,166 +716,80 @@
 lue)
-)%0A   
+;%0A
       
- matches = false;%0A        return;%0A      %7D%0A%0A      if(!equal(query%5BqueryKey%5D, object%5BqueryKey%5D))%0A        matches = false;%0A    %7D);%0A%0A    return matches
+%7D%0A%0A      return equal(query%5BqueryKey%5D, object%5BqueryKey%5D);%0A    %7D)
 ;%0A  

move to lodash