github.com/haraldrudell/parl@v0.4.176/pslices/stringify-slice.go (about)

     1  /*
     2  © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package pslices
     7  
     8  import "fmt"
     9  
    10  // StringifySlice returns the string representation of any slice
    11  func StringifySlice[E any](slic []E) (sList []string) {
    12  	length := len(slic)
    13  	if length == 0 {
    14  		return
    15  	}
    16  	sList = make([]string, length)
    17  	for i, e := range slic {
    18  		sList[i] = fmt.Sprint(e) // uses String or %v
    19  	}
    20  	return
    21  }