(arr)
array literals and array patterns (destructuring)
clojure
(arr elems?)Where:
- elems: element constraints to apply within the array (use
(el ...)to target position and/or value) *
Matching:
- array literals, e.g.
[a, b] - array patterns, e.g.
[a, b] = coords
Behavior
- Does not match Array constructor calls like
new Array(1, 2)orArray.from(...). - Use
(el)to constrain elements;(arr (el))only matches non-empty arrays.
Examples
Review arrays of allowed HTTP methods that include DELETE.
clojure
(arr (el _ (str "DELETE")))Selects in lines { 1, 3 } but not in { 2 }:
typescript
const methods1 = ["GET", "DELETE"]
const methods2 = ["GET", "POST"]
const methods3 = ["DELETE", "POST"]Find locale arrays that default to English so the default can be changed.
clojure
(arr (el 1 (str "en")))Selects in lines { 1, 3 } but not in { 2 }:
typescript
const locales1 = ["en", "fr"]
const locales2 = ["fr", "en"]
const locales3 = ["en", "es", "de"]Identify tuple route declarations [method, path, handler] for migration.
clojure
(arr (:and (el 1 (str /GET|POST|DELETE/)) (el 3 (fun))))Selects in lines { 2, 3 } but not in { 4, 5 }:
typescript
const routes = [
["GET", "/health", () => {}],
["POST", "/users", createUser],
["OPTIONS", "/users", options],
["GET", "/admin", admin, { auth: true }]
]Arguments
elems
• (el)
• (:into) • (:and) • (:or) • (:not) • (:text) • (:kind) • (:replace) • (:capture)