Skip to content

Commit

Permalink
Add enumerate to prelude.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryancatanzaro committed May 8, 2013
1 parent 2962e59 commit 8f76d01
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend
Submodule backend updated from 4843c5 to cb331d
8 changes: 8 additions & 0 deletions copperhead/prelude.py
Expand Up @@ -239,7 +239,15 @@ def filter(function, sequence):
"""
return __builtin__.filter(function, sequence)

@cutype("([a]) -> [(Int, a)]")
@_wraps(__builtin__.enumerate)
def enumerate(x):
"""
Return a sequence containing (index, value) pairs, with values
from the input sequence.
"""
return list(__builtin__.enumerate(x))

############## Copperhead primitives not in Python builtins

Expand Down
4 changes: 4 additions & 0 deletions copperhead/prelude_impl.py
Expand Up @@ -99,3 +99,7 @@ def rotate_el(i):
def bounded_range(a, b):
length = b - a
return [xi + a for xi in range(length)]

@cu
def enumerate(x):
return zip(range(len(x)), x)

0 comments on commit 8f76d01

Please sign in to comment.