This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-31
Channels
- # announcements (7)
- # asami (2)
- # babashka (47)
- # beginners (8)
- # calva (42)
- # clj-kondo (58)
- # cljdoc (1)
- # clojure (88)
- # clojure-europe (11)
- # clojurescript (6)
- # conjure (7)
- # data-science (5)
- # emacs (9)
- # events (1)
- # holy-lambda (3)
- # introduce-yourself (5)
- # meander (3)
- # missionary (4)
- # nbb (18)
- # obb (5)
- # off-topic (1)
- # other-languages (10)
- # pathom (2)
- # reagent (6)
- # releases (3)
- # ring (3)
- # scittle (1)
- # shadow-cljs (1)
- # spacemacs (2)
- # xtdb (6)
If I'm trying to map over a range, and build up a single string with the result, is that the job of a reduce?
Maybe take a look at reductions
too: https://clojuredocs.org/clojure.core/reductions
Can you write the exact problem and expected result?
(apply str (map generate-string-with-number (range start end -1)))
is what I ended up with
I think the best solution is ->>
map
, clojure.string/join
:
(->> (range 10 5 -1)
(map #(str "I am string number " % "."))
(s/join " "))
You can do something like that with reduce
, if you don't mind missing space between sentences (or there will be one unwanted space):
(->> (range 10 5 -1)
(reduce #(str %1 "I am string number " %2 ".") ""))
And one more with clojure.pprint/cl-format
:
(pp/cl-format nil "~{I am string number ~a.~^ ~}" (range 10 5 -1))