Added Join and improved test

This commit is contained in:
Rnhmjoj 2014-03-02 15:28:48 +01:00
parent 9620206ee8
commit af92f694d9
2 changed files with 18 additions and 3 deletions

View File

@ -1,6 +1,10 @@
package py package py
import ("fmt") import (
"fmt"
"strings"
"reflect"
)
func Chr(x rune) string { func Chr(x rune) string {
@ -14,3 +18,13 @@ func Ord(x string) rune {
} }
return rune(x[0]) 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)
}

View File

@ -21,7 +21,8 @@ func main(){
All([]interface{}{true,"",1}), All([]interface{}{true,"",1}),
Min([]float64{3.14159,23.14069,2.71828}), Min([]float64{3.14159,23.14069,2.71828}),
Max(-3,24,1,-23,31), 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))
} }