From af92f694d9af58d18046ccad573090cd73ea17b1 Mon Sep 17 00:00:00 2001 From: Rnhmjoj Date: Sun, 2 Mar 2014 15:28:48 +0100 Subject: [PATCH] Added Join and improved test --- py/str.go | 16 +++++++++++++++- test.go | 5 +++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/py/str.go b/py/str.go index d68a884..63395e2 100644 --- a/py/str.go +++ b/py/str.go @@ -1,6 +1,10 @@ package py -import ("fmt") +import ( + "fmt" + "strings" + "reflect" +) func Chr(x rune) string { @@ -14,3 +18,13 @@ func Ord(x string) rune { } return rune(x[0]) } + + +func Join(sep string, iter interface{}) string { + var list []string + viter := reflect.ValueOf(iter) + for i := 0; i < viter.Len(); i++ { + list = append(list, fmt.Sprintf("%v", viter.Index(i).Interface())) + } + return strings.Join(list, sep) +} diff --git a/test.go b/test.go index 0677e7e..9674970 100644 --- a/test.go +++ b/test.go @@ -21,7 +21,8 @@ func main(){ All([]interface{}{true,"",1}), Min([]float64{3.14159,23.14069,2.71828}), Max(-3,24,1,-23,31), - Input("Scrivi qualcosa: "), + Join(", ", []interface{}{2,-2.33,true,"hi",}), + //Input("Say hi! "), } - fmt.Println(test) + fmt.Println(Join("\n",test)) }