Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Created April 21, 2021 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KinoAR/7b928fb0aaf0507a7bdbf28181d4191e to your computer and use it in GitHub Desktop.
Save KinoAR/7b928fb0aaf0507a7bdbf28181d4191e to your computer and use it in GitHub Desktop.
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
Copy link
Author

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