Skip to content

Commit

Permalink
fix: list flat
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Nov 30, 2023
1 parent e8e6bda commit cfb5ad3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/beize_vm/lib/values/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,9 @@ class BeizeListValue extends BeizePrimitiveObjectValue {
}

List<BeizeValue> flat(final int level) {
final List<BeizeValue> flat = <BeizeValue>[];
List<BeizeValue> flat = elements.toList();
for (int i = 0; i < level; i++) {
for (final BeizeValue x in elements) {
flat.addAll(x.cast<BeizeListValue>().elements);
}
flat = _flatOnce(flat.cast<BeizeListValue>());
}
return flat;
}
Expand Down Expand Up @@ -374,3 +372,11 @@ class BeizeListValue extends BeizePrimitiveObjectValue {
@override
int get kHashCode => elements.hashCode;
}

List<BeizeValue> _flatOnce(final List<BeizeValue> elements) {
final List<BeizeValue> flat = <BeizeValue>[];
for (final BeizeValue x in elements) {
flat.addAll(x.cast<BeizeListValue>().elements);
}
return flat;
}

0 comments on commit cfb5ad3

Please sign in to comment.