Skip to content

Commit 245d62d

Browse files
committed
Merge branch 'release/1.4.9a'
2 parents 4105353 + 234ed02 commit 245d62d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

warg/iteration.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
#!/usr/bin/env python3
22

33
import logging
4-
from itertools import pairwise
5-
from typing import Any, Callable, Iterable, List, Sequence, Sized, Tuple
4+
from typing import Any, Callable, Generator, Iterable, List, Sequence, Sized, Tuple
5+
6+
try:
7+
from itertools import pairwise
8+
except:
9+
10+
def pairwise(iterable: Iterable) -> Generator:
11+
# pairwise('ABCDEFG') → AB BC CD DE EF FG
12+
13+
iterator = iter(iterable)
14+
a = next(iterator, None)
15+
16+
for b in iterator:
17+
yield a, b
18+
a = b
19+
620

721
logger = logging.getLogger(__name__)
822
__all__ = ["pairs", "chunks", "leaf_apply", "leaf_type_apply"]
923

1024

11-
def pairs(s: Iterable) -> Tuple[Any, Any]:
25+
def pairs(s: Iterable) -> Generator[tuple[Any, Any], None, None]:
1226
"""
1327
1428
NOTE: Just use itertools.pairwise....

0 commit comments

Comments
 (0)