diff --git a/packages/beize_vm/lib/values/list.dart b/packages/beize_vm/lib/values/list.dart index 2e817ed..5a957e0 100644 --- a/packages/beize_vm/lib/values/list.dart +++ b/packages/beize_vm/lib/values/list.dart @@ -335,11 +335,9 @@ class BeizeListValue extends BeizePrimitiveObjectValue { } List flat(final int level) { - final List flat = []; + List flat = elements.toList(); for (int i = 0; i < level; i++) { - for (final BeizeValue x in elements) { - flat.addAll(x.cast().elements); - } + flat = _flatOnce(flat.cast()); } return flat; } @@ -374,3 +372,11 @@ class BeizeListValue extends BeizePrimitiveObjectValue { @override int get kHashCode => elements.hashCode; } + +List _flatOnce(final List elements) { + final List flat = []; + for (final BeizeValue x in elements) { + flat.addAll(x.cast().elements); + } + return flat; +}