Query a collection of Bokeh models and yield any that match the
    a selector.

    Args:
        obj (Model) : object to test
        selector (JSON-like) : query selector
        context (dict) : kwargs to supply callable query attributes

    Yields:
        Model : objects that match the query

    Queries are specified as selectors similar to MongoDB style query
    selectors, as described for :func:`~bokeh.core.query.match`.

    Examples:

        .. code-block:: python

            # find all objects with type Grid
            find(p.references(), {'type': Grid})

            # find all objects with type Grid or Axis
            find(p.references(), {OR: [
                {'type': Grid}, {'type': Axis}
            ]})

            # same query, using IN operator
            find(p.references(), {'type': {IN: [Grid, Axis]}})

            # find all plot objects on the 'left' layout of the Plot
            # here layout is a method that takes a plot as context
            find(p.references(), {'layout': 'left'}, {'plot': p})

def find(objs, selector, context=None):
    ''' Query a collection of Bokeh models and yield any that match the
    a selector.

    Args:
        obj (Model) : object to test
        selector (JSON-like) : query selector
        context (dict) : kwargs to supply callable query attributes

    Yields:
        Model : objects that match the query

    Queries are specified as selectors similar to MongoDB style query
    selectors, as described for :func:`~bokeh.core.query.match`.

    Examples:

        .. code-block:: python

            # find all objects with type Grid
            find(p.references(), {'type': Grid})

            # find all objects with type Grid or Axis
            find(p.references(), {OR: [
                {'type': Grid}, {'type': Axis}
            ]})

            # same query, using IN operator
            find(p.references(), {'type': {IN: [Grid, Axis]}})

            # find all plot objects on the 'left' layout of the Plot
            # here layout is a method that takes a plot as context
            find(p.references(), {'layout': 'left'}, {'plot': p})

    '''
    return (obj for obj in objs if match(obj, selector, context))