practicalli / practicalli/clojure

Applying a function to a nested map

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

Nobody has claimed this yet.

clojure-core maps and keys
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.