This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-17
Channels
- # admin-announcements (1)
- # aleph (1)
- # architecture (1)
- # bangalore-clj (14)
- # beginners (15)
- # boot (89)
- # braveandtrue (1)
- # cider (1)
- # cljs-dev (33)
- # cljsjs (1)
- # cljsrn (147)
- # clojure (149)
- # clojure-quebec (1)
- # clojure-russia (82)
- # clojure-spec (18)
- # clojure-taiwan (2)
- # clojure-uk (15)
- # clojurescript (97)
- # cursive (11)
- # datomic (22)
- # funcool (2)
- # hoplon (53)
- # immutant (16)
- # jobs-rus (8)
- # lambdaisland (1)
- # off-topic (13)
- # om (7)
- # onyx (58)
- # parinfer (6)
- # planck (19)
- # protorepl (2)
- # re-frame (17)
- # reagent (201)
- # rum (6)
- # specter (9)
- # test-check (68)
- # untangled (47)
- # yada (94)
I’m not sure if I should be using reduce
or if there’s a better function in Clojure for this: Say I have [1 3 6 10]
and want to calculate a new seq where each element is the result of a function of two adjacent elements in the input -> (foo - [1 3 6 10]) ;;=> [2 3 4]
.
Is there a foo
function that would do that? I guess I would need to push a vector through a reduce
otherwise?
Actually - (map #(apply - %) (partition 2 1 [1 3 6 10]))
seems to be what I need 🙂 (Except that my sample output is obviously wrong - it should be [-2 -3 -4]
).
@gnejs: You are correct. If you want to use reduce you could. Anything you can solve recursively you can solve with reduce.
is there a mapc
version of map
that is explicitly for side effects? Or do you just have to (doall (map .... ))
your mappings?