github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/isc/jointo.go (about)

     1  package isc
     2  
     3  func ListJoinToStringFull[T any](list []T, sep string, prefix string, postfix string, f func(T) string) string {
     4  	buffer := prefix
     5  	var count = 0
     6  	for _, e := range list {
     7  		count++
     8  		if count > 1 {
     9  			buffer += sep
    10  		}
    11  		buffer += f(e)
    12  	}
    13  	buffer += postfix
    14  	return buffer
    15  }
    16  
    17  func ListJoinToString[T any](list []T, f func(T) string) string {
    18  	return ListJoinToStringFull(list, ",", "", "", f)
    19  }
    20  
    21  func MapJoinToStringFull[K comparable, V any](m map[K]V, sep string, prefix string, postfix string, f func(K, V) string) string {
    22  	buffer := prefix
    23  	var count = 0
    24  	for k, v := range m {
    25  		count++
    26  		if count > 1 {
    27  			buffer += sep
    28  		}
    29  		buffer += f(k, v)
    30  	}
    31  	buffer += postfix
    32  	return buffer
    33  }
    34  
    35  func MapJoinToString[K comparable, V any](m map[K]V, f func(K, V) string) string {
    36  	return MapJoinToStringFull(m, ",", "", "", f)
    37  }