JanetDocsI'm feeling luckyGithub sign in

get



    function

    (get ds key &opt dflt)
    
    Get the value mapped to key in data structure ds, and return dflt or
    nil if not found. Similar to in, but will not throw an error if the key
    is invalid for the data structure unless the data structure is an
    abstract type. In that case, the abstract type getter may throw an
    error.


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
(get  [10 11 12 13]  0  )  # => 10
(get  {:a 10 :b 20}  :a )  # => 10

(get  [10 11 12]  99  )  # => nil
(get  [10 11 12]  -1  )  # => nil
(get  [10 11 12]  -2  )  # => nil
(get  {:a 1}      :z  )  # => nil

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