M8Test Help

flatMapTo

val nc = mutableListOf<Int>() val numbers = arrayOf(arrayOf(1, 2), arrayOf(3, 4), arrayOf(5, 6)) // 将嵌套数组展平为单个列表,展平后的列表: [1, 2, 3, 4, 5, 6] numbers.flatMapTo(nc) { it.toList() }.forEach { _console.log(it) }
def wc = $objectWrappers.wrap($iterables.mutableListOf()) 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.flatMapTo(wc) { $arrays.toList(it) }.forEach { $console.log(it) }
let wc = $objectWrappers.wrap($iterables.mutableListOf()) 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.flatMapTo(wc, it => $arrays.toList(it)).forEach((it) => { $console.log(it) })
local wc = _objectWrappers:wrap(_iterables:mutableListOf()) 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:flatMapTo(wc, function(it) return _arrays:toList(it) end) :forEach(function(it) _console:log(it) end)
<?php $wc = $objectWrappers->wrap($iterables->mutableListOf()); $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->flatMapTo($wc, function ($it) use ($arrays) { return $arrays->toList($it); })->forEach(function ($it) use ($console) { $console->log($it); });
wc = _objectWrappers.wrap(_iterables.mutableListOf()) 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.flatMapTo(wc, lambda it: _arrays.toList(it)).forEach(lambda it: _console.log(it))
# encoding: utf-8 wc = $objectWrappers.wrap($iterables.mutableListOf()) 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.flatMapTo(wc) { |it| $arrays.toList(it) }.forEach { |it| $console.log(it) }
Last modified: 05 September 2025