Compare commits
2 Commits
2ae5e2e30f
...
d4c08a0f8c
Author | SHA1 | Date | |
---|---|---|---|
d4c08a0f8c | |||
38054a95bb |
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.tebibyte.media/tomo/backend
|
|||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.tebibyte.media/tomo/tomo v0.41.1
|
git.tebibyte.media/tomo/tomo v0.42.0
|
||||||
git.tebibyte.media/tomo/typeset v0.7.1
|
git.tebibyte.media/tomo/typeset v0.7.1
|
||||||
git.tebibyte.media/tomo/xgbkb v1.0.1
|
git.tebibyte.media/tomo/xgbkb v1.0.1
|
||||||
github.com/jezek/xgb v1.1.1
|
github.com/jezek/xgb v1.1.1
|
||||||
|
4
go.sum
4
go.sum
@ -1,6 +1,6 @@
|
|||||||
git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q=
|
git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q=
|
||||||
git.tebibyte.media/tomo/tomo v0.41.1 h1:XdbyF3VjsLj1Zppr70gUaufuh49hU32JQo2ENnw4PcA=
|
git.tebibyte.media/tomo/tomo v0.42.0 h1:yaEUnURYrvBdMdcajrFhpd83TNzyQyBB+jOxvIyQTkU=
|
||||||
git.tebibyte.media/tomo/tomo v0.41.1/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
|
git.tebibyte.media/tomo/tomo v0.42.0/go.mod h1:WrtilgKB1y8O2Yu7X4mYcRiqOlPR8NuUnoA/ynkQWrs=
|
||||||
git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8=
|
git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8=
|
||||||
git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
|
git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
|
||||||
git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE=
|
git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE=
|
||||||
|
@ -91,17 +91,11 @@ 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cycler stores a value and an accompanying io.Closer. When the value is set,
|
// Cycler stores a value and an accompanying io.Closer. When the value is set,
|
||||||
// the closer associated with the previous value is closed.
|
// the closer associated with the previous value is closed.
|
||||||
type Cycler[T any] struct {
|
type Cycler[T any] struct {
|
||||||
@ -130,3 +124,28 @@ func (this *Cycler[T]) Close () error {
|
|||||||
this.closer = nil
|
this.closer = nil
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optional is an optional value.
|
||||||
|
type Optional[T any] struct {
|
||||||
|
value T
|
||||||
|
exists bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the value and true if the value exists. If not, it returns the
|
||||||
|
// last set value and false.
|
||||||
|
func (this *Optional[T]) Value () (T, bool) {
|
||||||
|
return this.value, this.exists
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set sets the value.
|
||||||
|
func (this *Optional[T]) Set (value T) {
|
||||||
|
this.value = value
|
||||||
|
this.exists = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unset unsets the value.
|
||||||
|
func (this *Optional[T]) Unset () {
|
||||||
|
var zero T
|
||||||
|
this.value = zero
|
||||||
|
this.exists = false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user