Recursively walk an object graph applying `fn`/`args` to objects.
13848
def walk(fn, obj, *args, **kwargs):
    """"""
    if type(obj) in [list, tuple]:
        return list(walk(fn, o, *args) for o in obj)
    if type(obj) is dict:
        return dict((walk(fn, k, *args), walk(fn, v, *args)) for k, v in
                    obj.items())
    return fn(obj, *args, **kwargs)
236231
def walk(self, cli):
        
        yield self
        for c in self.children:
            for i in c.walk(cli):
                yield i
157173
def callgraph(func):
    ''' 
    '''
    import pycallgraph
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        pycallgraph.start_trace()
        func(*args, **kwargs)
        pycallgraph.save_dot('callgraph.log')
        pycallgraph.make_dot_graph('callgraph.png')
        #pycallgraph.make_dot_graph('callgraph.jpg', format='jpg', tool='neato')
    return wrapper
189080
function walkNodesBreadthFirstHelper(ast, f) {
  let childAst = [];
  (ast || []).forEach(node => {
    f(node);
    childAst = childAst.concat(getChildren(node));
  });
  if (childAst.length > 0) {
    walkNodesBreadthFirstHelper(childAst, f);
  }
}
467294
function mapValues (obj, fn) {
  return Object.keys(obj).reduce(function (subresult, key) {
    subresult[key] = fn(obj[key], key)
    return subresult
  }, {})
}
985623
function ast_mangle(ast, do_toplevel) {
        var w = ast_walker(), walk = w.walk, scope;

        function get_mangled(name, newMangle) {
                if (!do_toplevel && !scope.parent) return name; // don't mangle toplevel
                return scope.get_mangled(name, newMangle);
        };

        function _lambda(name, args, body) {
                if (name) name = get_mangled(name);
                body = with_scope(body.scope, function(){
                        args = args.map(function(name){ return get_mangled(name) });
                        return body.map(walk);
                });
                return [ this[0], name, args, body ];
        };

        function with_scope(s, cont) {
                var _scope = scope;
                scope = s;
                for (var i in s.names) if (HOP(s.names, i)) {
                        get_mangled(i, true);
                }
                try { var ret = cont(); ret.scope = s; return ret; }
                finally { scope = _scope; };
        };

        function _vardefs(defs) {
                return defs.map(function(d){
                        return [ get_mangled(d[0]), walk(d[1]) ];
                });
        };

        return w.with_walkers({
                "function": _lambda,
                "defun": _lambda,
                "var": function(defs) {
                        return [ "var", _vardefs(defs) ];
                },
                "const": function(defs) {
                        return [ "const", _vardefs(defs) ];
                },
                "name": function(name) {
                        return [ "name", get_mangled(name) ];
                },
                "try": function(t, c, f) {
                        return [ "try",
                                 t.map(walk),
                                 c ? with_scope(c.scope, function(){
                                         return [ get_mangled(c[0]), c[1].map(walk) ];
                                 }) : null,
                                 f != null ? f.map(walk) : null ];
                },
                "toplevel": function(body) {
                        return with_scope(this.scope, function(){
                                return [ "toplevel", body.map(walk) ];
                        });
                },
                "for-in": function(has_var, name, obj, stat) {
                        return [ "for-in", has_var, get_mangled(name), walk(obj), walk(stat) ];
                }
        }, function() {
                return walk(ast_add_scope(ast));
        });
}
738597
def _iter_walk(
        self,
        fs,  # type: FS
        path,  # type: Text
        namespaces=None,  # type: Optional[Collection[Text]]
    ):
        # type: (...) -> Iterator[Tuple[Text, Optional[Info]]]
        """"""
        if self.search == "breadth":
            return self._walk_breadth(fs, path, namespaces=namespaces)
        else:
            return self._walk_depth(fs, path, namespaces=namespaces)
873059
def callgraph(G, stmt_list):
    
    func_list = []
    for stmt in stmt_list:
        try:
            G.add_node(stmt.head.ident.name)
            func_list.append(stmt)
        except:
            pass
    for func in func_list:
        assert isinstance(func,node.function)
        func_name = func.head.ident.name
        #resolve.resolve(func)
        for s in node.postorder(func):
            if (s.__class__ is node.funcall and
                s.func_expr.__class__ is  node.ident):
                #if s.func_expr.name in G.nodes():
                    G.add_edge(func_name,s.func_expr.name)
70905
function(obj, pathSoFar, interesting, ret) {
            for (var f=0; f<obj.length; f++) {
                var thisPath = pathSoFar+obj[f].name+".";
                if (obj[f].type == "string") {
                    ret.push(thisPath);
                }
                else {
                    buildStringPaths(interesting[obj[f].type], thisPath, interesting, ret);
                }
            }
        }
1348856
def dfs_do_func_on_graph(node, func, *args, **kwargs):
    '''
    
    '''
    for _node in node.tree_iterator():
        func(_node, *args, **kwargs)
1152940
function map(tree, method, args) {
    return tree.model[method].apply(tree.model, args);
}
988108
def walk(node):
    
    from collections import deque
    todo = deque([node])
    while todo:
        node = todo.popleft()
        todo.extend(iter_child_nodes(node))
        yield node
1351060
function (callback, ctx) {
            var _walk = function (depth, node, ctx) {
                if (typeof callback === "function")
                    ctx = callback(depth, node, ctx, false);
                var children = node.children();
                for (var i = 0; i < children.length; i++)
                    ctx = _walk(depth + 1, children[i], ctx);
                if (typeof callback === "function")
                    ctx = callback(depth, node, ctx, true);
                return ctx;
            };
            ctx = _walk(0, this, ctx);
            return ctx;
        }
1140913
def _walk_factory(self, dep_predicate):
    """"""
    walk = None
    if dep_predicate:
      walk = self.DepPredicateWalk(dep_predicate)
    else:
      walk = self.NoDepPredicateWalk()
    return walk
1223849
def walk_recursive(f, data):
    
    results = {}
    if isinstance(data, list):
        return [walk_recursive(f, d) for d in data]
    elif isinstance(data, dict):
        results = funcy.walk_keys(f, data)

        for k, v in data.iteritems():
            if isinstance(v, dict):
                results[f(k)] = walk_recursive(f, v)
            elif isinstance(v, list):
                results[f(k)] = [walk_recursive(f, d) for d in v]
    else:
        return f(data)

    return results
467387
function partialAny(fn /* arguments */) {
    var appliedArgs = Array.prototype.slice.call(arguments, 1);
    if ( appliedArgs.length < 1 ) return fn;

    return function () {
      var args = _.deepClone(appliedArgs);
      var partialArgs = _.toArray(arguments);
      for (var i=0; i < args.length; i++) {
        if ( args[i] === _ )
          args[i] = partialArgs.shift();
      }
      return fn.apply(this, args.concat(partialArgs));
    };
  }
804269
def call_fn(fn, arglist, env):
  """"""
  if isinstance(fn, framework.LazyFunction):
    # The following looks complicated, but this is necessary because you can't
    # construct closures over the loop variable directly.
    thunks = [(lambda thunk: lambda: framework.eval(thunk, env))(th) for th in arglist.values]
    return fn(*thunks)

  evaled_args = framework.eval(arglist, env)
  if isinstance(fn, framework.EnvironmentFunction):
    return fn(*evaled_args, env=env)

  return fn(*evaled_args)