You can use SlotSequence and ConstantArray (or Table):
fun[x_List, n_Integer] := Flatten[Outer[List, ##] & @@ ConstantArray[x, n], 2]
fun[{a, b}, 3] == Tuples[{a, b}, 3]
(* True *)
Answer from rm -rf on Stack ExchangeWolfram Language
reference.wolfram.com › language › ref › Sequence.html
Sequence - Wolfram Language Documentation
Wolfram Language code: f[{{a, b}, {c, d}, {a}}] /. List -> Sequence · Conditionally add an element to a list by using Apply to delay the Sequence until evaluation:
Top answer 1 of 2
5
You can use SlotSequence and ConstantArray (or Table):
fun[x_List, n_Integer] := Flatten[Outer[List, ##] & @@ ConstantArray[x, n], 2]
fun[{a, b}, 3] == Tuples[{a, b}, 3]
(* True *)
2 of 2
4
Here's an approach with Table.
fun[x_List, n_Integer] := Flatten[Outer[List, Sequence @@ Table[x, {n}]], n-1]
examples
fun[{a, b}, 3]
{{a, a, a}, {a, a, b}, {a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b, b}}
fun[{a, b}, 4]
{{a, a, a, a}, {a, a, a, b}, {a, a, b, a}, {a, a, b, b}, {a, b, a, a}, {a, b, a, b}, {a, b, b, a}, {a, b, b, b}, {b, a, a, a}, {b, a, a, b}, {b, a, b, a}, {b, a, b, b}, {b, b, a, a}, {b, b, a, b}, {b, b, b, a}, {b, b, b, b}}
Wolfram Language
reference.wolfram.com › language › ref › List.html
List - Wolfram Language Documentation
A list can be converted to a sequence of expressions by applying Sequence to it.
Wolfram Language
reference.wolfram.com › language › ref › SequenceReplace.html
SequenceReplace - Wolfram Language Documentation
SequenceReplace[list, rules] replaces sequences in list according to the specified rule or list of rules. SequenceReplace[list, rules, n] does only the first n replacements. SequenceReplace[rules] represents an operator form of SequenceReplace ...
Webel IT Australia
webel.com.au › node › 3498
Mathematica: HOWTO Convert a list into a Sequence of arguments to a function (where each of the arguments to the function corresponds to a list item) | Webel IT Australia
There are many easy solutions, perhaps the easiest is the infix @@ version of Apply: f[a_,b_,c_,d_] := .. list = {fe,fi,fo,fum}; f @@ list It's also possible to splice sequences in. list2 = {e,f} g[a, b, c, d, Sequence @@ list2]
Wolfram Language
reference.wolfram.com › language › ref › FindSequenceFunction.html.en
FindSequenceFunction—Wolfram Documentation
FindSequenceFunction[{a1, a2, a3, ...}] attempts to find a simple function that yields the sequence an when given successive integer arguments. FindSequenceFunction[{{n1, a1}, {n2, a2}, ...}] attempts to find a simple function that yields ai ...
Wolfram Language
reference.wolfram.com › language › ref › List.html.en
List
A list can be converted to a sequence of expressions by applying Sequence to it.
Wolfram|Alpha
wolframalpha.com › examples › Sequences.html
Wolfram|Alpha Examples: Sequences
What can you ask Wolfram|Alpha about
Wolfram Language
reference.wolfram.com › language › ref › FindSequenceFunction.html
FindSequenceFunction - Wolfram Language Documentation
FindSequenceFunction[{a1, a2, a3, ...}] attempts to find a simple function that yields the sequence an when given successive integer arguments. FindSequenceFunction[{{n1, a1}, {n2, a2}, ...}] attempts to find a simple function that yields ai ...
Wolfram Language
reference.wolfram.com › language › ref › Sequence.html.en
Sequence
Listable · SequenceHold · Splice · Nothing · Tech Notes · Sequences · Sequence[expr1,expr2,…] represents a sequence of arguments to be spliced automatically into any function.
Wolfram Language
reference.wolfram.com › language › guide › IntegerSequences.html
Integer Sequences - Wolfram Language Documentation
The symbolic character of the Wolfram Language makes possible a uniquely coherent approach to integer sequences, integrating functional forms, equations, generating functions, and explicit lists of values. Powerful new algorithms developed at Wolfram Research make possible recognition of functional forms for an extremely wide range of classes of integer sequences.
Wolfram Language
reference.wolfram.com › language › ref › SequenceCases.html
SequenceCases - Wolfram Language Documentation
SequenceCases[list, patt] gives a list of the sublists in list that match the sequence pattern patt. SequenceCases[list, patt -> rhs] gives a list of the values of rhs corresponding to sublists that match patt.
Wolfram Language
reference.wolfram.com › language › guide › ListManipulation.html
List Manipulation - Wolfram Language Documentation
Lists are central constructs in the Wolfram Language, used to represent collections, arrays, sets, and sequences of all kinds. Lists can have any structure and size and can routinely involve even millions of elements. Well over a thousand built-in functions throughout the Wolfram Language operate ...
Wolfram Language
reference.wolfram.com › language › ref › SequenceCount.html
SequenceCount - Wolfram Language Documentation
In SequenceCount[list,patt], patt can be an expression with head List that includes pattern constructs such as PatternSequence, Repeated (..), Blank (_), and BlankSequence (__).
Wolfram|Alpha
wolframalpha.com › examples › IntegerSequences.html
Alpha Examples: Integer Sequences
What can you ask Wolfram|Alpha about
Wolfram Language
reference.wolfram.com › language › guide › IntegerSequences.html.en
Integer Sequences—Wolfram Documentation
The symbolic character of the Wolfram Language makes possible a uniquely coherent approach to integer sequences, integrating functional forms, equations, generating functions, and explicit lists of values. Powerful new algorithms developed at Wolfram Research make possible recognition of functional forms for an extremely wide range of classes of integer sequences.
Wolfram Language
reference.wolfram.com › language › guide › RearrangingAndRestructuringLists.html
Rearranging & Restructuring Lists—Wolfram Documentation
The Wolfram Language encapsulates in a small number of functions vast flexibility in rearranging lists with any structure and any number of elements. Flatten — flatten out any sequence of levels in a nested list
Wolfram Language
reference.wolfram.com › language › ref › SequencePosition.html
SequencePosition—Wolfram Documentation
SequencePosition[list, sublist] gives a list of the starting and ending positions at which sublist appears in list. SequencePosition[list, patt] gives all positions at which sequences matching patt occur in list.