split: chunk: segment: func [ ; subdivide ?
{See: CLOS pg. 937. Not that mine works the same, but that was
the inspiration.}
series [series!]
size [integer!] "The size of the chunks (last chunk may be shorter)"
/into "split into a set number (size) of chunks (last chunk may be longer than others)."
/local ct cur-piece result
][
ct: either into [size] [round/down divide length? series size]
if into [size: to-integer divide length? series size]
result: copy []
if zero? size [return result]
parse series [
ct [
copy cur-piece size skip (append/only result cur-piece) mark:
]
]
if any [into not zero? remainder length? series size] [
cur-piece: copy mark
either into
[append last result cur-piece]
[append/only result cur-piece]
]
result
]
You need to create an account or log in to post comments to this site.