practicalli / practicalli/clojure
reduce and into
Nobody has claimed this yet.
- Dominant language
- Makefile
- Stars
- 117
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
Given a data structure, transform each map to use the :name value as the key and the :value as value
(def data
[{:name :isaac :value ["pencil", "pen"]}
{:name :brian :value ["eraser", "cat"]}])
(reduce
#(assoc %1 (:name %2) (:value %2)) {} data)
Output
{:isaac ["pencil" "pen"], :brian ["eraser" "cat"]}
Caveat:
If you have hash maps in the data that have the same value associated with :name then all successive keys you generate will overwrite previous ones.
Simplifiying the code using into and juxt
(into {} (map (juxt :name :value) input))
TODO: elaborate
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named in the issue. Start by locating the documentation entry for the reduce, into, and juxt example; expand the explanation and preserve the duplicate-:name caveat, with the finished example and output clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100