Skip to content

Commit

Permalink
Merge pull request JulienPalard#33 from vstoykov/improve/tail
Browse files Browse the repository at this point in the history
Improve tail pipe
  • Loading branch information
JulienPalard authored May 21, 2018
2 parents 0aa7bb6 + 38d5a84 commit 1ecb06d
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import socket
import sys
from contextlib import closing
from collections import deque

try:
import builtins
Expand Down Expand Up @@ -74,12 +75,7 @@ def take(iterable, qte):
@Pipe
def tail(iterable, qte):
"Yield qte of elements in the given iterable."
out = []
for item in iterable:
out.append(item)
if len(out) > qte:
out.pop(0)
return out
return deque(iterable, maxlen=qte)


@Pipe
Expand Down

0 comments on commit 1ecb06d

Please sign in to comment.