Created: 2011-07-12 03:12
Updated: 2014-07-21 19:51



This library serves as an JavaScript adaptation of the itertools and functools built-in libraries of the Python language.

The iterator

__.iterator will return a Python iterator inspired object. Looping through them can be done via the following:

var iterator = __.iterator(0, function(c) { return c + 1; }, function(c) { return c > 3; });

while ((c = != __.stop) {

"Itertools" - Tools for Iteration

Most of these functions can be found within Python's itertools documentation. They will be reiterated here for the sake of minor discrepencies and convienience.


__.combinations(iterable, num)

__.compress(iterator, selectors)

__.count(start, step)


__.dropwhile(predicate, iterable)

__.idropwhile(predicate, iterable)

__.ifilter(predicate, iterable)

__.ifilterfalse(predicate, iterable)

__.groupby(iterable. key)

__.imap(callable, *iterables)

__.nth(iterable, index, default)

__.permuatations(iterable, num)

__.product(*iterables, repeat)

__.repeat(entity, times)

__.islice(iterable. start=0, stop=iterable.length, stop=1)

__.starmap(callable, iterable)

__.takewhile(predicate, iterable)

__.itakewhile(predicate, iterable)

__.tee(predicate, iterable), two)

__.izip(one, two)

"Functools" - Tools for Functional Development

__.partial(function, arguments)

Curries a function. Currying is to create a new function signature with the original function arguments prefilled with arguments. ie:

var add = function(a, b) { return a + b; }
var addToTwo = __.partial(add, 2);
addToTwo(3); // 5

__.curry(function, arguments)

Alias for __.partial().

__.reduce(function, sequence, initializer)

See Python's reduce()

Extra & Goodies


Creates a true boolean from an entity (ie: nonzero)


Creates a sequence from an entity. ie:

__.iterable([1, 2, 3]); // [1, 2, 3]
__.iterable('ABCD'); // ['A', 'B', 'C', 'D']
__.iterable(1); // [1]

__.range(min, max)

Constructs a range.


Reverses the order of an iterator. ie:

__.reverse([1, 2, 3]); // [3, 2, 1]


Returns a set an sequence of unique elements.

__.set([1, 1, 2, 3, 3]); // [3, 2, 1]


Returns the iterable from iterables with the smallest length.


Like __.smallest(), but returns the largest iterable.

Playing with Other Libraries


if (_ && _.mixin) {


if ($ && $.extend) {
	$.extend($, __);
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more