M8Test Help

associate

val numbers = arrayOf(1, 2, 3, 4, 5) // 将数字与其平方关联起来, {1=1, 2=4, 3=9, 4=16, 5=25} numbers.associate { it to it * it }.forEach { _console.log(it) }
def numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2, 3, 4, 5)) // 将数字与其平方关联起来, {1=1, 2=4, 3=9, 4=16, 5=25} numbers.associate { $maps.pairOf(it, it * it) }.forEach { $console.log(it) }
let numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2, 3, 4, 5)) // 将数字与其平方关联起来, {1=1, 2=4, 3=9, 4=16, 5=25} numbers.associate(((it) => $maps.pairOf(it, it * it))).forEach((it) => { $console.log(it) })
local numbers = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.Integer"), 1, 2, 3, 4, 5)) -- 将数字与其平方关联起来, {1=1, 2=4, 3=9, 4=16, 5=25end) numbers:associate(function(it) return _maps:pairOf(it, it * it) end) :forEach(function(it) _console:log(it) end)
<?php $numbers = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.Long"), 1, 2, 3, 4, 5)); // 将数字与其平方关联起来, {1=1, 2=4, 3=9, 4=16, 5=25}) $numbers->associate(function ($it) use ($maps) { return $maps->pairOf($it, $it * $it); })->forEach(function ($it) use ($console) { $console->log($it); });
numbers = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.Long"), 1, 2, 3, 4, 5)) # 将数字与其平方关联起来, {1=1, 2=4, 3=9, 4=16, 5=25} numbers.associate(lambda it: _maps.pairOf(it, it * it)).forEach(lambda it: _console.log(it))
# encoding: utf-8 numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Long"), 1, 2, 3, 4, 5)) # 将数字与其平方关联起来, {1=1, 2=4, 3=9, 4=16, 5=25} numbers.associate { |it| $maps.pairOf(it, it * it) }.forEach { |it| $console.log(it) }
Last modified: 08 August 2025