Created
May 18, 2019 09:23
-
-
Save toomasv/4980a6d4a7e6f97817d86ffcf32329ab to your computer and use it in GitHub Desktop.
Applies func(s) to elements of series
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
Red [ | |
Description: {Applies function or sequence of functions | |
to block or collected output of previous functions} | |
Date: 18-May-2019 | |
Author: "Toomas Vooglaid" | |
] | |
each*: make op! function [fn [any-function! block!] block [series!]][ | |
{Applies a function to as many elements of the block as it has arguments | |
or a sequence of functions to the block or collected output of the previous function. | |
Returns block with the collected result of last function} | |
append fns: clear [] reduce :fn | |
foreach fn fns [ | |
words: parse spec-of :fn [collect [ | |
some [refinement! break | keep word! | skip]] | |
] | |
code: compose/deep [ | |
block: collect [ | |
foreach [(words)] block [ | |
attempt [keep (compose either op? :fn [ | |
[(words/1) fn (words/2)] | |
] [ | |
[fn (words)] | |
])] | |
] | |
] | |
] | |
do code | |
] | |
] | |
;Simple `each` | |
each: make op! func [fn block][forall block [fn block/1]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment