-
Notifications
You must be signed in to change notification settings - Fork 1
/
return.go
42 lines (33 loc) · 926 Bytes
/
return.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package incr
import (
"fmt"
)
// Return yields a constant incremental for a given value.
//
// Note that it does not implement [IStabilize] and is effectively
// always the same value, and never causes recomputations.
func Return[A any](scope Scope, v A) Incr[A] {
return WithinScope(scope, &returnIncr[A]{
n: NewNode("return"),
v: v,
})
}
var (
_ Incr[string] = (*returnIncr[string])(nil)
_ IShouldBeInvalidated = (*returnIncr[string])(nil)
_ IStale = (*returnIncr[string])(nil)
_ fmt.Stringer = (*returnIncr[string])(nil)
)
type returnIncr[A any] struct {
n *Node
v A
}
func (r returnIncr[A]) Stale() bool {
return r.n.recomputedAt == 0
}
func (vn *returnIncr[T]) ShouldBeInvalidated() bool {
return false
}
func (r returnIncr[A]) Node() *Node { return r.n }
func (r returnIncr[A]) Value() A { return r.v }
func (r returnIncr[A]) String() string { return r.n.String() }