Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Last active April 21, 2021 00:40
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/2bc31987b21266bb01894d5c7bf7bf03 to your computer and use it in GitHub Desktop.
Save KinoAR/2bc31987b21266bb01894d5c7bf7bf03 to your computer and use it in GitHub Desktop.
Haxe Simple Pipe Example
import haxe.Rest;
function main() {
var result = pipe('A',
(val:String) -> val.toUpperCase(),
(val2:String) -> val2 += " " + "World");
trace(result); //A World
}
//Dynamic Piping Function
function pipe<T>(val:T, ...fns:T->Any) {
for(fn in fns) {
val = fn(val);
}
return val;
}
@KinoAR
Copy link
Author

KinoAR commented Apr 21, 2021

You can try out the example pipe here:

https://try.haxe.org/#082513ef

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