Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1kbgz Tributary Lazy To Streaming Bridge

From Leeroopedia
Knowledge Sources
Domains Streaming, Lazy_Evaluation
Last Updated 2026-10-14 00:00 GMT

Overview

Concrete bridge function for converting lazy graph nodes into streaming source nodes, provided by the Tributary library.

Description

The LazyToStreaming function bridges the lazy and streaming subsystems. It takes a lazy Node (LazyNode) and wraps it in a streaming Func node. On each streaming tick, the Func calls the lazy node's __call__ method, which re-evaluates if dirty or returns the cached value.

The companion _gen_node function is a polymorphic auto-wrapper: it converts any input into a streaming node — lazy nodes become LazyToStreaming conversions, callables become Func sources, and scalars become Const sources.

Usage

Import LazyToStreaming when you need to integrate a lazy computation graph into a streaming pipeline. This is useful when you want to combine on-demand lazy evaluation with real-time streaming data.

Code Reference

Source Location

  • Repository: Tributary
  • File: tributary/utils.py

Signature

def LazyToStreaming(lazy_node):
    """Convert a lazy Node into a streaming Func source.

    Args:
        lazy_node: a LazyNode (lazy Node) instance
    Returns:
        A streaming Func node that calls lazy_node() on each tick
    """

def _gen_node(n):
    """Auto-wrap any value into a streaming node.

    - StreamingNode: returned as-is
    - LazyNode: converted via LazyToStreaming
    - callable: wrapped in Func
    - scalar/other: wrapped in Const
    """

Import

from tributary import LazyToStreaming
# or:
from tributary.utils import LazyToStreaming, _gen_node

I/O Contract

Inputs

Name Type Required Description
lazy_node LazyNode Yes A lazy Node instance to convert

Outputs

Name Type Description
return Func (streaming Node) A streaming Func node that calls lazy_node() on each tick

Usage Examples

Basic Lazy to Streaming

import tributary as t
import tributary.streaming as ts

# Build a lazy graph
x = t.LazyNode(value=5, name="x")
y = t.LazyNode(value=3, name="y")
z = x + y  # lazy: z = 8

# Bridge into streaming
stream_source = LazyToStreaming(z)

# Use in a streaming pipeline
out = ts.Print(stream_source)
ts.run(out)  # Output: 8

# Change lazy input and stream again
x.setValue(10)
ts.run(out)  # Output: 13

Mixing Lazy and Streaming

import tributary as t
import tributary.streaming as ts

# Lazy computation
lazy_x = t.LazyNode(value=10, name="x")
lazy_squared = lazy_x * lazy_x  # 100

# Streaming source
stream_counter = ts.Curve(value=[1, 2, 3, 4, 5])

# Convert lazy to streaming and merge
lazy_stream = LazyToStreaming(lazy_squared)
merged = ts.Merge(stream_counter, lazy_stream)

out = ts.Print(merged)
ts.run(out)
# Output: (1, 100), (2, 100), (3, 100), (4, 100), (5, 100)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment