MCPcopy Index your code
hub / github.com/riverqueue/river / ValOrDefaultFunc

Function ValOrDefaultFunc

rivershared/util/ptrutil/ptr_util.go:19–24  ·  view source on GitHub ↗

ValOrDefaultFunc returns the value of the given pointer as long as it's non-nil, or invokes the given function to produce a default value otherwise.

(ptr *T, defaultFunc func() T)

Source from the content-addressed store, hash-verified

17// ValOrDefaultFunc returns the value of the given pointer as long as it's
18// non-nil, or invokes the given function to produce a default value otherwise.
19func ValOrDefaultFunc[T any](ptr *T, defaultFunc func() T) T {
20 if ptr != nil {
21 return *ptr
22 }
23 return defaultFunc()
24}

Callers 4

MigrationFunction · 0.92
QueueFunction · 0.92
buildUniqueKeyStringFunction · 0.92
TestValOrDefaultFuncFunction · 0.70

Calls

no outgoing calls

Tested by 1

TestValOrDefaultFuncFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…