This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-04
Channels
- # aleph (8)
- # aws (14)
- # babashka (37)
- # beginners (30)
- # calva (5)
- # cider (4)
- # clj-kondo (21)
- # cljsrn (4)
- # clojure (234)
- # clojure-denmark (1)
- # clojure-europe (10)
- # clojure-france (10)
- # clojure-italy (4)
- # clojure-nl (17)
- # clojure-sanfrancisco (1)
- # clojure-spec (8)
- # clojure-uk (44)
- # clojurescript (20)
- # cursive (9)
- # datascript (2)
- # datomic (5)
- # emacs (9)
- # fulcro (50)
- # graalvm (32)
- # jackdaw (18)
- # leiningen (1)
- # malli (10)
- # meander (10)
- # nrepl (10)
- # off-topic (15)
- # pathom (20)
- # re-frame (14)
- # reagent (37)
- # reitit (7)
- # ring (1)
- # shadow-cljs (102)
- # test-check (6)
- # tree-sitter (15)
- # vim (4)
- # xtdb (2)
- # yada (1)
@tylertracey09 Datomic cloud could fit your usecase. Manged infrastructure if you desire it (or just run it locally to start), fits well with event sourcing and most of all fits well with Clojure.
Hi, is there a way I can apply doall
recursively? I would like to catch
any exceptions that may occur upon realizing the returned data from a function (letās call it f
. The problem is that f
might call other functions (which might call other functions etc.) returning lazy sequences which āescapeā my catch
.
Are you wanting something that works for one particular situation, or you are trying to handle an arbitrary return value that could be any kind of nested collection(s)?
For example, if you want to handle a case where f
always returns a sequence, and some of the elements might be lazy sequences, but nothing nested any further deeply than that you suspect is a lazy sequence you want to force, you could use (doall (map doall (f arg1 ...)))
If you want something that can handle lazy sequences nested arbitrarily deeply, but you know that all of them are in a short list of different types of collections, e.g. maps, sets, vectors, and/or sequences only, then you could look into something like (clojure.walk/postwalk doall (f arg1 ...))
Or actually not that, but replace doall
with a function that only calls doall
if the argument is not a vector, map, or set, since those are never lazy.
What would be the best predicate for that? Could I use something like:
(fn [x] (if (not (realized? x)) (doall x) x)
?@andy.fingerhut, thanks! I am indeed trying to handle an arbitrary return value. Will look at the postwalk solution later today,
What would be the best predicate for that? Could I use something like:
(fn [x] (if (not (realized? x)) (doall x) x)
?(dorun (tree-seq coll? seq x))
should realize recursively every lazy thing in x (edit - forgot some args)
postwalk uses that same coll?
condition but it also would recreate your structure which isn't strictly needed and might be a detriment
you know, (postwalk identity x)
would already realize the entire coll now that I think of it...
otherwise it couldn't fulfill it's behavioral contract
unless x contains a non-clojure object that in turn contains something lazy.... - but for the common case where you have layers of native clojure coll types it would get them
and due to the args I forgot, you could special case the types of containers you expect by replacing coll?
with a new predicate and seq
with a new extraction function
Hi folks - I have a lazy sequence of letters that Iām going to use for a regex matcher. Itās basically every combination of 13 letters (done with clojure.math.combinatorics) so:
(take 3 alpha-combo)
=>
(("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m")
("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "n")
("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "o"))
However, Iād like the output to look more like a regex, so I get something like:
(take 3 alpha-re)
=>
("[abcdefghijklm]" "[abcdefghijkln]" "[abcdefghijklo]")
Iām close, if I do it one at a time, like:
(apply str (first alpha-combo))
=> "abcdefghijklm"
Can someone help me over the last couple of hurdles? Thanks!Maybe looking at the above dorun
command, I think I can use thatā¦
maybe (map str (take 3 alpha-combo))
(map str (take 3 alpha-combo))
=> ("clojure.lang.LazySeq@1770d606" "clojure.lang.LazySeq@1770d607" "clojure.lang.LazySeq@1770d608")
ahh laziness
LOL yes, my enemy!
Oof, yes!!! map
!
map then take would work i think
That worked splendidly!
(def alphas
(map (fn [group] (str "[" (apply str group) "]")) alpha-combo))
=> #'further-testing.core/alphas
(take 5 alphas)
=> ("[abcdefghijklm]" "[abcdefghijkln]" "[abcdefghijklo]" "[abcdefghijklp]" "[abcdefghijklq]")
(map (partial apply str) ...)
oh you want the brackets, OK
Thanks @bfabry!