practicalli / practicalli/clojure

clojure.core - into

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

Nobody has claimed this yet.

Dominant language
Makefile
Stars
117
Forks
36
PR merge metrics
No merged PRs in 30d

Description

f i want to conj a bunch of objects onto a vector in a map atom, and i have them in a list, is it better to write a (doseq [obj objects] (swap! v update :key conj obj) or something like (swap! v update :key #(apply conj % objects))?

that's a cumbersome way of saying: is it "better"/more idiomatic to do a bunch of swap!s or a single swap! with apply?

absolutely the latter
the former is N separate transactions (and someone else could be doing the same thing, interleaving the results)
👍
1

but really you'd probably be better off with (swap! v update :key into objects)
but be careful with the nil case - into uses a list in that case
I guess conj has the same problem (since into uses conj)
into will also automatically use transients if it can (like with vectors)

guard against the nil case with fnil like so: (swap! v update :key (fnil into []) objects), to make the type of the collection explicit.
Can easily swap out the vector in (fnil into []) for a #{} or {} depending on the type one wants.

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, test, or entry point is named. Start by reviewing the existing discussion and locating where this repository records Clojure usage guidance. Done means the question has a clear, documented recommendation that covers the collection type and nil behavior described in the thread.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.