Yog.FSharp
Getting Started Examples API Reference GitHub

Live Module

Live graph builder for incremental graph construction.

The Live builder queues changes (additions and removals) that can be applied to a graph in batches via sync. This is useful for: - Building graphs incrementally from streaming data - Delaying expensive graph operations until necessary - Tracking pending changes before commit

Comparison with LabeledBuilder

Aspect

LiveBuilder

LabeledBuilder

Changes

Queued/batched

Immediate

Sync required

Yes

No

Remove operations

Yes

No

Use case

Streaming/mutable

Static construction

Example

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
open Yog.Builder

// Queue multiple changes
let builder, graph =
    Live.create<string, int>()
    |> Live.addEdge "Alice" "Bob" 5
    |> Live.addEdge "Bob" "Charlie" 3
    |> Live.removeEdge "Alice" "Bob"
    |> Live.sync (Yog.Model.empty Directed)

// graph now contains only Bob -> Charlie

Transition Types

  • AddNode: Create a new node with given ID and label
  • AddEdge: Create an edge between node IDs
  • RemoveEdge: Remove an edge between node IDs
  • RemoveNode: Remove a node and all its edges
namespace Yog
namespace Yog.Builder
val builder: obj
val graph: obj
module Live from Yog.Builder
<summary> Live graph builder for incremental graph construction. The Live builder queues changes (additions and removals) that can be applied to a graph in batches via `sync`. This is useful for: - Building graphs incrementally from streaming data - Delaying expensive graph operations until necessary - Tracking pending changes before commit ## Comparison with LabeledBuilder | Aspect | LiveBuilder | LabeledBuilder | |--------|-------------|----------------| | Changes | Queued/batched | Immediate | | Sync required | Yes | No | | Remove operations | Yes | No | | Use case | Streaming/mutable | Static construction | ## Example ```fsharp open Yog.Builder // Queue multiple changes let builder, graph = Live.create&lt;string, int&gt;() |&gt; Live.addEdge "Alice" "Bob" 5 |&gt; Live.addEdge "Bob" "Charlie" 3 |&gt; Live.removeEdge "Alice" "Bob" |&gt; Live.sync (Yog.Model.empty Directed) // graph now contains only Bob -&gt; Charlie ``` ## Transition Types - `AddNode`: Create a new node with given ID and label - `AddEdge`: Create an edge between node IDs - `RemoveEdge`: Remove an edge between node IDs - `RemoveNode`: Remove a node and all its edges </summary>
val create: unit -> LiveBuilder<'n,'e> (requires comparison)
<summary> Creates a new empty live builder. ## Example ```fsharp let builder = Live.create&lt;string, int&gt;() ``` </summary>
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
val addEdge: fromLabel: 'a -> toLabel: 'a -> weight: 'b -> builder: LiveBuilder<'a,'b> -> LiveBuilder<'a,'b> (requires comparison)
<summary> Queues an edge addition between two labels. Creates nodes automatically if they don't exist. ## Example ```fsharp let builder = Live.create&lt;string, int&gt;() |&gt; Live.addEdge "A" "B" 10 ``` </summary>
val removeEdge: fromLabel: 'a -> toLabel: 'a -> builder: LiveBuilder<'a,'b> -> LiveBuilder<'a,'b> (requires comparison)
<summary> Queues an edge removal. Silently ignored if either label doesn't exist. </summary>
val sync: builder: LiveBuilder<'n,'e> -> graph: Yog.Model.Graph<'n,'e> -> LiveBuilder<'n,'e> * Yog.Model.Graph<'n,'e> (requires comparison)
<summary> Synchronizes pending changes to the provided graph. Returns the updated builder (with cleared queue) and the updated graph. ## Parameters - `builder`: The LiveBuilder with pending changes - `graph`: The target graph to apply changes to ## Returns Tuple of (builder with cleared pending, updated graph) ## Example ```fsharp let builder, updatedGraph = myBuilder |&gt; Live.sync existingGraph ``` </summary>
module Model from Yog
<summary> Core graph data structures and basic operations for the yog library. This module defines the fundamental `Graph` type and provides all basic operations for creating and manipulating graphs. The graph uses an adjacency list representation with dual indexing (both outgoing and incoming edges) for efficient traversal in both directions. </summary>
val empty: graphType: Yog.Model.GraphType -> Yog.Model.Graph<'n,'e>
<summary> Creates a new empty graph of the specified type. ## Example ```fsharp let graph = Model.empty Directed ``` </summary>

Functions and values

Function or value Description

addEdge fromLabel toLabel weight builder

