The lazy sequence of results returned by SComb.permutations/1,
SComb.combinations/2, SComb.subsets/1, SComb.selections/2,
SComb.partitions/1, SComb.combinations_with_replacement/2,
SComb.permuted_combinations/2 and SComb.cartesian_product/1.
A sequence is an Enumerable that generates its elements one at a time, like
a Stream. In addition it knows its size and how to find an element by its
index, so functions such as Enum.count/1, Enum.at/2, Enum.slice/2,
Enum.take/2 with a negative amount and Enum.random/1 do not generate the
elements before the ones asked for:
iex> sequence = SComb.permutations(1..30)
iex> Enum.count(sequence)
265252859812191058636308480000000
iex> Enum.at(sequence, 10 ** 30) |> Enum.take(3)
[14, 28, 9]Indexing is only used for inputs of moderate size, as the size of the
sequence has to be cheap to find. For larger inputs the sequence is
streamed, and Enum.count/1 still returns the size.
Summary
Types
@type t() :: %SComb.Sequence{ count: (-> non_neg_integer()), from: (non_neg_integer() -> Enumerable.t()), indexable: boolean(), name: String.t(), nth: (non_neg_integer() -> term()), stream: Enumerable.t() }
A lazy, indexable sequence of results