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

Function After

function/function.go:16–27  ·  view source on GitHub ↗

After creates a function that invokes func once it's called n or more times. Play: https://go.dev/play/p/8mQhkFmsgqs

(n int, fn any)

Source from the content-addressed store, hash-verified

14// After creates a function that invokes func once it's called n or more times.
15// Play: https://go.dev/play/p/8mQhkFmsgqs
16func After(n int, fn any) func(args ...any) []reflect.Value {
17 // Catch programming error while constructing the closure
18 mustBeFunction(fn)
19
20 return func(args ...any) []reflect.Value {
21 n--
22 if n < 1 {
23 return unsafeInvokeFunc(fn, args...)
24 }
25 return nil
26 }
27}
28
29// Before creates a function that invokes func once it's called less than n times.
30// Play: https://go.dev/play/p/0HqUDIFZ3IL

Callers 2

ExampleAfterFunction · 0.70
TestAfterFunction · 0.70

Calls 2

mustBeFunctionFunction · 0.85
unsafeInvokeFuncFunction · 0.85

Tested by 2

ExampleAfterFunction · 0.56
TestAfterFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…