Skip to content

davesann/let-map

Repository files navigation

let-map

Status

example workflow

Why?

Abbreviation of constructs where you let vars and then want to create a map.

(let [a 1
      b (inc a)]
  {:a a
   :b b}

Usage

namespace: let-map

(require '[dsann.let-map :refer [let-map])

(let-map
  a 1
  b (inc a)
  ...)

=> {:a 1 :b 2}

namespace: let-map2

let-map2 should be preferred because the syntax is closer to let. It also adds additional features: namespaced keywords and value filtering (particularly nils)

(require '[dsann.let-map2 :refer [let-map])

(let-map
  [a 1
   b (inc a)
   ...])

=> {:a 1 :b 2}

refer to dsann.let-map2-test for examples

Deps

io.github.davesann/let-map {:git/tag "v9" :git/sha "d0f023e"}

if you want to list all versions

git show-ref --tags --abbrev

Supported dialects

  • clj
  • cljs
  • bb

Features

  • Names that start _ are removed from the final map
    • Useful for intermediate values
  • Destructuring works
  • Refer to tests for examples: let-map tests
  • since v8:
    • The input map type will be retained when using assoc versions
    • If you want to let-map a specific map type then (let-assoc (my-map-type) a 1 ...)

Variants in namespace: let-map

  • let-assoc:
    • like let-map but add to a provided map
  • sym-map:
    • create a map from a list of symbols. Keys will be the symbol names
  • assoc-syms
    • like sym-map but add to a provided map

Variants in namespace: let-map2

  • let-assoc:
    • like let-map but add to a provided map
  • sym-map:
    • create a map from a list of symbols. Keys will be the symbol names
  • assoc-syms
    • like sym-map but add to a provided map

namespaced keywords

all variants that end in -ns create namespaced keywords

  • let-map-ns
  • let-assoc-ns
  • sym-map-ns
  • assoc-syms-ns

value filtering variants

all variants that end in a '-' filter based on values. the default is to filter nils.

  • let-map-

  • let-assoc-

  • sym-map-

  • assoc-syms-

  • let-map-ns-

  • let-assoc-ns-

  • sym-map-ns-

  • assoc-syms-ns-

Examples

See namespaces:

Other

clj-kondo

if using clj-kondo and you are seeing unresolved-symbol errors

  1. Ensure there is a .clj-kondo directory in your project
  2. Then run the following command to copy configs to exclude these errors
clj-kondo --lint "$(clojure -Spath)" --copy-configs --skip-lint

About

let like syntax to create maps

Resources

License

Stars

Watchers

Forks

Packages

No packages published