practicalli / practicalli/clojure

reduce and into

Open
#67 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clojure-core
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.