Execute multiple functions in one function

Hello ■■■■,
I have to implement a function of the following form:

func appendFunc (dst func ([] int), src ... func ([] int)) func ([] int)

This function takes as an argument some function for processing dst slices and an unlimited number of other processing functions that need to be “attached” to the dst function and return a new function

I stuck in this code

func appendFunc(src ...func([]int)) func() {
	numsSlice := []int{9, 0, 1, 8, 7, 2, 3, 4, 6, 5}
	return func() {
		fmt.Println("this wont be printed")
		for _, i := range src {
			i(numsSlice)
		}
	}
}
func main() {
	appendFunc(SortSlice, IncrementOdd, PrintSlice, ReverseSlice)
}

wae it shows nothing?

How are you calling the function?

Sorry, I didn’t actually ask the right question here. I meant that your appendFunc itself returns a function, but you’re not calling that returned function.

3 Likes

Thank you! now it works!
The solution is:
appendFunc(SortSlice, IncrementOdd, PrintSlice, ReverseSlice)()