Skip to main content
Module

x/itertools/mod.ts

🦕 A TypeScript port of Python's itertools and more-itertools for Deno
Latest
import * as itertools from "https://deno.land/x/itertools@v1.1.2/mod.ts";

Functions

Returns true when all of the items in iterable are truthy. An optional key function can be used to define what truthiness means for this specific collection.

Returns true when any of the items in iterable are truthy. An optional key function can be used to define what truthiness means for this specific collection.

Returns an iterator that returns elements from the first iterable until it is exhausted, then proceeds to the next iterable, until all of the iterables are exhausted. Used for treating consecutive sequences as a single sequence.

Break iterable into lists of length size:

See icompact().

Removes all undefined values from the given object. Returns a new object.

Non-lazy version of icompress().

Returns true when any of the items in the iterable are equal to the target object.

Returns an iterator that counts up values starting with number start (default 0), incrementing by step. To decrement, use a negative step number.

Returns an iterator producing elements from the iterable and saving a copy of each. When the iterable is exhausted, return elements from the saved copy. Repeats indefinitely.

Returns an iterator that drops elements from the iterable as long as the predicate is true; afterwards, returns every remaining element. Note, the iterator does not produce any output until the predicate first becomes false.

Returns an iterable of enumeration pairs. Iterable must be a sequence, an iterator, or some other object which supports iteration. The elements produced by returns a tuple containing a counter value (starting from 0 by default) and the values obtained from iterating over given iterable.

Non-lazy version of ifilter().

Returns the first item in the iterable for which the predicate holds, if any. If no such item exists, undefined is returned. The default predicate is any defined value.

Returns 0 or more values for every value in the given iterable. Technically, it's just calling map(), followed by flatten(), but it's a very useful operation if you want to map over a structure, but not have a 1:1 input-output mapping. Instead, if you want to potentially return 0 or more values per input element, use flatmap():

Return an iterator flattening one level of nesting in a list of lists:

Yields the heads of all of the given iterables. This is almost like roundrobin(), except that the yielded outputs are grouped in to the "rounds":

Returns an iterable, filtering out any undefined values from the input iterable. This function is useful to convert a list of Maybe<T>'s to a list of T's, discarding all the undefined values:

Returns an iterator that filters elements from data returning only those that have a corresponding element in selectors that evaluates to true. Stops when either the data or selectors iterables has been exhausted.

Returns an iterator that filters elements from iterable returning only those for which the predicate is true.

Returns an iterator that computes the given mapper function using arguments from each of the iterables.

Returns an iterable containing only the first n elements of the given iterable.

Returns an iterator object for the given iterable. This can be used to manually get an iterator for any iterable datastructure. The purpose and main use case of this function is to get a single iterator (a thing with state, think of it as a "cursor") which can only be consumed once.

Returns an iterator that aggregates elements from each of the iterables. Used for lock-step iteration over several iterables at a time. When iterating over two iterables, use izip2. When iterating over three iterables, use izip3, etc. izip is an alias for izip2.

Like izip2, but for three input iterables.

Like the other izips (izip, izip3, etc), but generalized to take an unlimited amount of input iterables. Think izip(*iterables) in Python.

Non-lazy version of imap().

Return the largest item in an iterable. Only works for numbers, as ordering is pretty poorly defined on any other data type in JS. The optional keyFn argument specifies a one-argument ordering function like that used for sorted().

Return the smallest item in an iterable. Only works for numbers, as ordering is pretty poorly defined on any other data type in JS. The optional keyFn argument specifies a one-argument ordering function like that used for sorted().

Returns an iterator of paired items, overlapping, from the original. When the input iterable has a finite number of items n, the outputted iterable will have n - 1 items.

Returns a 2-tuple of arrays. Splits the elements in the input iterable into either of the two arrays. Will fully exhaust the input iterable. The first array contains all items that match the predicate, the second the rest:

Return successive r-length permutations of elements in the iterable.

Returns an iterator producing all the numbers in the given range one by one, starting from start (default 0), as long as i < stop, in increments of step (default 1).

Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a single value. For example:

Yields the next item from each iterable in turn, alternating between them. Continues until all items are exhausted.

Return a new sorted list from the items in iterable.

Sums the items of an iterable from left to right and returns the total. The sum will defaults to 0 if the iterable is empty.

Non-lazy version of itake().

Returns an iterator that produces elements from the iterable as long as the predicate is true.

Yield unique elements, preserving order.

Yields elements in order, ignoring serial duplicates.

See izip.

See izip3.