Flatten
The collection with all levels of nested lists merged into one.
✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram Language
Flatten✓Flatten(collection)every level of nested lists merged into one.Flatten(collection, n)flattening limited to the top n levels.Flatten(collection, PositiveInfinity)an explicit infinite depth, the same as the default.Flatten(collection, {{p1}, {p2}, …})a permutation-shaped list of levels regroups the array's dimensions — transposing a matrix, say.Flatten(expr)nested calls of any one head flatten, not just 's.Typed signatures
| Type | Package | Applies |
|---|---|---|
(value, integer?) -> list | compute-engine | always |
(any, any?) -> any | combinatoricsreplaces compute-engine | always |
Details
- Undoes Partition: chunking and then re-flattening recovers the original list.
- Simply deletes inner braces/levels; it doesn't otherwise reorder or transform elements.
- A depth argument limits flattening to that many levels, leaving deeper nesting intact.
- Any single head's nested calls flatten, not just 's.
Examples
1 more kept as data, checked against the oraclesScope #
A depth argument limits flattening to just that many levels, leaving deeper nesting intact
live ↗InOut
Properties #
A three-index array flattens in lexicographic index order, so the digits count up like an odometer
live ↗InOut
live ↗
InOut
About
| Examples | 23 |
|---|---|
| Checked against | Wolfram Language 23 agreemathlib4 2 agree10 error |
| Crosswalk | Wolfram Language |
Implementation
mapped
mathlib4packages/oracle/src/mappings.tsA list of lists of numbers, merged one level, which is every level there is. Deeper or ragged nesting and a flat list fail to elaborate, since Lean types them differently from ours.
mapped
mathlib4packages/oracle/src/mappings.tsA depth of one or more over a list of lists of numbers, where that is the same as flattening fully. Depth zero or a negative depth fails to elaborate, as does any nesting deeper than two levels.
See also: Join