mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* Implementation change for continuation handling * Implement array methods find, findIndex, map, reduce * Add tests * update filter test for coverage * update docs * change implementation to not copy * update tests; add tests for "polyfill" comparison * update escript guide
35 lines
832 B
Text
35 lines
832 B
Text
print( array{ "a", "b", "c", "d", "e" }.map( @ConstantString ) );
|
|
print( array{ "a", "b", "c", "d", "e" }.map( @ToIndex ) );
|
|
print( array{ "a", "b", "c", "d", "e" }.map( @ToUpper ) );
|
|
print( array{ "a", "b", "c", "d", "e" }.map( @UsesAllParameters ) );
|
|
|
|
print( array{}.map( @DoNotCall ) ); // Returns new, empty array
|
|
|
|
// Test with a name_arr'd array
|
|
var arr := array{ "hello" };
|
|
arr.+name := "hello";
|
|
print( arr.map( @DoNotCall ) );
|
|
|
|
// Errors
|
|
print( array{}.map() );
|
|
print( array{}.map( "foo" ) );
|
|
|
|
function ConstantString()
|
|
return "!";
|
|
endfunction
|
|
|
|
function ToIndex( unused element, index )
|
|
return index;
|
|
endfunction
|
|
|
|
function ToUpper( element )
|
|
return Upper( element );
|
|
endfunction
|
|
|
|
function UsesAllParameters( element, index, arr )
|
|
return $"{element}{arr[index]}";
|
|
endfunction
|
|
|
|
function DoNotCall()
|
|
exit;
|
|
endfunction
|