Skip to content

Commit 2d91d85

Browse files
committed
feature: add type hints for recipes (#496)
1 parent e9bc1e1 commit 2d91d85

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ dist/
44
*.egg-info/
55
bench/shakespeare.txt
66
.coverage
7+
.idea
78

89
\.tox/

toolz/recipes.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import itertools
2-
from .itertoolz import frequencies, pluck, getter
2+
from typing import TypeVar, Iterable, Dict, Tuple, Callable
33

4+
from .itertoolz import frequencies, pluck, getter
45

56
__all__ = ('countby', 'partitionby')
67

8+
A = TypeVar('A')
9+
B = TypeVar('B')
10+
711

8-
def countby(key, seq):
12+
def countby(key: Callable[[A], B], seq: Iterable[A]) -> Dict[B, int]:
913
""" Count elements of a collection by a key function
1014
1115
>>> countby(len, ['cat', 'mouse', 'dog'])
@@ -23,7 +27,8 @@ def countby(key, seq):
2327
return frequencies(map(key, seq))
2428

2529

26-
def partitionby(func, seq):
30+
def partitionby(func: Callable[[A], bool],
31+
seq: Iterable[A]) -> Iterable[Tuple[A, ...]]:
2732
""" Partition a sequence according to a function
2833
2934
Partition `s` into a sequence of lists such that, when traversing

0 commit comments

Comments
 (0)