Skip to content

Commit dd09de4

Browse files
committed
more doc strings
1 parent feb1d61 commit dd09de4

7 files changed

+45
-12
lines changed

bind.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
// as a "child" of (b), preventing it from being considered part of the
2626
// overall computation unless it's referenced by another node in the graph.
2727
//
28-
// More information is available at:
28+
// More information is available at in the [Janestreet docs].
2929
//
30-
// https://github.com/janestreet/incremental/blob/master/src/incremental_intf.ml
30+
// [Janestreet Docs]: https://github.com/janestreet/incremental/blob/master/src/incremental_intf.ml
3131
func Bind[A, B any](scope Scope, input Incr[A], fn BindFunc[A, B]) BindIncr[B] {
3232
return BindContext(scope, input, func(_ context.Context, bs Scope, va A) (Incr[B], error) {
3333
return fn(bs, va), nil

bind_if.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import "context"
44

55
// BindIf lets you swap out an entire subgraph of a computation based
66
// on a given boolean incremental predicate.
7+
//
8+
// It is largely "macro" for a Bind that takes an input bool incremental.
79
func BindIf[A any](scope Scope, p Incr[bool], fn func(context.Context, Scope, bool) (Incr[A], error)) BindIncr[A] {
8-
b := BindContext[bool, A](scope, p, fn)
10+
b := BindContext(scope, p, fn)
911
b.Node().SetKind("bind_if")
1012
return b
1113
}

detect_cycle_if_linked.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import "fmt"
55
// DetectCycleIfLinked determines if adding a given input to a given
66
// child would cause a graph cycle.
77
//
8-
// It is a low-level utility function that should be used
9-
// in special cases; the vast majority of direct use cases
10-
// for the incremental library cannot create graph cycles.
8+
// It is a low-level utility function that should be used in special cases; the vast
9+
// majority of situations outside very esoteric [Bind] use cases cannot create cycles.
1110
func DetectCycleIfLinked(child, parent INode) error {
1211
if child == nil || parent == nil {
1312
return nil

expert_graph.go

+30-2
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,50 @@ func ExpertGraph(g *Graph) IExpertGraph {
1616
// Note there are no compatibility guarantees on this interface
1717
// and you should use this interface at your own risk.
1818
type IExpertGraph interface {
19+
// SetID sets the identifier for the [Graph].
1920
SetID(Identifier)
21+
22+
// NumNodes returns the number of nodes the [Graph] is tracking.
2023
NumNodes() uint64
24+
25+
// NumNodesRecomputed returns the number of nodes the [Graph] has
26+
// recomputed in its lifetime.
2127
NumNodesRecomputed() uint64
28+
29+
// NumNodesChanged returns the number of nodes the [Graph] has
30+
// updated the value of in its lifetime.
2231
NumNodesChanged() uint64
32+
33+
// NumObservers returns the current count of observers the [Graph] is tracking.
2334
NumObservers() uint64
35+
36+
// StabilizationNum returns the current stabilization number of the [Graph].
2437
StabilizationNum() uint64
38+
39+
// SetStabilizationNumber sets the current stabilization number, specifically
40+
// in situations where you're restoring graph state.
2541
SetStabilizationNum(uint64)
2642

43+
// RecomputeHeapAdd directly adds a varadic array of nodes to the recompute heap.
2744
RecomputeHeapAdd(...INode)
45+
46+
// RecomputeHeapLen returns the current length of the recompute heap.
2847
RecomputeHeapLen() int
48+
49+
// RecomputeHeapIDs returns the node identifiers that are held in the recompute heap.
50+
//
51+
// This is useful when saving the state of a [Graph] to an external store.
2952
RecomputeHeapIDs() []Identifier
3053

31-
AddChild(INode, INode) error
32-
RemoveParent(INode, INode)
54+
// AddChild associates a child node to a parent.
55+
AddChild(child INode, parent INode) error
56+
// RemoveParent removes the association between a child and a parent.
57+
RemoveParent(child INode, parent INode)
3358

59+
// ObserveNode implements the observe steps usually handled by [Observe] for custom nodes.
3460
ObserveNode(IObserver, INode) error
61+
62+
// UnobserveNode implements the unobserve steps usually handled by observers.
3563
UnobserveNode(IObserver, INode)
3664
}
3765

expert_var.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func ExpertVar[A any](v VarIncr[A]) IExpertVar[A] {
1414
// and you should use this interface at your own risk.
1515
type IExpertVar[A any] interface {
1616
// SetInternalValue allows you to set the underlying value of a var
17-
// _without_ marking it as stale or needing to be recomputed.
17+
// without marking it as stale.
1818
//
1919
// This can be useful when deserializing graphs from some other state.
2020
SetInternalValue(A)

freeze.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import (
66
)
77

88
// Freeze yields an incremental that takes the value of an
9-
// input incremental and doesn't change thereafter.
9+
// input incremental on the first stabilization and
10+
// doesn't change thereafter.
11+
//
12+
// Stabilization propagates through this node even
13+
// after the first stabilization.
1014
func Freeze[A any](scope Scope, i Incr[A]) Incr[A] {
1115
return WithinScope(scope, &freezeIncr[A]{
1216
n: NewNode("freeze"),

return.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
// Return yields a constant incremental for a given value.
88
//
9-
// Note that it does not implement `IStabilize` and is effectively
10-
// always the same value (and treated as such).
9+
// Note that it does not implement [IStabilize] and is effectively
10+
// always the same value, and never causes recomputations.
1111
func Return[A any](scope Scope, v A) Incr[A] {
1212
return WithinScope(scope, &returnIncr[A]{
1313
n: NewNode("return"),

0 commit comments

Comments
 (0)