JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

get

core-api


    function

    (get x key &opt dflt)

    Get the value mapped to `key` in `x`. Returns `dflt` or `nil` if 
    `key` is not found. Similar to `in`, but will not throw an error if 
    `key` is invalid for `x`. However, if `x` is an abstract type, its 
    getter may throw an error.

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


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

cellularmitosisPlayground
(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       ]
cellularmitosisPlayground