/gist:048d5e6593c51a91193e Secret
Last active
August 29, 2015 14:14
-
-
Save hostilefork/048d5e6593c51a91193e to your computer and use it in GitHub Desktop.
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
thread: function/with [ | |
{ | |
sends a value through a block of functions, the first argument of the last function | |
becomes the value. This value is then seeded by composing the functions together. | |
Ex: thread 1 + 1 [add 1 add 2] => [add add 2 2 1] | |
} | |
first-composed-value | |
code-block | |
/only "only return the code itself, do not evaluate it" | |
] [ | |
each [arg code-arg rearranged-code] memoize [ | |
if all [ | |
first-composed-value = arg | |
code-arg = code-block | |
] [ | |
code: rearranged-code | |
break | |
] | |
] | |
unless code [ | |
code: copy [] | |
append memoize first-composed-value | |
append/only memoize code-block | |
insert code first-composed-value | |
while [not empty? code-block][ | |
fx: code-block/1 | |
fx-arg-amount: length words-of get fx | |
insert code fx | |
append code copy/part next code-block (fx-arg-amount - 1) | |
code-block: skip code-block fx-arg-amount | |
] | |
append/only memoize code | |
] | |
return either only [code] [do code] | |
] [ | |
memoize: [] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment