M8Test Help

flatMap

val numbers = arrayOf(arrayOf(1, 2), arrayOf(3, 4), arrayOf(5, 6)) // 将嵌套数组展平为单个列表,展平后的列表: [1, 2, 3, 4, 5, 6] numbers.flatMap { it.toList() }.forEach { _console.log(it) }
def numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Object"), $arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2), $arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 3, 4), $arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 5, 6))) // 将嵌套数组展平为单个列表,展平后的列表: [1, 2, 3, 4, 5, 6] numbers.flatMap { $arrays.toList(it) }.forEach { $console.log(it) }
let numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Object"), $arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2), $arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 3, 4), $arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 5, 6))) // 将嵌套数组展平为单个列表,展平后的列表: [1, 2, 3, 4, 5, 6] numbers.flatMap(it => $arrays.toList(it)).forEach((it) => { $console.log(it) })
local numbers = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.Object"), _arrays:arrayOf(_plugins:loadClass("java.lang.Integer"), 1, 2), _arrays:arrayOf(_plugins:loadClass("java.lang.Integer"), 3, 4), _arrays:arrayOf(_plugins:loadClass("java.lang.Integer"), 5, 6))) -- 将嵌套数组展平为单个列表,展平后的列表: [1, 2, 3, 4, 5, 6] numbers:flatMap(function(it) return _arrays:toList(it) end) :forEach(function(it) _console:log(it) end)
<?php $numbers = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.Object"), $arrays->arrayOf($plugins->loadClass("java.lang.Long"), 1, 2), $arrays->arrayOf($plugins->loadClass("java.lang.Long"), 3, 4), $arrays->arrayOf($plugins->loadClass("java.lang.Long"), 5, 6))); // 将嵌套数组展平为单个列表,展平后的列表: [1, 2, 3, 4, 5, 6] $numbers->flatMap(function ($it) use ($arrays) { return $arrays->toList($it); })->forEach(function ($it) use ($console) { $console->log($it); });
numbers = _objectWrappers.wrap( _arrays.arrayOf(_plugins.loadClass("java.lang.Object"), _arrays.arrayOf(_plugins.loadClass("java.lang.Long"), 1, 2), _arrays.arrayOf(_plugins.loadClass("java.lang.Long"), 3, 4), _arrays.arrayOf(_plugins.loadClass("java.lang.Long"), 5, 6))) # 将嵌套数组展平为单个列表,展平后的列表: [1, 2, 3, 4, 5, 6] numbers.flatMap(lambda it: _arrays.toList(it)).forEach(lambda it: _console.log(it))
# encoding: utf-8 numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Object"), $arrays.arrayOf($plugins.loadClass("java.lang.Long"), 1, 2), $arrays.arrayOf($plugins.loadClass("java.lang.Long"), 3, 4), $arrays.arrayOf($plugins.loadClass("java.lang.Long"), 5, 6))) # 将嵌套数组展平为单个列表,展平后的列表: [1, 2, 3, 4, 5, 6] numbers.flatMap { |it| $arrays.toList(it) }.forEach { |it| $console.log(it) }
Last modified: 31 August 2025