Skip to content

Commit

Permalink
fix: fix copylocks warning in Optional struct methods
Browse files Browse the repository at this point in the history
  • Loading branch information
duke-git committed Feb 19, 2024
1 parent 9f7b416 commit 9fd0603
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions datastructure/optional/optional.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import (
// Optional is a type that may or may not contain a non-nil value.
type Optional[T any] struct {
value *T
mu sync.RWMutex
mu *sync.RWMutex
}

// Empty returns an empty Optional instance.
func Empty[T any]() Optional[T] {
return Optional[T]{}
return Optional[T]{mu: &sync.RWMutex{}}
}

// Of returns an Optional with a non-nil value.
func Of[T any](value T) Optional[T] {
return Optional[T]{value: &value}
return Optional[T]{value: &value, mu: &sync.RWMutex{}}
}

// OfNullable returns an Optional for a given value, which may be nil.
func OfNullable[T any](value *T) Optional[T] {
if value == nil {
return Empty[T]()
}
return Optional[T]{value: value}
return Optional[T]{value: value, mu: &sync.RWMutex{}}
}

// IsPresent checks if there is a value present.
Expand Down

0 comments on commit 9fd0603

Please sign in to comment.