MCPcopy
hub / github.com/duke-git/lancet / Before

Function Before

function/function.go:31–45  ·  view source on GitHub ↗

Before creates a function that invokes func once it's called less than n times. Play: https://go.dev/play/p/0HqUDIFZ3IL

(n int, fn any)

Source from the content-addressed store, hash-verified

29// Before creates a function that invokes func once it's called less than n times.
30// Play: https://go.dev/play/p/0HqUDIFZ3IL
31func Before(n int, fn any) func(args ...any) []reflect.Value {
32 // Catch programming error while constructing the closure
33 mustBeFunction(fn)
34 var result []reflect.Value
35 return func(args ...any) []reflect.Value {
36 if n > 0 {
37 result = unsafeInvokeFunc(fn, args...)
38 }
39 if n <= 0 {
40 fn = nil
41 }
42 n--
43 return result
44 }
45}
46
47// CurryFn is for make curry function
48type CurryFn[T any] func(...T) T

Callers 2

ExampleBeforeFunction · 0.70
TestBeforeFunction · 0.70

Calls 2

mustBeFunctionFunction · 0.85
unsafeInvokeFuncFunction · 0.85

Tested by 2

ExampleBeforeFunction · 0.56
TestBeforeFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…