practicalli / practicalli/clojure
Applying a function to a nested map
Nobody has claimed this yet.
- Dominant language
- Makefile
- Stars
- 117
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
What’s the idiomatic way to map a function into a nested collection? For example, in Haskell I’d do:
The best I could come up with in clojure was:
(((comp #(partial map %) #(partial map %)) inc) [[1 2][3 4]])
but that seems pretty ugly
clojure.walk/ post-replace works on every value
clojure.walk/postwalk applies a function
(clojure.walk/postwalk
#(if (number? %)
(inc %)
%)
the-data)
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
Review the issue's nested collection example, the proposed comp/map expression, and the clojure.walk alternatives first. Done means documenting or linking an idiomatic Clojure approach for applying a function at the requested nesting level, while distinguishing it from applying the function to every value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100