Created
April 21, 2021 00:32
-
-
Save KinoAR/7b928fb0aaf0507a7bdbf28181d4191e to your computer and use it in GitHub Desktop.
Haxe Rest Summation Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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