This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-03
Channels
- # aws-lambda (6)
- # beginners (38)
- # boot (39)
- # cider (44)
- # cljs-dev (9)
- # cljsrn (96)
- # clojure (142)
- # clojure-dev (6)
- # clojure-dusseldorf (8)
- # clojure-greece (45)
- # clojure-ireland (3)
- # clojure-italy (7)
- # clojure-norway (6)
- # clojure-russia (26)
- # clojure-sg (16)
- # clojure-spec (31)
- # clojure-uk (39)
- # clojurescript (125)
- # cursive (38)
- # datascript (4)
- # datomic (18)
- # emacs (34)
- # figwheel (2)
- # hoplon (3)
- # immutant (23)
- # jobs (1)
- # lambdaisland (2)
- # lumo (13)
- # off-topic (77)
- # om (8)
- # onyx (9)
- # pedestal (2)
- # play-clj (1)
- # re-frame (52)
- # reagent (3)
- # rum (4)
- # spacemacs (2)
- # specter (4)
- # unrepl (37)
- # untangled (8)
- # vim (79)
- # yada (1)
@danburton I would just check https://crossclj.info and see what yaml libs seem to used in projects you recognize or respect, and/or review the libraries available and pick one that suits your coding preferences
Hi, can anyone give a little help? I'm trying to figure it out how can I search for a nested value inside a list and I haven't done yet
I have the above list:
({:receivable-response {:identifier UX00126, :status 01, :message Recebivel já foi importado para o sistema}} {:receivable-response {:identifier UX00127, :status 00, :message Recebivel importado com sucesso}} {:receivable-response {:identifier UX00128, :status 00, :message Recebivel importado com sucesso}})
I've tried to use filter, but I could not realize how to access the nested status value
if the map is always in a list, and there's only ever one item in that list, you can just do (first processados)
before passing it to filter
oh, you have multiple maps in there. wrap your code in three backticks "`" to make it a code block
so, something like
(defn- mount-message
[processados]
(let [filtered (filter #(= (:status (:receivable-response %)) "01") processados)]
(println "filtered: " filtered)
))
untested ^^thanks! It worked this way:
(defn- mount-message
[processados]
(let {filtered (filter #(= (get-in % [:receivable-response :status]) "01") processados)]
(println "filtered: " filtered)
))
Calling all fellow Singaporean Clojurians, please search #clojure-sg to join Singapore Clojure slack channel, we have regular Singapore Clojure Meetup monthly, do come and join us.😀
I have a test utils namespace, that has a function that does some checks and uses is
. I want to use that function, but I want to write a test that checks that an assertion that should fail, does fail. Is there a way to do that, other than remove the is
call from the helper function?
Hmm, maybe I could use a dynamic var or something like that. If it is true, the helper function does the is
assertion. If not, it just does the checks and returns the result.
I know I've seen a library that had some enhanced testing tools, including an is-not macro, but I can't find it via google. I think it was in one of the big "useful utilities" libraries, rather than something specifically focused on testing.
personally, I just use (is (not ...)) 🙂
Does anyone have any experiences with hara: https://github.com/zcaudate/hara who would like to share?
I want to execute shell commands and receive there feedback when their done, but I can't get manifolds chain to recognize it. Do you now sources, where I can look at on this topic?
@danielgrosse how are you executing the shell commands ?
Actually i experimenting with conch from raynes
danielgrosse: my experience is that if what I want wasn’t directly offered by conch, it was easier to use ProcessBuilder and Process - eg. if I wanted to make an interactive process and read it’s stdout and send data to stdin, or run an async command and get its output later
the java apis for these is simpler than conch is
looks like conch returns a lazy-seq of output lines ? so you would need a thread to convert that to a stream (or deferred)
What's the reasoning for why (get-in {:foo {:bar "stuff"}} nil :not-found)
returns {:foo {:bar "stuff"}}
instead of :not-found
?
@carter.andrewj my guess: nil
is interpreted as an empty sequence of keys, so you get back the initial data structure
Is there a straightforward way of renaming a Leiningen project, or do I need to use some Cursive magic to do that?
@carter.andrewj that answer from @moxaj is correct. get-in
starts with the provided map, and keeps descending down through the nested maps until the sequence of keys has been exhausted. An empty seq is an “already exhausted” sequence of keys, so there is no more descent required, and the entire map is returned.
When dealing with long running timeout channels in Go
, to avoid memory leaks, I use the Stop() method to clean resources and to close the background goroutine, e.g:
c := make(chan bool,1)
t := time.NewTimer(time.Hour)
c <- true
// this select returns immediately (c has message inside)
select {
case <-c:
// handle message
case <-t.C:
// timeout
}
// stop the one-hour timer
t.Stop()
How can I mimic this behavior in core async, does the GC know how to clean timeout channels that aren't in use any more ?
(use 'clojure.core.async)
(def c (chan 1))
(>!! c true)
(alts!! [(timeout 100000000) c])
# what happen to the timeout channel ? its still running in the backgroud ?
Go blocks, are callbacks that are attached to channels. Channels are just queues + a few locks. All of that can be GC'd
so yes, in a round-about way it can all be GC'd
And here's a video that goes into way too much detail on the subject if you care to learn more 🙂 https://www.youtube.com/watch?v=VrwVc-saWLw
The name of project is not directly connected with the namespace. You can call the project foo, containing only namespace bar.
On the other hand, leiningen doesn't have anything to do with actual namespaces in clj files...
Ah, I didn’t know if there was some pattern-matching lein script I could run like lein rename
or something. Thanks.
@jtth you can try using clj-refactor: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-rename-file-or-dir
@tbaldridge I want more of those videos, I bought access to your ones on <https://tbaldridge.pivotshare.com> 🙂
you know if there is some function which does following:
(when (some-do
(operation-1)
(operation-2)
(operation-3))
(run-if-any-operation-returned-anything-else-than-nil))
I’m seeking for the some-do
-function@theikkila (when (or …) …)
that stops on the first truthy one of course
@theikkila if you want to run all the operations, and then only run another operation if any return nil
you could do (when (some nil? ((juxt opt1 opt2 opt3) <insert-val>)) (only-if-any-nil))
or some variation of things on that idea, don’t think there’s a built in function for this though 🙂
well actually all of those operation-*
-functions are side effects into database and the “after”-function is trigger if any of those had any results
otherwise juxt
would be perfect but I don’t have same arguments with every function
then presumably you know the functions at the time of writing this code? and you can just do something like:
(when (some (complement nil?)
[(fn1 <arg-list>)
(fn2 <arg-list>)
(fn3 <arg-list>)])
(my-only-if-something-not-nil-fn))
side note: (complement nil?)
might be the same as some?
some?
is equivalent to (complement nil?)
😄 most of my use cases don’t involve differentiating between is definitely not nil, but is some value (including false)
and it's falsey
, so I tend to forget about some?
I use EDN for simple things typically done at compile- or app start time, but recently migrated other runtime stuff to transit
it is able to exploit structural sharing as well
the main disadvantage IMO is that I kept writing the same pattern around a writer in JVM-land over and over again
I wonder how many times we’ve done this collectively, heh
fyi .toString
is str
the disadvantage is coordinating access if you use threads at all
I guess you skip the allocation cost?
but in a local scope you can reuse one for sure
I’d reuse in a let where it never escapes scope or enters another thread
eg. if you might have multiple transit messages coming on one stream and you are looping
which would make sense with eg. a websocket or kafka
@mkeathley one of the key reasons for Transit is that it's much faster than EDN, especially in CLJs.
And EDN really only has parsers for .NET, JVM and JS. The EDN readers in Python/Ruby are super buggy. But Cognitect maintains readers/writers for Transit on JS, Java, Clojure, CLJS, Python and Ruby. And transit libs exist for other platforms as well.
I haven't heard about anything like that from Cognitect, but the format is out there, and if you have a JSON parser for a platform, writing a transit impl probably takes 10-16 hours of dev work.
That was also a goal of Transit, make it simple to implement on new platforms.
thanks @tbaldridge that makes sense
hey, vim supports json now, I bet I could make a vim transit plugin
hi folks, I'm trying to get ring/piped-input-stream to actually stream text when i call .write
like this:
(response/response
(ring-io/piped-input-stream
#(let [w (io/make-writer % {:encoding "UTF-8"})]
(.write w "start\n" 0 4)
(Thread/sleep 1000)
(.write w "done\n")
(.flush w))))
which waits a full second and then prints
start
done
so it appears not to be streamingstreams created by http://clojure.java.io tend to be buffered
@hiredman hmm and wrapping this in a middleware that flushed the stream returned from piped-input-stream seems not to work either
e.g. if your data is smaller that some number of k, jetty won't send it until the stream is closed
the latest ring release has some support for async responses, I am not sure how that works with all the buffers, you might try that
and Pedestal...
But I agree with @hiredman ring doesn't handle streaming data very well, and doesn't handle async at all.
Immutant also has support for streaming on top of Ring
@tbaldridge As @hiredman just pointed out, apparently there is async support now in the latest Ring, though!
Yeah, but to be fair it's new, and it's basically callbacks chained together. While other solutions have been around for years.
And the way it's designed you have to write your middleware twice, or support two calling conventions 😐
Yeah, certainly not the most recommendable option as of yet 🙂
I see, that's too bad 😞
Pedestal was designed from the ground up with async in mind, so if you require a lot of asynchronous I/O that might be worth taking a look at.
Ring 1.6.0 supports asynchronous handlers, but not non-blocking I/O. However, it’s easier to go from a simple synchronous design to a performant asynchronous one with Ring.
Ring asynchronous handlers are made to be backward compatible, so you can transition when necessary.