🔍 Code Extractor

function get_nested_streams

Maturity: 43

Recursively traverses a DynamicMap object to extract and return all unique Stream objects found within it and its nested DynamicMaps.

File:
/tf/active/vicechatdev/patches/spaces.py
Lines:
648 - 657
Complexity:
simple

Purpose

This function is used to discover all Stream objects associated with a DynamicMap hierarchy. It's particularly useful in visualization frameworks (like HoloViews) where DynamicMaps can contain nested structures, and you need to collect all streams for event handling, parameter tracking, or interactive visualization setup. The function ensures no duplicate streams are returned by using a set internally.

Source Code

def get_nested_streams(dmap):
    """Recurses supplied DynamicMap to find all streams

    Args:
        dmap: DynamicMap to recurse to look for streams

    Returns:
        List of streams that were found
    """
    return list({s for dmap in get_nested_dmaps(dmap) for s in dmap.streams})

Parameters

Name Type Default Kind
dmap - - positional_or_keyword

Parameter Details

dmap: A DynamicMap object to be recursively searched. DynamicMap is typically a HoloViews data structure that can contain nested DynamicMaps. The function will traverse through all nested levels to find streams. Expected to have a 'streams' attribute and be compatible with the get_nested_dmaps function.

Return Value

Returns a list of unique Stream objects found within the provided DynamicMap and all its nested DynamicMaps. The list contains no duplicates due to the internal set conversion. If no streams are found, returns an empty list. Stream objects are typically used for interactive parameter updates and event handling in visualization contexts.

Dependencies

  • param
  • numpy

Required Imports

from streams import Stream

Usage Example

# Assuming HoloViews context with DynamicMap and Stream objects
import holoviews as hv
from holoviews.streams import Stream, PointerXY

# Create a stream
pointer = PointerXY(x=0, y=0)

# Create a DynamicMap with the stream
def plot_function(x, y):
    return hv.Points([(x, y)])

dmap = hv.DynamicMap(plot_function, streams=[pointer])

# Get all streams from the DynamicMap
streams = get_nested_streams(dmap)
print(f"Found {len(streams)} stream(s)")
print(streams)  # [PointerXY(x=0, y=0)]

Best Practices

  • Ensure the input is a valid DynamicMap object with a 'streams' attribute to avoid AttributeError
  • The function depends on get_nested_dmaps being available in scope - ensure this dependency is met
  • The returned list contains unique streams only, so multiple references to the same stream in different nested DynamicMaps will appear only once
  • This function is read-only and does not modify the input DynamicMap or its streams
  • Consider caching results if calling repeatedly on the same DynamicMap structure for performance optimization

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_nested_dmaps 79.6% similar

    Recursively traverses a DynamicMap object to find and collect all nested DynamicMap instances that serve as inputs to the callback function.

    From: /tf/active/vicechatdev/patches/spaces.py
  • function dimensioned_streams 71.2% similar

    Filters and returns streams from a DynamicMap that have parameters matching the DynamicMap's key dimensions.

    From: /tf/active/vicechatdev/patches/util.py
  • function dynamicmap_memoization 56.7% similar

    A context manager that temporarily controls memoization behavior of a callable object based on the state of associated streams, disabling memoization when transient streams are triggering.

    From: /tf/active/vicechatdev/patches/spaces.py
  • class DynamicMap 56.4% similar

    A DynamicMap is a type of HoloMap where the elements are dynamically generated by a callable. The callable is invoked with values associated with the key dimensions or with values supplied by stream parameters.

    From: /tf/active/vicechatdev/patches/spaces.py
  • function unbound_dimensions 51.7% similar

    Filters a list of dimensions (kdims) to return only those that have not been associated with any of the provided streams.

    From: /tf/active/vicechatdev/patches/util.py
← Back to Browse