This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-28
Channels
- # aleph (48)
- # announcements (3)
- # bangalore-clj (1)
- # beginners (131)
- # cider (30)
- # cljdoc (6)
- # cljs-dev (53)
- # cljsrn (24)
- # clojure (312)
- # clojure-austin (2)
- # clojure-europe (4)
- # clojure-finland (6)
- # clojure-nl (24)
- # clojure-spec (24)
- # clojure-uk (66)
- # clojurescript (185)
- # core-async (46)
- # cursive (10)
- # data-science (9)
- # datomic (15)
- # devcards (2)
- # emacs (50)
- # fulcro (28)
- # jobs (1)
- # jobs-discuss (2)
- # kaocha (11)
- # lein-figwheel (12)
- # nyc (1)
- # off-topic (105)
- # other-languages (80)
- # pedestal (6)
- # re-frame (50)
- # reagent (5)
- # reitit (1)
- # remote-jobs (2)
- # ring (10)
- # rum (1)
- # shadow-cljs (10)
- # spacemacs (19)
what's an idiomatic way of abstracting over a value that could be either a map or a set?
@qythium Perhaps convert the set to a hash map (where you don't care about the values)?
I would be suspicious of a function that could accept both a set and a hash map -- that suggests there's something wrong with the abstractions being used in the program perhaps?
user=> (let [s #{:a :b :c :f :h}] (zipmap s s)) ; no need for this (into {} (map vector s s))
{:c :c, :h :h, :b :b, :f :f, :a :a}
Then contains?
and dissoc
do what you need and adding to the "set" becomes (assoc s v v)
(and if you need to get a set back, (into #{} (keys s))
where s
is your hash map "set")
Thanks, I was actually "broadening" the type of an object from a set to a map, to account for cases where I would need an optional "label" for a key
and wondering if there was a way to do so without having to go around and refactor all the function calls
Yes, that would be simpler. My bad.
thanks 🙂 I suppose the order of sequencing s
is guaranteed to be the same for both arguments of zipmap, even though it's unordered
Hello all, I want to do something like this: - Having a big list/vector/something else ... with (it´s a list of ips) - Having like n 'consumers' that will "consume" the element of this list in thread, not more than n running at the same time Is that possible? How can I limit the n running thread function at the same time?
Queue + worker pool
= Java executor
Hi. I was expecting to get "hola" everywhere. Is there something about map that ignores the binding?
Interestingly enough, if I use pmap
instead it works.
Interestingly enough, if I use pmap
instead it works.
map is lazy, so it returns a lazy seq of pending calls to f
you are forcing those calls in printing the result returned from the binding (after the binding has been popped)
pmap is sending those calls off in binding scope and then lazily looking at the results
many ways to alter behavior here, but changing map
to mapv
would make it eager
for a side-effecting thing like this, usually run!
is preferred to map
(defn hrm []
(prn "M" *xxx*)
(run! f [1 2 3]))
Ah, thanks. Forgot about the laziness of map 🙂 I'll go with mapv as my actual code does other things.
that's also sufficient to fix this. returns nil instead, rather than (nil nil nil)
or wrap a doall
around the map call
Is there a simpler way to do the following?
dev=> (join "." (filter some? ["a" nil]))
"a"
dev=> (join "." (filter some? ["a" "b"]))
"a.b"
I would thread that
perhaps it could be clearer with (filter string?)
@robertfrederickwarner
unless you can keep nils out higher up or make sure only strings end up. then you can filter str/blank?
`(join "." (keep some? coll))` ? - incorrect
The second value is coming out of an associative destructuring, so I could set a default for that to be ""
but keep is like map - it transforms the elements (often you can avoid needing a filter identity
by using keep
instead of map
)
nothing beats (remove nil?)
when your goal is to remove nils imo
it's like literally the same words :)
vars that refer to functions can be invoked and will invoke the function they refer to
Thanks 🙂 I was wondering if that was the more canonical options, b/c people have presented it as something of a hack
I believe it's a fine thing to do :)
go forth and test thy private functions :)
you can just use filter
and reject keys not matching your regex, right?
What is your function, and what concerns do you have?
I was using a vector of keys to pull out from a function response. The thing is that sometimes the keys are representations of many keys and I need to somehow distinguish from a regular key to multiple keys. All this complexity seems unnecessary to me but after asking its suppose to enforce that those keys get removed at another point in the system.
So re date-times, if you have an inst in clojure that is particularly long ago, like #inst "0001-01-01"
. If you convert that to an Instant
, you get a particular strange representation of “0000-12-30T00:00:00Z”. I guess that sense because of shifts in calendar systems between now and thousands of years ago, but what is the inst
actually representing, where is this difference in presentation coming from
abstractly true, but if you literally type #inst ..., you'll get a java.util.Date and that's kind of baked in
so you could rephrase as, if I have a java.util.Date representing some very old instant, and format it with "whatever inst uses", why does it present in this way?
getting Clojure mostly out of the way to leave you with a Java question
off the top of my head, I have no idea
when you say "convert that to an Instant" that is almost certainly where the difference is introduced
yeah, that would be my question too
.toInstant()?
yeah, toInstant does this indeed
Date.toInstant()
does Instant.ofEpochMilli(getTime())
where "getTime()" is just long millis since the beginning of 1970 (when all time began)
right, so they are both the same value so to say, but they are shown differently
they have the same number of milliseconds since epoch
I don’t feel like I am posing a coherent question, sorry!
I did read something strange about switching of calendar systems
Try for example (.toInstant #inst "1500-01-01")
no you get 1500-01-10
(note the 10)
right, I ninja’edited: (.toInstant #inst "1500-01-01")
date and time is weird
and majorly confusing
right, but it gets extra confusing when the one API requires new style java.time.*
objects, and the other old style java.util.*
objects
In such a way that I can’t get my head around it anymore
There was about 200 years where Catholic European countries adopted the Gregorian calendar, which when adopted suddenly jumped the calendar 10 days forward, whereas Protestant countries resisted the change. Neighboring countries official calendars were off of each other by 10 days for all of that time.
right, so this date in 1500, which is pre the switch to Gregorian is printing correctly if you take into account the switch in calendar systems
prob a leap day kind of thing somewhere I'd guess
but i think this is a timezone thing maybe?
Clojure 1.10.0
user=> #inst "0001-01-01"
#inst "0001-01-01T00:00:00.000-00:00"
user=>
I don't think I'd rely much on the Instant object toString() you're seeing in there
Okay, not my most coherent question, thanks for thinking along…
You’re not going to get year 0 you shouldn’t be getting year 0, b/c year 0 does not exist (if you use the AD/BC aka CE/BCE)
…except in ISO when it is, turns out. https://en.wikipedia.org/wiki/Year_zero#ISO_8601 Calendars in the deep past are worse than handling summer/winter time and leap years 🙂
That’s quite interesting, thanks
I feel like I have this half grasp of what is happening with jumps in calendars
It’s just very confusing
Yes, and it seems that java.util.Date just ignores that fact
Or at least in its toString
some holidays look weird now, but they used to fall on solar dates, St Lucy used to be winter solstice
there’s a GregorianCalendar and more recently JulianFields in java itself… but it’s been long since I did something with the language so I’d advise checking for the current recommended method somewhere more official 🙂
I was reading in wiki that any year divisible by 4 is the leap year on Gregorian Calendar?
any time you think you know something about dates, you don’t know something about dates