diff --git a/README.md b/README.md index d7d8d48..edcf24d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,30 @@ -### Swark +# Swark SWiss ARmy Knife - Your everyday clojure toolbelt! https://clojars.org/org.clojars.stanv/swark +## Basic usage + +### Clojure CLI/deps.edn + +Add this dependency to the :deps map in deps.edn +`org.clojars.stanv/swark {:mvn/version "0.1.0"}` + +Require swark.core in your ns form: +`(:require [swark.core :as swark])` + +Then you can use the Swark utility functions: +`(swark/key-by :id [{:id 1 :name "one"} {:id 2 :name "two"}])` + +## Development + +Start a repl with `clojure -M:repl/reloaded` + +Create an uberjar with `clj -X:uberjar :jar swark-x.x.x.jar` (replacing x's with version) + +Install Swark locally with `clj -X:install` + +## License + Swark by Stan Verberkt is marked with CC0 1.0 Universal diff --git a/deps.edn b/deps.edn index 3f5401f..5a1d6ff 100644 --- a/deps.edn +++ b/deps.edn @@ -1,5 +1,22 @@ {:aliases - {:deploy + {:repl/reloaded + {:extra-deps {nrepl/nrepl {:mvn/version "1.0.0"} + cider/cider-nrepl {:mvn/version "0.28.7"} + com.bhauman/rebel-readline {:mvn/version "0.1.4"} + djblue/portal {:mvn/version "0.34.2"} + org.clojure/tools.namespace {:mvn/version "1.3.0"} + org.clojure/tools.deps.alpha {:git/url "https://github.com/clojure/tools.deps.alpha" + :git/sha "e4fb92eef724fa39e29b39cc2b1a850567d490dd"} + org.slf4j/slf4j-nop {:mvn/version "2.0.5"} + lambdaisland/kaocha {:mvn/version "1.71.1119"} + org.clojure/test.check {:mvn/version "1.1.1"} + ring/ring-mock {:mvn/version "0.4.0"}} + :main-opts ["-m" "nrepl.cmdline" + "--middleware" "[cider.nrepl/cider-middleware]" + "--interactive" + "-f" "rebel-readline.main/-main"]} + + :deploy {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.2"}} :exec-fn deps-deploy.deps-deploy/deploy :exec-args {:installer :remote diff --git a/src/swark/core.cljc b/src/swark/core.cljc index c20977a..d7a3a29 100644 --- a/src/swark/core.cljc +++ b/src/swark/core.cljc @@ -7,13 +7,15 @@ ;; Regarding collections (defn key-by - "Returns a map with all items in collection `coll` keyed by the value returned by `(f item)`" + "Returns a map with all items in collection `coll` keyed by the value returned by `(f item)` + When `(f item)` returns a falsey value, it is NOT included in the resulting map." [f coll] (when coll (-> f ifn? assert) (-> coll coll? assert) (->> coll (map (juxt f identity)) + (filter key) (into {})))) (comment @@ -21,6 +23,7 @@ (key-by nil [{:id 0 :name "ab"} {:id 1 :name "cd"}]) (key-by :id nil) (key-by (partial reduce +) [[1 1] [1 2] [2 3 5] [3 5 8 13]]) + (key-by :user/id [#:user{:id 12 :name "u12"} #:user{:id 23 :name "u23"} {:id 34 :name "not-included!"}]) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/uberjar.sh b/uberjar.sh deleted file mode 100644 index dd70be1..0000000 --- a/uberjar.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/bash - -clj -X:uberjar :jar swark-0.1.0.jar \ No newline at end of file