A recursive function to find nested results
547111
function searchAndCompare(specObject, comparisonObject, currentDescription) {

    if (comparisonObject === undefined) {
        comparisonObject = {};
    }

    for (var key in specObject) {
        if (specObject.hasOwnProperty(key)) {
            currentDescription.push(key);
            if (typeof(specObject[key]) === "string") {
                compare(specObject[key], comparisonObject[key], currentDescription);
            } else {
                searchAndCompare(specObject[key].specs, comparisonObject[key], currentDescription);
            }
            currentDescription.pop();
        }
    }
}
1196418
function findValues(toSearch, ...searchFor) {
  const searchesLen = searchFor.length;
  let results = {};
  let searches = {};

  for (let i = 0; i < searchesLen; i++) {
    searches[searchFor[i]] = true;
  }

  /* Object, Object -> Void */
  function traverseObject(toSearchObj, searchForObj) {
    const allKeys = Object.keys(toSearchObj);
    const len = allKeys.length;

    for (let i = 0; i < len; i++) {
      const key = allKeys[i];
      const val = toSearchObj[key];

      if (searchForObj[key] && !results[key]) {
        results[key] = val;
      } else if (isObject(val)) {
        traverseObject(val, searchForObj);
      } else if (isArray(val)) {
        traverseArray(val, searchForObj);
      }
    }
  }

  /* Array, Object -> Void */
  function traverseArray(arr, searchForObj) {
    const len = arr.length;

    for (let i = 0; i < len; i++) {
      const item = arr[i];

      if (isArray(item)) {
        traverseArray(item, searchForObj);
      } else if (isObject(item)) {
        traverseObject(item, searchForObj);
      }
    }
  }

  traverseObject(toSearch, searches);

  return results;
}
1086446
function traverseFilters(config, levels, levelIdx) {
    var lastIdx = levels.length - 1;
    var val, filters;

    if (!config || levelIdx > lastIdx) { return null; }

    val = config[levels[levelIdx]];


    if (levelIdx === lastIdx) {
        if (val) {
            return val;
        }
        else {
            return config.all;
        }
    }
    else {
        filters = traverseFilters(val, levels, levelIdx + 1);
        if (!filters) {
            filters = traverseFilters(config.all, levels, levelIdx + 1);
        }
        return filters;
    }
}
207753
def recursive_map(func, data):
    
    def recurse(item):
        return recursive_map(func, item)
    items_mapped = map_collection(recurse, data)
    return func(items_mapped)
91984
def get_nested_dicts_with_key_containing_value(parent_dict: dict, key, value):
    """"""
    references = []
    NestedLookup(parent_dict, references, NestedLookup.key_value_containing_value_factory(key, value))
    return (document for document, _ in references)
1262475
def _traverse(summary, function, *args):
    
    function(summary, *args)
    for row in summary:
        function(row, *args)
        for item in row:
            function(item, *args)
1081338
private static TreeElement recursiveFindSelected(TreeElement elem)
    {
        assert(elem != null);

        if (elem.isSelected())
            return elem;

        TreeElement children[] = elem.getChildren();
        assert(children != null);
        for (int i = 0; i < children.length; i++) {
            TreeElement e = recursiveFindSelected(children[i]);
            if (e != null)
                return e;
        }
        return null;
    }
248994
function findNodes(node, kind, max = Infinity) {
    if (!node || max == 0) {
        return [];
    }
    const arr = [];
    if (node.kind === kind) {
        arr.push(node);
        max--;
    }
    if (max > 0) {
        for (const child of node.getChildren()) {
            findNodes(child, kind, max).forEach(node => {
                if (max > 0) {
                    arr.push(node);
                }
                max--;
            });
            if (max <= 0) {
                break;
            }
        }
    }
    return arr;
}
399428
def is_nested(values):
    ''''''
    return (all(isinstance(item, Iterable) for item in values)
            if isinstance(values, Iterable) else False)
424539
def resolve_composed_functions(data, recursive=True):
    

    if isinstance(data, ComposedFunction):
        data = data()

    if recursive:
        if isinstance(data, dict):
            for key, value in data.items():
                data[key] = resolve_composed_functions(
                    value,
                    recursive=recursive,
                )
        elif isinstance(data, (list, tuple, set)):
            for index, value in enumerate(data):
                data[index] = resolve_composed_functions(
                    value,
                    recursive=recursive,
                )

    return data
1356538
private function search(&$search, $idx, $selectors, $level, $search_level = 0) {
		if ($search_level >= $level) {
			$rs = $this->seek($search, $selectors, $level - 1);
			if ($rs !== FALSE && $idx !== NULL) {
				if ($idx == count($this->_lFind)) {
					$this->_lFind[] = new self($rs);
					return TRUE;
				} else {
					$this->_lFind[] = new self($rs);
				}
			} elseif ($rs !== FALSE) {
				$this->_lFind[] = new self($rs);
			}
		}
		if (!empty($search->childNodes)) {
			foreach ($search->childNodes as $val) {
				if ($this->search($val, $idx, $selectors, $level, $search_level + 1)) {
					return TRUE;
				}
			}
		}
		return FALSE;
	}
