JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

next

core-api


    function

    (next x &opt key)

    Gets the next key in `x`. Can be used to iterate through the keys 
    of `x` in an unspecified order. Keys are guaranteed to be seen only 
    once per iteration if `x` is not mutated during iteration. If `key` 
    is `nil`, returns the first key. If `nil` is returned, there are no 
    more keys to iterate through.

    `x` can be a bytes, indexed, dictionary, fiber, or abstract type 
    with a suitable `next` method.


1 exampleSign in to add an example
Loading...
(next  [4 5 6]    )  # => 0
(next  [4 5 6]  0 )  # => 1
(next  [4 5 6]  1 )  # => 2
(next  [4 5 6]  2 )  # => nil

# note that dictionary keys are not necessarily in the same order
# as the corresponding literal.
(next  {:a 5 :b 6 :c 7}     )  # => :a
(next  {:a 5 :b 6 :c 7}  :a )  # => :c
(next  {:a 5 :b 6 :c 7}  :c )  # => :b
(next  {:a 5 :b 6 :c 7}  :b )  # => nil
cellularmitosisPlayground