Full Usage: addEdge fromLabel toLabel weight builder

Parameters:
    fromLabel : 'a
    toLabel : 'a
    weight : 'b
    builder : LiveBuilder<'a, 'b>

Returns: LiveBuilder<'a, 'b>

Queues an edge addition between two labels.

Creates nodes automatically if they don't exist.

Example

1: 
2: 
3: 
let builder =
    Live.create<string, int>()
    |> Live.addEdge "A" "B" 10
val builder: obj
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int

fromLabel : 'a
toLabel : 'a
weight : 'b
builder : LiveBuilder<'a, 'b>
Returns: LiveBuilder<'a, 'b>

addSimpleEdge fromLabel toLabel builder

Full Usage: addSimpleEdge fromLabel toLabel builder

Parameters:
    fromLabel : 'a
    toLabel : 'a
    builder : LiveBuilder<'a, int>

Returns: LiveBuilder<'a, int>

Queues a simple edge with weight 1.

fromLabel : 'a
toLabel : 'a
builder : LiveBuilder<'a, int>
Returns: LiveBuilder<'a, int>

allLabels builder

Full Usage: allLabels builder

Parameters:
Returns: 'a list

Returns all registered labels.

builder : LiveBuilder<'a, 'b>
Returns: 'a list

create ()

Full Usage: create ()

Parameters:
    () : unit

Returns: LiveBuilder<'n, 'e>

Creates a new empty live builder.

Example

1: 
let builder = Live.create<string, int>()
val builder: obj
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int

() : unit
Returns: LiveBuilder<'n, 'e>

fromLabeled labeled

Full Usage: fromLabeled labeled

Parameters:
Returns: LiveBuilder<'n, 'e>

Migrate from a static LabeledBuilder to a LiveBuilder.

Preserves all labels and IDs but starts with an empty pending queue.

Example

1: 
2: 
let labeled = Labeled.directed<string, int>() |> Labeled.addEdge "A" "B" 1
let live = Live.fromLabeled labeled
val labeled: obj
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
val live: obj

labeled : LabeledBuilder<'n, 'e>
Returns: LiveBuilder<'n, 'e>

getId label builder

Full Usage: getId label builder

Parameters:
Returns: NodeId option

Some id if the label is registered, None otherwise.


Looks up the NodeId for a label.

label : 'a
builder : LiveBuilder<'a, 'b>
Returns: NodeId option

Some id if the label is registered, None otherwise.

pendingCount builder

Full Usage: pendingCount builder

Parameters:
Returns: int

Total count of pending changes.

builder : LiveBuilder<'a, 'b>
Returns: int

purgePending builder

Full Usage: purgePending builder

Parameters:
Returns: LiveBuilder<'a, 'b>

Discards all pending changes without applying them.

Example

1: 
let cleanBuilder = Live.purgePending builder
val cleanBuilder: obj

builder : LiveBuilder<'a, 'b>
Returns: LiveBuilder<'a, 'b>

removeEdge fromLabel toLabel builder

Full Usage: removeEdge fromLabel toLabel builder

Parameters:
    fromLabel : 'a
    toLabel : 'a
    builder : LiveBuilder<'a, 'b>

Returns: LiveBuilder<'a, 'b>

Queues an edge removal.

Silently ignored if either label doesn't exist.

fromLabel : 'a
toLabel : 'a
builder : LiveBuilder<'a, 'b>
Returns: LiveBuilder<'a, 'b>

removeNode label builder

Full Usage: removeNode label builder

Parameters:
Returns: LiveBuilder<'a, 'b>

Queues a node removal and removes it from the label registry.

Silently ignored if the label doesn't exist.

label : 'a
builder : LiveBuilder<'a, 'b>
Returns: LiveBuilder<'a, 'b>

sync builder graph

Full Usage: sync builder graph

Parameters:
Returns: LiveBuilder<'n, 'e> * Graph<'n, 'e>

Tuple of (builder with cleared pending, updated graph)


Synchronizes pending changes to the provided graph.

Returns the updated builder (with cleared queue) and the updated graph.

Parameters

  • builder: The LiveBuilder with pending changes
  • graph: The target graph to apply changes to

Example

1: 
2: 
3: 
let builder, updatedGraph =
    myBuilder
    |> Live.sync existingGraph
val builder: obj
val updatedGraph: obj

builder : LiveBuilder<'n, 'e>
graph : Graph<'n, 'e>
Returns: LiveBuilder<'n, 'e> * Graph<'n, 'e>

Tuple of (builder with cleared pending, updated graph)