M8Test Help

mapNotNullTo

val dw = mutableListOf<Int>() val data = arrayOf("one", null, "three", "four", null) // 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4] data.mapNotNullTo(dw) { it?.count() }.forEach { _console.log(it) }
def dw = $objectWrappers.wrap($iterables.mutableListOf()) def data = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "one", null, "three", "four", null)) // 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4] data.mapNotNullTo(dw) { if (it != null) { $objectWrappers.wrap(it).count() } }.forEach { $console.log(it) }
let dw = $objectWrappers.wrap($iterables.mutableListOf()) let data = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "one", null, "three", "four", null)) // 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4] data.mapNotNullTo(dw, it => { if (it != null) { return $objectWrappers.wrap(it).count() } else { return null } }).forEach((it) => { $console.log(it) })
local dw = _objectWrappers:wrap(_iterables:mutableListOf()) local data = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.String"), "one", nil, "three", "four", nil)) -- 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4] data:mapNotNullTo(dw, function(it) if (it ~= nil) then return _objectWrappers:wrap(it):count() else return nil end end):forEach(function(it) _console:log(it) end)
<?php $dw = $objectWrappers->wrap($iterables->mutableListOf()); $data = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "one", null, "three", "four", null)); // 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4] $data->mapNotNullTo($dw, function ($it) use ($objectWrappers) { if ($it != null) return $objectWrappers->wrap($it)->count(); else return null; })->forEach(function ($it) use ($console) { $console->log($it); });
dw = _objectWrappers.wrap(_iterables.mutableListOf()) data = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.String"), "one", None, "three", "four", None)) # 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4] data.mapNotNullTo(dw, lambda it: _objectWrappers.wrap(it).count() if it != None else None).forEach( lambda it: _console.log(it))
# encoding: utf-8 dw = $objectWrappers.wrap($iterables.mutableListOf()) data = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "one", nil, "three", "four", nil)) # 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4] data.mapNotNullTo(dw) { |it| if it != nil then $objectWrappers.wrap(it).count() else nil end }.forEach { |it| $console.log(it) }
Last modified: 09 September 2025