polserver/testsuite/escript/array/map.src
Kevin Eady d1a1bd3afe
Additional escript array functional methods (#674)
* 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
2024-08-02 20:39:32 +02:00

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