JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

get-in

core-api


    function
    boot.janet on line 1820, column 1

    (get-in x ks &opt dflt)

    Use the keys `ks` to look up a nested value in `x`. If a value is 
    not found, will return `dflt` if provided, or `nil` otherwise.

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

    `ks` can be an indexed or abstract type with `get` and `next` 
    methods.


3 examplesSign in to add an example
Loading...
(get-in  {:a {:cc 2} :b {:dd 3}}  [:a]     42)  # => {:cc 2}
(get-in  {:a {:cc 2} :b {:dd 3}}  [:a :cc] 42)  # => 2

(get-in  {:a {:cc 2} :b {:dd 3}}  [0]  42)  # => 42
(get-in  {:a {:cc 2} :b {:dd 3}}  [:z] 42)  # => 42
cellularmitosisPlayground
(get-in  [[4 5] [6 7]]  [0]    42)  # => (4 5)
(get-in  [[4 5] [6 7]]  [0 1]  42)  # => 5

(get-in  [[4 5] [6 7]]  [-1]     42)  # => 42
(get-in  [[4 5] [6 7]]  [9 9 9]  42)  # => 42
cellularmitosisPlayground
(def request {:params {:id 1}}) # => {:params {:id 1}}

(get-in request [:params :id]) # => 1

(get-in request [:params :name]) # => nil

(get-in request [:params :name] "N/A") # => "N/A"
inchingforwardPlayground