Compare commits
No commits in common. "fc1af9f4a12a972749f0fc82abdacb5c37ee0663" and "e94de08d4f85e9c9c61ad7560b3c7c530426e560" have entirely different histories.
fc1af9f4a1
...
e94de08d4f
@ -20,7 +20,6 @@ func NewMemo[T any] (update func () T) Memo[T] {
|
|||||||
func (this *Memo[T]) Value () T {
|
func (this *Memo[T]) Value () T {
|
||||||
if !this.valid {
|
if !this.valid {
|
||||||
this.cache = this.update()
|
this.cache = this.update()
|
||||||
this.valid = true
|
|
||||||
}
|
}
|
||||||
return this.cache
|
return this.cache
|
||||||
}
|
}
|
||||||
@ -28,8 +27,13 @@ func (this *Memo[T]) Value () T {
|
|||||||
// Invalidate marks the Memo's value as invalid, which will cause it to be
|
// Invalidate marks the Memo's value as invalid, which will cause it to be
|
||||||
// updated the next time Value is called.
|
// updated the next time Value is called.
|
||||||
func (this *Memo[T]) Invalidate () {
|
func (this *Memo[T]) Invalidate () {
|
||||||
var zero T
|
|
||||||
this.cache = zero
|
|
||||||
this.valid = false
|
this.valid = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvalidateTo invalidates the Memo and sets its value. The new value will be
|
||||||
|
// entirely inaccessible. This is only intended to be used for setting a
|
||||||
|
// reference to nil
|
||||||
|
func (this *Memo[T]) InvalidateTo (value T) {
|
||||||
|
this.Invalidate()
|
||||||
|
this.cache = value
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user