From 4232591fcc413f6137c8f6bcea0831814481a2ba Mon Sep 17 00:00:00 2001 From: ScuroNeko Date: Thu, 19 Feb 2026 15:05:01 +0300 Subject: [PATCH] join --- set.go | 10 ++++++++++ slice.go | 10 ++++++++++ tuple.go | 9 +++++++++ 3 files changed, 29 insertions(+) diff --git a/set.go b/set.go index e92b9dd..af1ce8e 100644 --- a/set.go +++ b/set.go @@ -1,7 +1,9 @@ package extypes import ( + "fmt" "reflect" + "strings" ) type Set[T any] []T @@ -108,3 +110,11 @@ func (s Set[T]) Map(f func(e T) T) Set[T] { } return s } + +func (s Set[T]) Join(sep string) string { + st := make([]string, len(s)) + for i, v := range s { + st[i] = fmt.Sprintf("%v", v) + } + return strings.Join(st, sep) +} diff --git a/slice.go b/slice.go index d0bdeba..1381450 100644 --- a/slice.go +++ b/slice.go @@ -1,7 +1,9 @@ package extypes import ( + "fmt" "reflect" + "strings" ) type Slice[T any] []T @@ -103,3 +105,11 @@ func (s Slice[T]) Map(f func(e T) T) Slice[T] { } return s } + +func (s Slice[T]) Join(sep string) string { + st := make([]string, len(s)) + for i, v := range s { + st[i] = fmt.Sprintf("%v", v) + } + return strings.Join(st, sep) +} diff --git a/tuple.go b/tuple.go index 4b24fbb..cd6386f 100644 --- a/tuple.go +++ b/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) }