join
This commit is contained in:
9
tuple.go
9
tuple.go
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Tuple[T any] struct {
|
||||
@@ -60,6 +61,14 @@ func (t Tuple[T]) ForEach(f func(int, T)) Tuple[T] {
|
||||
return t
|
||||
}
|
||||
|
||||
func (t Tuple[T]) Join(sep string) string {
|
||||
st := make([]string, len(t.s))
|
||||
for i, v := range t.s {
|
||||
st[i] = fmt.Sprintf("%v", v)
|
||||
}
|
||||
return strings.Join(st, sep)
|
||||
}
|
||||
|
||||
func (t Tuple[T]) String() string { return fmt.Sprint(t.s) }
|
||||
func (t *Tuple[T]) UnmarshalJSON(data []byte) error { return json.Unmarshal(data, &t.s) }
|
||||
func (t Tuple[T]) MarshalJSON() ([]byte, error) { return json.Marshal(t.s) }
|
||||
|
||||
Reference in New Issue
Block a user