Can Functions You ➤ Now REORDER

As things have slowly nudged along in the function composition space, I've kept a generic reordering facility in mind.

And today... less than a week into 2021... we have a first version of it, tentatively named REORDER.

>> append-value-first: reorder :append [value series]

>> append-value-first <item> [a b c]
== [a b c <item>]

As with other function derivations, there's a lot of benefit over writing func [value series] [append series value] !

First of all, it's nearly as fast as the original function. It adds a little overhead to do the rearrangement, but it places values in the same underlying frame slots...and introduces no new frame of its own.

You keep the HELP, parameter names, and well as keep the refinements:

>> append-value-first/dup <item> [a b c] 3
== [a b c <item> <item> <item>]

Usage Notes

You need to provide all the required arguments. It won't guess where you want parameters to go.

>> reorder :append [value]
** Script Error: append is missing its series argument

However... you can position optional arguments in the ordering if you like!

>> append-val-dup-ser: reorder :append [value dup series]

>> append-val-dup-ser <item> 3 [a b c]
== [a b c <item> <item> <item>]

As usual, I will plead for the submission of more tests:


I point out that this is based on a more foundational ability, to specify non-refinement arguments in paths...which pushes them to the end of the pending arguments:

>> append/series <item> [a b c]
== [a b c <item>]

REORDER gives you a more intuitive interface to it, but you can also do it that way if you feel like it!


Very cool tool to have in the box!