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)
| 29 | // Before creates a function that invokes func once it's called less than n times. |
| 30 | // Play: https://go.dev/play/p/0HqUDIFZ3IL |
| 31 | func 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 |
| 48 | type CurryFn[T any] func(...T) T |
searching dependent graphs…