next | previous | forward | backward | up | index | toc

# deepSplice -- remove all levels of subsequences from a sequence or list

## Synopsis

• Usage:
deepSplice X
• Inputs:
• X, ,
• Outputs:
• Y, , the new list resulting from replacing any element of X that is a sequence with its elements, at every level of nesting

## Description

Unlike the function splice, which removes a single nested level of subsequences, deepSplice recursively flattens subsequences at all levels.

 i1 : X = {(), (0, (1, 2, (3, 4))), (5, (6, 7)), 8, 9}; i2 : splice X o2 = {0, (1, 2, (3, 4)), 5, (6, 7), 8, 9} o2 : List i3 : deepSplice X o3 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} o3 : List

deepSplice does not alter elements that are lists, arrays, or anything other than sequences.

 i4 : Z = {(), {0, {1, 2, (3, 4)}}, [5, [6, 7]], 8, 9}; i5 : deepSplice Z o5 = {{0, {1, 2, (3, 4)}}, [5, [6, 7]], 8, 9} o5 : List

deepSplice works on sequences, too, and all other objects of class BasicList. The output matches the class of the input.

 i6 : deepSplice ((), (0, (1, 2, (3, 4))), (5, (6, 7)), 8, 9) o6 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) o6 : Sequence

Even if X is a MutableList, deepSplice returns a new list rather than altering the definition of X.

 i7 : M = new MutableList from X o7 = MutableList{...5...} o7 : MutableList i8 : deepSplice M o8 = MutableList{...10...} o8 : MutableList i9 : M o9 = MutableList{...5...} o9 : MutableList