有没有办法在Dart中基于条件拆分列表,类似以下方式:
[1, 2, 3, 4, 5, 6, 7, 8] (A sample list)
After splitting it based on i % 2 == 0 condition,
it would generate the following two lists:
1) [1, 3, 5, 7]
2) [2, 4, 6, 8]
我知道可以简单地编写循环来遍历所有元素并检查条件以创建两个子列表。但是,在Dart中是否有更短的函数式方式呢?非常感谢!