1177928
def find(fn, record):
    
    values_result = fn(record.values())
    keys_result = [k for k, v in record.items() if v == values_result]
    return {keys_result[0]: values_result}
17874
function flattenNodeGenerator(node, parent, index, settings, stack) {
  const { itemsKey, idKey } = settings;

  return function flattenNode(list) {
    node = settings.initNode(node);
    node[idKey] = node[idKey] || settings.generateUniqueId();
    list.push(node);

    if (node[itemsKey]) {
      for (let i = 0, len = node[itemsKey].length; i < len; i++) {
        stack.push(
          flattenNodeGenerator(
            node[itemsKey][i],
            node,
            i,
            settings,
            stack
          )
        );
      }
    }

    if (parent && parent[itemsKey]) {
      // Records children' id
      parent[itemsKey][index] = node[idKey];
      node.parent = parent[idKey];
    }

    return list;
  };
}
454955
def hook_get_results(self, changelist):
        """"""

        # Poor NestedSet guys they've punished themselves once chosen that approach,
        # and now we punish them again with all those DB hits.

        result_list = list(changelist.result_list)

        # Get children stats.
        filter_kwargs = {'%s' % self.left_field: models.F('%s' % self.right_field) - 1}  # Leaf nodes only.
        filter_kwargs.update(self.get_immediate_children_filter(self.parent))

        stats_qs = changelist.result_list.filter(**filter_kwargs).values_list('id')
        leafs = [item[0] for item in stats_qs]

        for result in result_list:

            if result.id in leafs:
                setattr(result, self.CHILD_COUNT_MODEL_ATTR, 0)
            else:
                setattr(result, self.CHILD_COUNT_MODEL_ATTR, '>1')  # Too much pain to get real stats, so that'll suffice.

        if self.pid:
            # Render to upper level link.
            parent = self.parent

            filter_kwargs = {
                '%s__lt' % self.left_field: getattr(parent, self.left_field),
                '%s__gt' % self.right_field: getattr(parent, self.right_field),
            }

            try:
                granparent_id = changelist.model.objects.filter(**filter_kwargs).order_by('-%s' % self.left_field)[0].id
            except IndexError:
                granparent_id = None

            if granparent_id != parent.id:
                parent = changelist.model(pk=granparent_id)

            setattr(parent, self.UPPER_LEVEL_MODEL_ATTR, True)
            result_list = [parent] + result_list

        changelist.result_list = result_list
525218
function nest (str, refs, escape) {
		var res = [], match

		var a = 0
		while (match = re.exec(str)) {
			if (a++ > 10e3) throw Error('Circular references in parenthesis')

			res.push(str.slice(0, match.index))

			res.push(nest(refs[match[1]], refs))

			str = str.slice(match.index + match[0].length)
		}

		res.push(str)

		return res
	}
288486
function nest(t, x, node, func, end) {
        x.stmtStack.push(node);
        var n = func(t, x);
        x.stmtStack.pop();
        end && t.mustMatch(end);
        return n;
    }
2095
function(str, options = {}) {
    var comment, current, data, lines, stack;
    lines = string.lines(str);
    current = data = {};
    stack = [current];
    comment = options.comment || ';';
    lines.forEach(function(line, _, __) {
      var depth, match, parent;
      if (!line || line.match(/^\s*$/)) {
        return;
      }
      // Category
      if (match = line.match(/^\s*(\[+)(.+?)(\]+)\s*$/)) {
        depth = match[1].length;
        // Add a child
        if (depth === stack.length) {
          parent = stack[depth - 1];
          parent[match[2]] = current = {};
          stack.push(current);
        }
        // Invalid child hierarchy
        if (depth > stack.length) {
          throw Error(`Invalid child ${match[2]}`);
        }
        // Move up or at the same level
        if (depth < stack.length) {
          stack.splice(depth, stack.length - depth);
          parent = stack[depth - 1];
          parent[match[2]] = current = {};
          return stack.push(current);
        }
      // comment
      } else if (comment && (match = line.match(RegExp(`^\\s*(${comment}.*)$`)))) {
        return current[match[1]] = null;
      // key value
      } else if (match = line.match(/^\s*(.+?)\s*=\s*(.+)\s*$/)) {
        return current[match[1]] = match[2];
      // else
      } else if (match = line.match(/^\s*(.+?)\s*$/)) {
        return current[match[1]] = null;
      }
    });
    return data;
  }