Skip to content

Commit 57d854e

Browse files
committed
updates
1 parent 2fe31f6 commit 57d854e

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

bind.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func Bind[A, B any](scope Scope, input Incr[A], fn func(Scope, A) Incr[B]) BindI
3636

3737
// BindContext is like Bind but allows the bind delegate to take a context and return an error.
3838
//
39-
// If an error returned, the bind is aborted and the error listener(s) will fire for the node.
39+
// If an error returned, the bind is aborted, the error listener(s) will fire for the node, and the
40+
// computation will stop.
4041
func BindContext[A, B any](scope Scope, input Incr[A], fn func(context.Context, Scope, A) (Incr[B], error)) BindIncr[B] {
4142
o := &bindIncr[A, B]{
4243
n: NewNode("bind"),
@@ -50,9 +51,11 @@ func BindContext[A, B any](scope Scope, input Incr[A], fn func(context.Context,
5051
return WithinScope(scope, o)
5152
}
5253

53-
// BindIncr is a node that implements Bind, which
54-
// dynamically swaps out entire subgraphs
55-
// based on input incrementals.
54+
// BindIncr is a node that implements Bind, which can dynamically swap out
55+
// subgraphs based on input incrementals changing.
56+
//
57+
// BindIncr gives the graph dynamism, but as a result is somewhat expensive to
58+
// compute and should be used tactically.
5659
type BindIncr[A any] interface {
5760
Incr[A]
5861
IStabilize

bind2.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ func Bind2[A, B, C any](scope Scope, a Incr[A], b Incr[B], fn func(Scope, A, B)
1313
// Bind2Context lets you swap out an entire subgraph of a computation based
1414
// on a given set of 2 input incrementals, taking a context and as well returning an error.
1515
func Bind2Context[A, B, C any](scope Scope, a Incr[A], b Incr[B], fn func(context.Context, Scope, A, B) (Incr[C], error)) BindIncr[C] {
16-
m := Map2(scope, a, b, func(av A, bv B) Tuple2[A, B] {
17-
return Tuple2[A, B]{av, bv}
16+
m := Map2(scope, a, b, func(av A, bv B) tuple2[A, B] {
17+
return tuple2[A, B]{av, bv}
1818
})
19-
bind := BindContext[Tuple2[A, B], C](scope, m, func(ctx context.Context, bs Scope, tv Tuple2[A, B]) (Incr[C], error) {
19+
bind := BindContext[tuple2[A, B], C](scope, m, func(ctx context.Context, bs Scope, tv tuple2[A, B]) (Incr[C], error) {
2020
return fn(ctx, scope, tv.A, tv.B)
2121
})
2222
bind.Node().SetKind("bind2")
2323
return bind
2424
}
2525

26-
// Tuple2 is a tuple of values.
27-
type Tuple2[A, B any] struct {
26+
// tuple2 is a tuple of values.
27+
type tuple2[A, B any] struct {
2828
A A
2929
B B
3030
}

bind3.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ func Bind3[A, B, C, D any](scope Scope, a Incr[A], b Incr[B], c Incr[C], fn func
1313
// Bind3Context lets you swap out an entire subgraph of a computation based
1414
// on a given set of 3 input incrementals, taking a context and as well returning an error.
1515
func Bind3Context[A, B, C, D any](scope Scope, a Incr[A], b Incr[B], c Incr[C], fn func(context.Context, Scope, A, B, C) (Incr[D], error)) BindIncr[D] {
16-
m := Map3(scope, a, b, c, func(av A, bv B, cv C) Tuple3[A, B, C] {
17-
return Tuple3[A, B, C]{av, bv, cv}
16+
m := Map3(scope, a, b, c, func(av A, bv B, cv C) tuple3[A, B, C] {
17+
return tuple3[A, B, C]{av, bv, cv}
1818
})
19-
bind := BindContext[Tuple3[A, B, C], D](scope, m, func(ctx context.Context, bs Scope, tv Tuple3[A, B, C]) (Incr[D], error) {
19+
bind := BindContext[tuple3[A, B, C], D](scope, m, func(ctx context.Context, bs Scope, tv tuple3[A, B, C]) (Incr[D], error) {
2020
return fn(ctx, scope, tv.A, tv.B, tv.C)
2121
})
2222
bind.Node().SetKind("bind3")
2323
return bind
2424
}
2525

26-
// Tuple3 is a tuple of values.
27-
type Tuple3[A, B, C any] struct {
26+
// tuple3 is a tuple of values.
27+
type tuple3[A, B, C any] struct {
2828
A A
2929
B B
3030
C C

bind4.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ func Bind4[A, B, C, D, E any](scope Scope, a Incr[A], b Incr[B], c Incr[C], d In
1313
// Bind4Context lets you swap out an entire subgraph of a computation based
1414
// on a given set of 4 input incrementals, taking a context and as well returning an error.
1515
func Bind4Context[A, B, C, D, E any](scope Scope, a Incr[A], b Incr[B], c Incr[C], d Incr[D], fn func(context.Context, Scope, A, B, C, D) (Incr[E], error)) BindIncr[E] {
16-
m := Map4(scope, a, b, c, d, func(av A, bv B, cv C, dv D) Tuple4[A, B, C, D] {
17-
return Tuple4[A, B, C, D]{av, bv, cv, dv}
16+
m := Map4(scope, a, b, c, d, func(av A, bv B, cv C, dv D) tuple4[A, B, C, D] {
17+
return tuple4[A, B, C, D]{av, bv, cv, dv}
1818
})
19-
bind := BindContext[Tuple4[A, B, C, D], E](scope, m, func(ctx context.Context, bs Scope, tv Tuple4[A, B, C, D]) (Incr[E], error) {
19+
bind := BindContext[tuple4[A, B, C, D], E](scope, m, func(ctx context.Context, bs Scope, tv tuple4[A, B, C, D]) (Incr[E], error) {
2020
return fn(ctx, scope, tv.A, tv.B, tv.C, tv.D)
2121
})
2222
bind.Node().SetKind("bind4")
2323
return bind
2424
}
2525

26-
// Tuple4 is a tuple of values.
27-
type Tuple4[A, B, C, D any] struct {
26+
// tuple4 is a tuple of values.
27+
type tuple4[A, B, C, D any] struct {
2828
A A
2929
B B
3030
C C

graph.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import (
77
"time"
88
)
99

10-
// New returns a new graph state, which is the type that
11-
// represents the shared state of a computation graph.
10+
// New returns a new graph state, which is the type that represents the
11+
// shared state of a computation graph.
12+
//
13+
// You can pass configuration options as `GraphOption` to customize settings
14+
// within the graph, such as what the maximum "height" a node can be.
1215
//
1316
// This is the entrypoint for all stabilization and computation
14-
// operations.
17+
// operations, and generally the Graph will be passed to node constructors.
1518
//
16-
// Nodes you initialize the graph with will be "observed" before
17-
// the graph is returned, saving that step later.
19+
// Nodes you initialize the graph with will need to be be observed by
20+
// an `Observer` before you can stabilize them.
1821
func New(opts ...GraphOption) *Graph {
1922
options := GraphOptions{
2023
MaxHeight: DefaultMaxHeight,
@@ -61,12 +64,12 @@ var (
6164
_ Scope = (*Graph)(nil)
6265
)
6366

64-
// Graph is the state that is shared across nodes.
67+
// Graph is the state that is shared across nodes in a computation graph.
6568
//
66-
// You should instantiate this type with `New()`.
69+
// You should instantiate this type with the `New()` function.
6770
//
68-
// It is important to note that most operations on the graph are _not_ concurrent
69-
// safe and you should use your own mutex to synchronize access to internal state.
71+
// The graph holds information such as, how many stabilizations have happened,
72+
// what node are currently observed, and what nodes need to be recomputed.
7073
type Graph struct {
7174
// id is a unique identifier for the graph
7275
id Identifier

map_n.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func MapNContext[A, B any](scope Scope, fn MapNContextFunc[A, B], inputs ...Incr
2727
return WithinScope(scope, o)
2828
}
2929

30-
// MapNFunc is the function that the ApplyN incremental applies.
30+
// MapNFunc is the function that the MapN incremental applies.
3131
type MapNFunc[A, B any] func(...A) B
3232

33-
// MapNContextFunc is the function that the ApplyN incremental applies.
33+
// MapNContextFunc is the function that the MapNContext incremental applies.
3434
type MapNContextFunc[A, B any] func(context.Context, ...A) (B, error)
3535

3636
// MapNIncr is a type of incremental that can add inputs over time.

0 commit comments

Comments
 (0)