diff --git a/py/lambda.go b/py/lambda.go index a6c0710..e9e8a58 100644 --- a/py/lambda.go +++ b/py/lambda.go @@ -75,3 +75,12 @@ func Range(args...int) ([]int) { } 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 +} diff --git a/test.go b/test.go index e18909c..70b99b6 100644 --- a/test.go +++ b/test.go @@ -22,6 +22,7 @@ func main(){ Min([]float64{3.14159, 23.14069, 2.71828}), Max(-3,24,1,-23,31), Join(", ", []interface{}{2, -2.33, true, "hi"}), + Enumerate([]int{1, 1, 2, 42, 24024, 701149020}), Input("Say hi! "), } fmt.Println(Join("\n",test))