Skip to content

Instantly share code, notes, and snippets.

@KinoAR

KinoAR/SumRest.hx

Created Apr 21, 2021
Embed
What would you like to do?
Haxe Rest Summation Example
import haxe.Rest;
function main() {
trace(sum(1, 2, 3));
trace(sum('Hello', ' World'));
}
function sum(...rest:Dynamic) {
var result = null;
for(element in rest) {
result = result == null ? element : result + element;
}
return result;
}
@KinoAR

This comment has been minimized.

Copy link
Owner Author

@KinoAR KinoAR commented Apr 21, 2021

Haxe Rest Example

This illustrates some uses for rest that give a very JavaScript-like feel when building APIs.

You can see the example and run it here: https://try.haxe.org/#E8cD2F39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment