(attach-state {:keys [state initial file log] :as struct})used with component, adds watch on record that incorporates state
used with component, adds watch on record that incorporates state
(detach-state {:keys [state file log] :as struct})used with component, remove watch on record that incorporates state
used with component, remove watch on record that incorporates state
(file-out atom {:keys [transform] :as opts :or {transform identity}})adds watch to atom, saving its contents to file on every change
(def out-file (str (fs/create-tmpdir) "/test.txt"))
(swap! (file-out (atom 1) {:path out-file}) inc)
(read-string (slurp out-file)) => 2
adds watch to atom, saving its contents to file on every change
(def out-file (str (fs/create-tmpdir) "/test.txt"))
(swap! (file-out (atom 1) {:path out-file})
inc)
(read-string (slurp out-file))
=> 2(generate-basic-table rows)(generate-basic-table ks rows)generates a table for output
(generate-basic-table [:id :value] [{:id 1 :value "a"} {:id 2 :value "b"}])
=> (ascii ["| :id | :value |" "|-----+--------|" "| 1 | "a" |" "| 2 | "b" |"])
generates a table for output
(generate-basic-table [:id :value]
[{:id 1 :value "a"}
{:id 2 :value "b"}])
=> (ascii ["| :id | :value |"
"|-----+--------|"
"| 1 | \"a\" |"
"| 2 | \"b\" |"])(generate-single-table m {:keys [id-key headers sort-key] :as opts})generates a single table
(generate-single-table {"a@a.com" {:id 1 :value "a"} "b@b.com" {:id 2 :value "b"}} {:headers [:id :email :value] :sort-key :email :id-key :email}) => (ascii ["| :id | :email | :value |" "|-----+-----------+--------|" "| 1 | "a@a.com" | "a" |" "| 2 | "b@b.com" | "b" |"])
generates a single table
(generate-single-table {"a@a.com" {:id 1 :value "a"}
"b@b.com" {:id 2 :value "b"}}
{:headers [:id :email :value]
:sort-key :email
:id-key :email})
=> (ascii ["| :id | :email | :value |"
"|-----+-----------+--------|"
"| 1 | \"a@a.com\" | \"a\" |"
"| 2 | \"b@b.com\" | \"b\" |"])(log-out atom {:keys [transform] :as opts :or {transform identity}})adds watch to atom, logging the contents on every change
(with-out-str (swap! (log-out (atom 1) {}) inc))
adds watch to atom, logging the contents on every change
(with-out-str
(swap! (log-out (atom 1) {})
inc))(parse-basic-table s)reads a table from a string
(parse-basic-table (ascii ["| :id | :value |" "|-----+--------|" "| 1 | "a" |" "| 2 | "b" |"])) => {:headers [:id :value] :data [{:id 1 :value "a"} {:id 2 :value "b"}]}
reads a table from a string
(parse-basic-table (ascii
["| :id | :value |"
"|-----+--------|"
"| 1 | \"a\" |"
"| 2 | \"b\" |"]))
=> {:headers [:id :value]
:data [{:id 1 :value "a"}
{:id 2 :value "b"}]}(parse-single-table s {:keys [id-key] :as opts})generates a single table
(parse-single-table (ascii ["| :id | :email | :value |" "|-----+-----------+--------|" "| 1 | "a@a.com" | "a" |" "| 2 | "b@b.com" | "b" |"])
{:headers [:id :email :value] :sort-key :email :id-key :email}) => {"a@a.com" {:id 1 :value "a"} "b@b.com" {:id 2 :value "b"}}
generates a single table
(parse-single-table
(ascii ["| :id | :email | :value |"
"|-----+-----------+--------|"
"| 1 | \"a@a.com\" | \"a\" |"
"| 2 | \"b@b.com\" | \"b\" |"])
{:headers [:id :email :value]
:sort-key :email
:id-key :email})
=> {"a@a.com" {:id 1 :value "a"}
"b@b.com" {:id 2 :value "b"}}(read-table {:keys [path suffix headers levels sort-key id-key body?] :as opts})generates a single table
(read-table {:path "dev/scratch/test.db" :suffix "txt" :levels 1 :headers {:account [:id :email :value] :info [:id :name]} :sort-key {:info :name} :id-key {:account :email}}) => {:account {"a@a.com" {:id 1 :value "a"} "b@b.com" {:id 2 :value "b"}} :info {1 {:name "Chris"} 2 {:name "David"} 3 {:name "Cain"}}}
generates a single table
(read-table
{:path "dev/scratch/test.db"
:suffix "txt"
:levels 1
:headers {:account [:id :email :value]
:info [:id :name]}
:sort-key {:info :name}
:id-key {:account :email}})
=> {:account {"a@a.com" {:id 1 :value "a"}
"b@b.com" {:id 2 :value "b"}}
:info {1 {:name "Chris"}
2 {:name "David"}
3 {:name "Cain"}}}reads a value from a file
(read-value {:path "dev/scratch/test.db" :format :table}) => {:account {"a@a.com" {:id 1, :value "a"}, "b@b.com" {:id 2, :value "b"}}, :info {3 {:name "Cain"}, 1 {:name "Chris"}, 2 {:name "David"}}}
reads a value from a file
(read-value {:path "dev/scratch/test.db"
:format :table})
=> {:account {"a@a.com" {:id 1, :value "a"},
"b@b.com" {:id 2, :value "b"}},
:info {3 {:name "Cain"},
1 {:name "Chris"},
2 {:name "David"}}}(write-table data
{:keys [path suffix headers levels sort-key id-key body?]
:as opts})generates a single table
(write-table {:account {"a@a.com" {:id 1 :value "a"} "b@b.com" {:id 2 :value "b"}} :info {1 {:name "Chris"} 2 {:name "David"} 3 {:name "Cain"}}} {:path "dev/scratch/test.db" :suffix "txt" :levels 1 :headers {:account [:id :email :value] :info [:id :name]} :sort-key {:info :name} :id-key {:account :email}}) => {:account (ascii ["| :id | :email | :value |" "|-----+-----------+--------|" "| 1 | "a@a.com" | "a" |" "| 2 | "b@b.com" | "b" |"])
:info (ascii
["| :id | :name |"
"|-----+---------|"
"| 3 | \"Cain\" |"
"| 1 | \"Chris\" |"
"| 2 | \"David\" |"])}
generates a single table
(write-table
{:account {"a@a.com" {:id 1 :value "a"}
"b@b.com" {:id 2 :value "b"}}
:info {1 {:name "Chris"}
2 {:name "David"}
3 {:name "Cain"}}}
{:path "dev/scratch/test.db"
:suffix "txt"
:levels 1
:headers {:account [:id :email :value]
:info [:id :name]}
:sort-key {:info :name}
:id-key {:account :email}})
=> {:account (ascii
["| :id | :email | :value |"
"|-----+-----------+--------|"
"| 1 | \"a@a.com\" | \"a\" |"
"| 2 | \"b@b.com\" | \"b\" |"])
:info (ascii
["| :id | :name |"
"|-----+---------|"
"| 3 | \"Cain\" |"
"| 1 | \"Chris\" |"
"| 2 | \"David\" |"])}write a value to file
(write-value {:account {"a@a.com" {:id 1 :value "a"} "b@b.com" {:id 2 :value "b"}} :info {3 {:name "Cain"} 1 {:name "Chris"} 2 {:name "David"}}} {:path "dev/scratch/test.db" :format :table :suffix "txt" :levels 1 :headers {:account [:id :email :value] :info [:id :name]} :sort-key {:info :name} :id-key {:account :email}})
write a value to file
(write-value {:account {"a@a.com" {:id 1 :value "a"}
"b@b.com" {:id 2 :value "b"}}
:info {3 {:name "Cain"}
1 {:name "Chris"}
2 {:name "David"}}}
{:path "dev/scratch/test.db"
:format :table
:suffix "txt"
:levels 1
:headers {:account [:id :email :value]
:info [:id :name]}
:sort-key {:info :name}
:id-key {:account :email}})cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |