JanetDocsI'm feeling luckyGithub sign in

in



    function

    (in ds key &opt dflt)
    
    Get value in ds at key, works on associative data structures. Arrays,
    tuples, tables, structs, strings, symbols, and buffers are all
    associative and can be used. Arrays, tuples, strings, buffers, and
    symbols must use integer keys that are in bounds or an error is raised.
    Structs and tables can take any value as a key except nil and will
    return nil or dflt if not found.


2 examplesSign in to add an example
Loading...
(get      [4 5 6]   -1     )  # => nil
(in       [4 5 6]   -1  42 )  # error
(get-in   [4 5 6]  [-1] 42 )  # => 42

(get     {:a 1}   -1     )  # => nil
(in      {:a 1}   -1  42 )  # => 42
(get-in  {:a 1}  [-1] 42 )  # => 42
cellularmitosis
(in  [10 11 12 13]  0   42 )  # => 10
(in  {:a 10 :b 20}  :a  42 )  # => 10

(in  [10 11 12]  99 42 )  # error
(in  [10 11 12]  -1 42 )  # error
(in  [10 11 12]  -2 42 )  # error
(in  {:a 1}      :z 42 )  # => 42

(map  (fn [x] (in x 0 42))   [  'a  :a  "a"  [97]  @[97]  {0 97}  @{0 97}  {:a 1} ])
# =>                        @[  97  97  97   97    97     97      97       42     ]
cellularmitosis