formulae v0.7.4 Formulae.Combinators View Source

Functions to calculate all the combinations, permutations and repeated permutations of the list given.

Examples

iex> Formulae.Combinators.combinations(~w|a b c d|a, 2)
[[:a, :b], [:a, :c], [:a, :d], [:b, :c], [:b, :d], [:c, :d]]
iex> Formulae.Combinators.permutations(~w|a b c d|a, 2)
[[:a, :b], [:a, :c], [:a, :d], [:b, :a], [:b, :c], [:b, :d],
 [:c, :a], [:c, :b], [:c, :d], [:d, :a], [:d, :b], [:d, :c]]
iex> Formulae.Combinators.repeated_permutations(~w|a b c d|a, 2)
[[:a, :a], [:a, :b], [:a, :c], [:a, :d], [:b, :a], [:b, :b],
 [:b, :c], [:b, :d], [:c, :a], [:c, :b], [:c, :c], [:c, :d],
 [:d, :a], [:d, :b], [:d, :c], [:d, :d]]

NB this functions should not be used for relatively big n because they perform greedy evaluation. See to Formulae.Combinators.Stream for lazy analogues returning streams.

Link to this section Summary

Functions

Calculates all combinations of the list, given as the first parameter

Calculates all permutations of the list, given as the first parameter

Calculates all repeated permutations of the list, given as the first parameter

Link to this section Functions

Link to this macro

combinations(l, n)

View Source (macro)
combinations(list :: list(), count :: non_neg_integer()) :: [list()]

Calculates all combinations of the list, given as the first parameter

Link to this macro

permutations(l, n)

View Source (macro)
permutations(list :: list(), count :: non_neg_integer()) :: [list()]

Calculates all permutations of the list, given as the first parameter

Link to this macro

repeated_permutations(l, n)

View Source (macro)
repeated_permutations(list :: list(), count :: non_neg_integer()) :: [list()]

Calculates all repeated permutations of the list, given as the first parameter