github.com/rudderlabs/rudder-go-kit@v0.30.0/ro/ro.go (about)

     1  package ro
     2  
     3  // Memoize stores the execution result of the provided function in-memory during the first call and uses it as a return value for subsequent calls
     4  func Memoize[R any](f func() R) func() R {
     5  	var result R
     6  	var called bool
     7  	return func() R {
     8  		if called {
     9  			return result
    10  		}
    11  		result = f()
    12  		called = true
    13  		return result
    14  	}
    15  }