package main

import (
	"errors"
	"fmt"
	"time"
)

// go中 函数可以拥有多个返回值，

func BothAdd(a, b int, action func(nun int) int) (int, int, error) {
	if a == 0 || b == 0 {
		return 0, 0, errors.New("the num must not be 0")
	}
	return action(a), action(b), nil
}

func Concat2(a string, bOptional ...int) string {
	b := 5
	if len(bOptional) > 0 {
		b = bOptional[0]
	}

	return fmt.Sprintf("%s%d", a, b)
}
func swap(a, b int) (int, int) {
	a, b = b, a
	return a, b

}

func Sum[T int | float64](a, b T) T {
	return a + b
}

func APprint(s chan string) {
	for i := 0; i < 10; i++ {
		fmt.Println(<-s)
		time.Sleep(time.Second)
	}
}
func main() {
	str := make(chan string, 5)
	go APprint(str)
	go APprint(str)
	for true {
		str <- "aaa"
		str <- "\\CCC"
	}
	time.Sleep(time.Second * 20)
	//fmt.Println(Sum[int](1, 2))
	//fmt.Println(Sum(1.23, 2.3))

}
