Added Join and improved test
This commit is contained in:
parent
9620206ee8
commit
af92f694d9
16
py/str.go
16
py/str.go
@ -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)
|
||||||
|
}
|
||||||
|
5
test.go
5
test.go
@ -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))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user