Skip to content

Commit

Permalink
Added a method that creates a transduce-compatible rf - mapseq-rf
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Dec 10, 2022
1 parent d6acf67 commit 820661d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/tech/v3/dataset.clj
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,14 @@ _unnamed [5 4]:
(tech.v3.dataset.readers/mapseq-reader dataset)))


(defn mapseq-rf
"Create a transduce-compatible rf that reduces a sequence of maps into a dataset"
([]
(tech.v3.dataset-api/mapseq-rf ))
([options]
(tech.v3.dataset-api/mapseq-rf options)))


(defn min-n-by-column
"Find the minimum N entries (unsorted) by column. Resulting data will be indexed in
original order. If you want a sorted order then sort the result.
Expand Down
2 changes: 1 addition & 1 deletion src/tech/v3/dataset/metamorph_api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

(def ^:private excludes-dataset
'#{bind-> all-descriptive-stats-names major-version ->dataset ->>dataset column-map-m
mapseq-parser})
mapseq-parser mapseq-rf})



Expand Down
16 changes: 16 additions & 0 deletions src/tech/v3/dataset_api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ _unnamed [5 4]:
([] (mapseq-parser nil)))


(defn mapseq-rf
"Create a transduce-compatible rf that reduces a sequence of maps into a dataset.
Same options as [[->dataset]].
```clojure
user> (transduce (map identity) (ds/mapseq-rf {:dataset-name :transduced}) [{:a 1 :b 2}])
:transduced [1 2]:
| :a | :b |
|---:|---:|
| 1 | 2 |
```"
([] (mapseq-rf nil))
([options] (-> (io-mapseq/mapseq-reducer options) (hamf/reducer->rf))))



(defmacro bind->
"Threads like `->` but binds name to expr like `as->`:
Expand Down

0 comments on commit 820661d

Please sign in to comment.