This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-27
Channels
- # bangalore-clj (1)
- # beginners (27)
- # boot (16)
- # cider (14)
- # cljs-dev (94)
- # cljsrn (8)
- # clojure (229)
- # clojure-dev (5)
- # clojure-dusseldorf (6)
- # clojure-italy (8)
- # clojure-norway (8)
- # clojure-russia (22)
- # clojure-sanfrancisco (2)
- # clojure-spec (48)
- # clojure-uk (44)
- # clojurescript (47)
- # core-async (87)
- # cursive (43)
- # datascript (22)
- # datomic (20)
- # defnpodcast (5)
- # emacs (6)
- # hoplon (4)
- # jobs-rus (4)
- # keechma (2)
- # klipse (8)
- # leiningen (2)
- # luminus (2)
- # lumo (14)
- # om (38)
- # onyx (4)
- # overtone (3)
- # pedestal (41)
- # planck (72)
- # powderkeg (42)
- # proton (46)
- # protorepl (9)
- # reagent (9)
- # ring (47)
- # ring-swagger (5)
- # rum (7)
- # sql (22)
- # unrepl (1)
- # untangled (24)
- # vim (19)
- # yada (5)
Hi all, just looking for a bit of clarification on sequential collections. I'm reading the Joy of Clojure, and it states they're ordered sets of values, and this link also confirms: http://insideclojure.org/2015/01/02/sequences/
The term ordered in this context, does it just mean that the order matters, whereas with something like a hashmap, the order doesn't matter?
Ace, thanks - thought so too, but would rather get confirmation than assume I've got it 🙂
Is it possible to do something like this (I know syntax here is wrong, but you get the idea): (def m {:x 3, :y 2, :z (+ :x :y)})
@jdeisenberg so z = 5?
Hello, if I have two arrays of integers and I want to take the greater of the two, but also have a condition say the max < 4 then to double the max, but only the first x times that max < 4, what would be the idiomatic way to express that? Do I have to use a recur or is there a way to accomplish that w/ map/reduce?
@jdeisenberg you can use a let
there
@tbaldridge The idea is I want to use a key that's already in the map to define something later on in the map. (Presume that instead of 2 and 3 I had some really long, complex expressions)
@greg_arcara you can do that in a reduce, although it gets a bit tricky. Basically have the accumulator of the reduce be a hashmap and update it as needed.
@tbaldridge Ah, of course! Why didn't I think of that?!:thinking_face:
@tbaldridge can I do the reduction with two arrays?
ah you have two arrays....
yea, that's my issue
I can do it with one 🙂
map
can take two seqs, so you can do: (map vector a b)
then either operate on the first
or second
of those elements
(map vector a b)
is zip
in Python (or some other languages you may know)
that's a good approach
@tbaldridge Still not sure how the code would look to get that value for :z
since I'd have to access the map currently being defined.
@tbaldridge thanks, I'll give this a go
@jdeisenberg you'd have to do this:
(def m (let [x 5 y 4]
{:x x :y y :z (+ x y)}))
@tbaldrige Got it; thanks.
(Sorry about the mistype on the name there)
@tbaldridge thanks so much for your help, I was able to make the solution work.