thi-ng / umbrella

⛱ Broadly scoped ecosystem & mono-repository of 199 TypeScript projects (and ~180 examples) for general purpose, functional, data driven development
https://thi.ng
Apache License 2.0
3.35k stars 149 forks source link

[transducers] Add transjuxt #408

Open rostero1 opened 1 year ago

rostero1 commented 1 year ago

Add support for transjuxt that'd behave similar to:

(def data [{:name "pete" :supply 1}
           {:name "pete" :supply 2}
           {:name "john" :supply 2}
           {:name "sara" :supply 1}
           {:name "jane" :supply 2}
           {:name "sara" :supply 2}])

(x/transjuxt [(comp (map :name) (distinct) (x/sort) (x/into []))
              (comp (map :supply) (distinct) (x/sort) (x/into []))]
             data)

Discussed in https://github.com/thi-ng/umbrella/discussions/407

Originally posted by **rostero1** August 19, 2023 I have a dataset: ``` type Data = { id: number; name: string; supply: number }; type Results = Data[]; ``` How can I write a transducer that will give me`{ uniqNames: string[], uniqSupply: number[] }`, where names are all the uniq names and unique supply. I also need each result sorted both ascending.