Henrik Mikael Kristensen wrote:
> Interlacing blocks:
> 
> a: [a b c]
> b: [x y z]
> c: [1 2 3]
> 
> => d: [a x 1 b y 2 c z 3]
> 
> Is there a function to do this? I wrote my own, but was curious.

>> a: [a b c]
== [a b c]
>> b: [x y z]
== [x y z]
>> x: [1 2 3]
== [1 2 3]
>> d: interweave reduce [a b x]
== [a x 1 b y 2 c z 3]
>> source interweave
interweave: func [
    {Combines several series into one series by interweaving their values.}
    Block [block!]
    /Initial Interweaved [series! datatype!] /local Length Item][
    Length: 0
    foreach Series Block [
        Length: max Length length? Series
    ]
    Interweaved: any [
        all [
            datatype? Interweaved
            make Interweaved Length * length? Block
        ]
        Interweaved
        make block! Length * length? Block
    ]
    repeat Index Length [
        foreach Series Block [
            all [
                Item: pick Series Index
                insert/only tail Interweaved Item
            ]
        ]
    ]
    Interweaved
]
>>

I wrote my own too.

Andrew J Martin
Speaking in tongues and performing miracles.
ICQ: 26227169
http://www.rebol.it/Valley/
http://valley.orcon.net.nz/
http://Valley.150m.com/
-><-

-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to