JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

in

core-api


    function

    (in x key &opt dflt)

    Get value in `x` at `key`. For bytes and indexed types, `key` must 
    be a non-negative integer in bounds or an error is raised. For 
    dictionaries `key` must be a non-nil value and if not found, will 
    return `dflt` if provided or `nil` otherwise.

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


4 examplesSign in to add an example
Loading...
(in :yo 0)
# => 121
sogaiuPlayground
(in "yo" 0)
# => 121
sogaiuPlayground
(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
(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     ]
cellularmitosisPlayground