This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-27
Channels
- # bangalore-clj (2)
- # beginners (37)
- # boot (16)
- # cider (17)
- # clara (4)
- # cljs-dev (351)
- # cljsrn (16)
- # clojure (219)
- # clojure-belgium (4)
- # clojure-dev (3)
- # clojure-france (2)
- # clojure-italy (24)
- # clojure-russia (23)
- # clojure-spec (55)
- # clojure-switzerland (3)
- # clojure-uk (89)
- # clojurescript (121)
- # cursive (2)
- # datomic (29)
- # devops (2)
- # graphql (8)
- # hoplon (15)
- # immutant (5)
- # lein-figwheel (4)
- # liberator (3)
- # luminus (18)
- # off-topic (9)
- # om (6)
- # onyx (31)
- # pedestal (48)
- # precept (9)
- # re-frame (19)
- # reagent (63)
- # ring-swagger (69)
- # robots (1)
- # slack-help (14)
- # spacemacs (12)
- # sql (2)
- # test-check (4)
- # unrepl (28)
- # untangled (5)
- # yada (3)
@maleghast I just looked it up on the map.... just one word... WOW!!!
Anyone here watched Collateral Beauty? Saw it last night. I thought it was really good (bit of a tear jerker)
@thomas - Yep; I am a lucky bugger (who pays for it by travelling a LOT, but I am not even CLOSE to complaining 😉 )
Does anyone have a neat way of creating a map from a vector of keys where all the values are nil..? I've already figured out that (zipmap coll emptycoll) returns an empty map 😞
constantly
-> repeat
?
Sadly that does not work, though I feel as though it should. I get the following error:
java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.core$constantly$fn__6693
try repeatedly then https://clojuredocs.org/clojure.core/repeatedly
Will do - and no need for an apology; I asked 'cos I was stumped, any input is good 🙂
OK, @otfrom, sadly "repeatedly" does not work, but this train of thought brought me to this, which does:
what @shan and @peterwestmacott said
@glenjamin - It's interesting, however, as it shows me another way of thinking about things... 🙂
I have never really spent the time to grok "for" properly, and this is another timely reminder that I should pay it more attention.
@maleghast I tend not to use for a lot either.
for
is really handy, although I prefer the elegance and composability of zipmap
. Sometimes for
has tendency to use temporary names that lack meaning, like k
. To me that make the code feel a little less elegant than using zipmap
.
@maleghast there is a nice video on list comprehension at https://www.youtube.com/watch?v=5lvV9ICwaMo
I never used to use for
much, but someone on IRC used to use it in answers a lot and then i got the hang of it
once I started thinking “for = list comprehension” instead of “for = loop”, i found it easier
for
can be quite useful with :let
and :when
to avoid a separate map
and filter
often you can write it quite reasonably either way, and it’s a question of preference
I get frustrated when I want mapcat
, but I also want to use for
, it's very conflicting 😞
dominicm: is that with cat
as xform
?
I have a forcat
in my utils ns for that
@peterwestmacott Is your forcat
lazy? I'm trying to write one, and can't figure out how to make it lazy.
I think it should be.
(defmacro forcat [seq-exprs body-expr]
`(apply concat (for ~seq-exprs ~body-expr)))
from memory I looked at mapcat
and did what that did
;; Doesn't print things until it's realized.
(def xs (map identity (repeatedly 10 #(do (prn "foo") (range 10)))))
;; Prints things
(def xs (mapcat identity (repeatedly 10 #(do (prn "foo") (range 10)))))
(defmacro forcat [for-args]
`(apply concat (for ~@for-args)))
should work as well as a concat & for.concat is pseudo lazy. It has some mixed reviews. I've been trying to work around them with things like (sequence cat)
& such, but I've no idea if cat
fixes many of the issues with concat
I tried that as well
(defmacro forcat
[seq-exprs body-expr]
`(apply sequence cat (for ~seq-exprs ~body-expr)))
But it seems to exhibit the same non-lazy behavior.https://stuartsierra.com/2015/04/26/clojure-donts-concat makes me scared of concat anyway 🙂
It was a good series of do’s/don’ts. Pity he stopped writing them.
dont stop using clojure, thats my favorite 🙂
@madstap the issue you're seeing with laziness & mapcat+apply is known and a combination of https://dev.clojure.org/jira/browse/CLJ-1218 and https://dev.clojure.org/jira/browse/CLJ-1583
Oh, I think I'm hugely confused about something. Maybe apply. If I apply a sequence to concat, it has to realize the sequence right? Or no?
it can force more elements than needed (see CLJ-1583) but it will never force the whole seq
if you care leave a comment/vote on the ticket & alex will eventually take a look at it
otherwise it's just a matter of waiting a few (more) years and eventually it will get applied