Typing
vlad-bezden opened this issue · comments
On page 88 specify typing for Callable
from typing import Iterable, Callable
def for_each(xs: Iterable[int], do: Callable[[Iterable[int]], None]) -> None:
it = iter(xs)
try:
while True:
do(next(it))
except StopIteration:
pass
# works with lists
for_each([1, 2, 3], print)
# works with iterators
for_each(upto(3), print)
next time I'm having you do my copy-editing.
would you believe this one I did on purpose, for a couple of reasons
- the "correct" way made the line much too long
- the "correct" way is pretty unwieldy to read and doesn't add a lot compensating pedagogical value
thanks, though, keep them coming!
Thank you, Joel. I'll be glad to do any of your books copy-editing. I have your "Data Science from Scratch" and I like the way you teach and explain. I also like and enjoy reading "Ten Essays on Fizz Buzz."
You are right that the "correct" way made the ling too long. However, I found it also teaches how to do correctly type annotations.
I'm learning a lot from your books and type annotations is one of them.
Thank you for such a great book, and keep up the excellent work.