JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

interleave

core-api


    function
    boot.janet on line 2044, column 1

    (interleave & xs)

    Returns an array of the values of each element of `xs`, 
    interleaved. If the elements of `xs` do not all have the same 
    number of values, the shortest element of `xs` determines the 
    number of values from each element of `xs` that are contained in 
    the returned array.

    Each element of `xs` can be a bytes, indexed, fiber, or abstract 
    type with suitable `get` and `next` methods.


3 examplesSign in to add an example
Loading...
(interleave [:a :b :c] [1 2 3]) 
# => @[:a 1 :b 2 :c 3]

(interleave [:a :b :c] (range 3)) 
# => @[:a 0 :b 1 :c 2]

(interleave [:a :b :c] (range 2)) 
# => @[:a 0 :b 1]

(struct ;(interleave [:a :b :c] [1 2 3]))
# {:c 3 :a 1 :b 2}

(table ;(interleave [:a :b :c] [1 2 3]))
# @{:c 3 :a 1 :b 2}
leobmPlayground
# excess elements of the longer list are discarded
(interleave [1] 
            [2 4] 
            [3 6])
# -> @[1 2 3]
KrasjetPlayground
(interleave [:a :b :c] 
            [1 2 3] 
            ["x" "y" "z"])
# => @[:a 1 "x" :b 2 "y" :c 3 "z"]
sogaiuPlayground