How To Use Rest
Advantages Of Rest
Rest allows you to create additive functions, variadic functions that were never available before in Haxe without using an array or using some of the functions tools. For example, with rest, you can write a summing function that takes any amount of numbers, strings, and more. You could do the same thing for numbers with multiplication. See the example below.
Another example use for this is to create a piping function. A piping function is a function that takes a value and applies each function individually to the value. Here’s an example.
As you can see the value just gets piped through each function until you finally reach the end. This can be very useful in functional programming.
There are many more use cases for Rest in Haxe. I feel we’ve barely scratched the surface. Hopefully, you find these useful in your own code. I know I’ll start using them in my own game in order to make things easier for myself for creating robust APIs!
For additional references you can find the API for Rest here.