Add enumerate

This commit is contained in:
Rnhmjoj 2014-07-04 16:34:36 +02:00
parent 9447daed1d
commit d42862a485
2 changed files with 10 additions and 0 deletions

View File

@ -75,3 +75,12 @@ func Range(args...int) ([]int) {
} }
return l return l
} }
func Enumerate(iter interface{}) interface{} {
viter := reflect.ValueOf(iter)
enum := make([][]interface{}, viter.Len())
for i:=0; i < viter.Len(); i++ {
enum[i] = []interface{}{i, viter.Index(i).Interface()}
}
return enum
}

View File

@ -22,6 +22,7 @@ func main(){
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),
Join(", ", []interface{}{2, -2.33, true, "hi"}), Join(", ", []interface{}{2, -2.33, true, "hi"}),
Enumerate([]int{1, 1, 2, 42, 24024, 701149020}),
Input("Say hi! "), Input("Say hi! "),
} }
fmt.Println(Join("\n",test)) fmt.Println(Join("\n",test))