JanetDocsPlaygroundI'm feeling luckyGitHub sign in

case



    macro
    boot.janet on line 202, column 1

    (case dispatch & pairs)

    Select the body that equals the dispatch value. When pairs has an 
    odd number of arguments, the last is the default expression. If no 
    match is found, returns nil.


See also:condmatch2 examplesSign in to add an example
Loading...
# Walk from the API is defined using a case 

(defn walk
  `Iterate over the values in ast and apply f
  to them. Collect the results in a data structure. If ast is not a
  table, struct, array, or tuple,
  returns form.`
  [f form]
  (case (type form)
    :table (walk-dict f form)
    :struct (table/to-struct (walk-dict f form))
    :array (walk-ind f form)
    :tuple (let [x (walk-ind f form)]
             (if (= :parens (tuple/type form))
               (tuple/slice x)
               (tuple/brackets ;x)))
    form))
pingiunPlayground
(defn output [x]
  (case x
    :a "a"
    "b"))

(output :a) # => "a"
(output "anything else") # => "b"
swlkrPlayground