Skip to content

Commit

Permalink
make repeat work with iterables
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Apr 29, 2015
1 parent de5006f commit d8834b1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sak/iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,24 @@ def starmap ( callable = None , iterable = None ) :


@lib.args.convert( n = int )
def repeat ( item , n = -1 ) :
def repeat ( iterable = None , n = -1 ) :

"""
Repeat given string n times. If n is negative then repeat given string an infinite number of times.
Repeat given lines n times. If n is negative then repeat given string an infinite number of times.
"""

iterable = lib.args.listify( iterable )

if not iterable :
iterable = [ s[:-1] for s in fileinput.input( [] ) ]

if n < 0 :
args = [ None ]
else :
args = [ None , n ]

for _ in itertools.repeat( *args ) :
print( item )
for item in iterable : print( item )


@lib.args.convert( n = int )
Expand Down

0 comments on commit d8834b1

Please sign in to comment.