Last active
October 8, 2025 23:59
-
-
Save acquitelol/8c164a343dc85bdada4b6d90e9b9abec to your computer and use it in GitHub Desktop.
Implements piping in vanilla JS.
This file contains hidden or 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
| // @ts-nocheck | |
| globalThis.rax = null; | |
| // for when you need the return value of the expr | |
| function pipe(_) { return globalThis.rax; }; | |
| function _(v) { return +(globalThis.rax = v); } | |
| Object.defineProperty(Function.prototype, Symbol.toPrimitive, { | |
| value: function() { | |
| globalThis.rax = this(globalThis.rax); | |
| return true; | |
| }, | |
| writable: true, | |
| configurable: true | |
| }); | |
| _(13) |0> (x => x * 2) | |
| |0> (x => x - 1) | |
| |0> (x => `${x}!!`) | |
| |0> console.log; | |
| _(12) |0> console.log; | |
| _([1, 2, 3]) | |
| |0> (x => x.map(y => y * 2)) | |
| |0> console.log; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment