hylang/hy — pull request #524 by pyos (2014-02-28 12:41:51+00:00)
Title: Reimplement some function in terms of the standard library.

Namely:

* `take-while` is strictly equivalent to `itertools.takewhile` on both Python 2 and 3;
* also: `drop-while` = `itertools.dropwhile`, `filter` = built-in `filter`, `zipwith` = built-in `map`, `repeat` = `itertools.repeat`, `cycle` = `itertools.cycle`;
* `take` and `drop` are easily implemented as calls to `itertools.islice`;
* `nth` is (almost) `(next (drop i xs))` which, unlike the previous implementation, correctly works on infinite iterators;
* `iterable?` and `iterator?` are best implemented by using ABCs from `collections`, as `(iter coll)` may evaluate some code with side effects.

In addition to that, `nth` will raise `IndexError` instead of returning `None` while `nth`, `take`, and `drop` will raise `ValueError` on negative indices. The main reasons for that are consistency (`itertools.islice` and `take-nth` do not accept negative indices while `get` will raise `IndexError` if the index is out of bounds) and clarity (`None` is a valid value for a collection to contain, and thus should not be used to signal errors.)

(Also, the documentation for `zipwith` was previously misplaced: it clearly should be in `core.rst`, not `api.rst`.)