chunky v0.1.0 Chunky View Source
Extended chunking and enumeration manipulations.
Functions
Chunky.permutations/1- Generate all combinations of a set of values, with no duplicationChunky.filter_with_predicates/2- Filter an enumeration to only those entries that meet all the provided predicate functionsChunky.chunk_runs/1- Chunk an enumerable by runs of duplicate valuesChunky.chunk_to_length/2- Chunk an enumerable into specific length chunks
TODO: Chunky.filter_with_predicates/2 TODO: Chunky.take_sequences/1 TODO: Chunky.take_chunks/2
Link to this section Summary
Functions
Generate all of the permutations, without duplicates, from a set of values. The set of values can be
Link to this section Functions
Generate all of the permutations, without duplicates, from a set of values. The set of values can be:
- a list of any type, like
[1, 2, 3]or[:a, :b, %{}] - a string or binary, like
"abcd" - a tuple, like
{1, :b, "asdf"} - a range, like
1..4or3..-1
This is not lazy generated, so a permutation of a large set may take awhile. Keep in mind
that the total number of permutations for a set of N values is N!.
When a set is permuted, the resulting list will contain values in the shape of the original; a permuted list will contains lists, permuted tuples will contain tuples, permuted strings will contain strings. The only exception is ranges, which will result in lists.
So, for instance, a permuted string will result in a list of strings. Chunky should handle Unicode just fine:
iex> Chunky.permutations("😀★⍵")
["😀★⍵", "😀⍵★", "★😀⍵", "★⍵😀", "⍵😀★", "⍵★😀"]
Examples
iex> Chunky.permutations([1, 2, 3])
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
iex> Chunky.permutations("abc")
["abc", "acb", "bac", "bca", "cab", "cba"]
iex> Chunky.permutations({:a, :b, :c})
[ {:a, :b, :c}, {:a, :c, :b}, {:b, :a, :c}, {:b, :c, :a}, {:c, :a, :b}, {:c, :b, :a} ]
iex> Chunky.permutations(1..-1)
[ [1, 0, -1], [1, -1, 0], [0, 1, -1], [0, -1, 1], [-1, 1, 0], [-1, 0, 1]]