SWiss ARmy Knife - Your everyday clojure toolbelt!
This library contains functionality that you might need every single day as a happy clojure(script) developer.
The aim is to provide composable functions that you can use everyday, but are just not as trivial as (some (comp #{42} :answer) answers).
Most functionality should work in both Clojure and Clojurescript.
Add this dependency to the :deps map in deps.edn:
org.clojars.stanv/swark {:mvn/version "0.1.52"}
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} {:id 2}]) => {1 {:id 1} 2 {:id 2}}
(swark/map-vals count {:a [:b :c] :d [:e]}) => {:a 2 :d 1}
(swark/jab / 10 0) => nil
key-by: Returns a map where all items are keyed by the result of calling (f item)map-vals: Returns a map where f is applied to all the input map's values.filter-keys: Returns a map containing only the map-entries whose key returns logical true when supplied to a predicate fn.select-namespaced: Returns a map containing only those map-entries whose key's namespace is equal to the supplied namespace.jab: Try and fail silently, returning nil when any kind of error or exception is thrown.->str: Returns input coerced to a (trimmed) string. Support (namesapced) keywords etc.unid: Return a unique id string.->keyword: Returns input coerced to a keyword, replacing whitespace with dashes.invalid-map?: Minimalistic spec checker, returns logical true if the input does not respect the spec-map. Spec map is simply a map with predicates as vals.valid-map?: Complement of invalid-map?memoir: Like memoize, but with flushing. Flush the complete cache, or specific parts.
Atomic authorization. Generate a token for a map, in conjunction with a password and optional secret. And of course check if it matches.
with-token: Returns a map item with a hashed token in it's metadata.check: Checks the password (and optional secret) given a map item.disclose: Returns map item with it's token associated with ::authom/token. Useful for serializing the hashed token.conceal: Returns the map item with it's token moved to it's metadata. Useful for parsing a persisted record.
atomic: Returns a map with in- and output async channels to provide atomic interactions for side-effecting functionality.put!: Puts an instruction on the atomic's input channel, blocks and returns the response.close!: Closes the atomic's channels and stops the internal go-loop.
Run the tests with clojure -X:test/run
Start a repl simply by running clojure -M:repl/basic command in your terminal.
You can connect your editor via nrepl afterwards, e.g. from emacs; cider-connect-clj
Or create a repl from your editor, e.g. from emacs; cider-jack-in-clj
Create an uberjar with clj -X:uberjar :jar swark-0.1.52.jar
Install Swark locally with clj -X:install
env CLOJARS_USERNAME=username CLOJARS_PASSWORD=clojars-token clj -X:deploy
Swark by Stan Verberkt is marked with CC0 1.0 Universal