This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-15
Channels
- # aleph (5)
- # bangalore-clj (1)
- # beginners (53)
- # boot (1)
- # cljs-dev (327)
- # cljsrn (3)
- # clojure (16)
- # clojure-filipino (47)
- # clojure-nlp (4)
- # clojure-russia (1)
- # clojure-spec (3)
- # clojurescript (64)
- # core-async (6)
- # datomic (25)
- # hoplon (5)
- # jobs (5)
- # klipse (2)
- # lein-figwheel (2)
- # lumo (27)
- # om (2)
- # onyx (6)
- # parinfer (4)
- # pedestal (1)
- # protorepl (1)
- # re-frame (31)
- # ring-swagger (1)
- # specter (9)
- # unrepl (11)
I have some utility functions i’d like to use in my cljs repl no matter what namespace i’m in. i defined them in cljs.user
. how do i make sure i can use them after switching to another namespace?
the least complex thing is to run (use 'cljs.user)
after switching namespaces - there's tools for jvm clojure that make certain definitions ubiquitous but honestly I think they are weird and they don't exist in cljs
s/tools/hacks/
really? interesting. thanks. i guess i can set up an emacs macro to enter that or something.
one of the things i find myself doing is all the time is (.keys js/Object lib)
. how do cljs devs explore libraries? i do .keys
, .-defaultProps
, and .-propTypes
, but i find myself typing the same stuff over and over.
hi, is there a way to act on the coll
itself when using reduce
? Like remove
elements from it?
@qle-guen If you want to remove stuff from a collection, you probably want to look at filter
Oh sorry, I misunderstood your question. Are you trying to implement remove
using reduce
?
not really... here's what I got so far: https://gist.github.com/qleguennec/d3f07cd9967c9a4b754c0a627dbc76fd
(ie (transduce prime-slieve-xf + 0 (range 2 10))
should output the sum of the primes from 2 to 9
nvm can't work because I need to remember all the old primes so I'll need to store them
it works with a hand-crafted stateful transducer, but it may not be a smart use case for transducers
CIDER has an explore namespace that you might like. I'm not sure that this is hooked up for cljs though. give that a shot
@dpsutton works in cljs namespaces! thanks. i see how underdocumented my code is…
curiously, doesn’t seem to work for cljsjs libraries. i require
cljsjs.d3
, but it isn’t picking it up.
i think the cljs brains of that are outside of the standard cider-nrepl middleware in a project called cljs-tooling
I have a question about core.async's go
. I know it returns a channel, but what if the body returns a channel? Does it wrap the channel in a channel, or does it do like JavaScript's async functions, which only wrap in a promise if the return value isn't a promise?
it does no automatic lifting - if the go block explicitly returns a channel, you get a channel that returns a channel
Okay, thanks.
I'm used to promises and async/await in JavaScript. It seems hard to do the same things in CLJS.
well - you can actually use those things from cljs
interop is easy, it's one of the good things about the language
Yeah. And I have promises extended to work as channels. It's just hard to wrap my head around how to write the similar things I write in JS, with regards to async/await.
yeah - CSP is its own thing with its own rules, but those rules actually have nice consequences
(if you use it right)
Specifically, I'm trying to make a function like this in CLJS:
const runShowPiece = async (client, msg, type, name, obj) => {
if (type === "command") await sendHelpMessage(client, msg, name);
return sendDebugMessage(client, msg, type, name, obj);
};
(Crap, I forget how code blocks work in Slack. I'm used to Discord)
This is what I have so far:
(defn run-show-piece [client msg type name obj]
(take-as-promise!
(go
(if (= type "command")
(<? (send-help-message client msg name)))
(send-debug-message client msg type name obj)))
(I'm using the cljs-promises library.) (Both of those functions still return promises.) If I do this, though, then the promise that send-debug-message
returns will be wrapped in a channel, which becomes a promise. I could use <?
to await it, as well, but then that makes the function not return until it finishes, right?Well, I guess the go
(wrapped in take-as-promise!
) would make the function return a promise right away, if I understand how that works
If anyone knows of any CLJS libraries that use promises a lot, that I could look at, that would probably help, to see what they do.
I'm a little confused about this kata on codewars: https://www.codewars.com/kata/55b3425df71c1201a800009c/train/clojure
My code isn't outputting the right answer, but even when I try to do it manually it doesn't come out right. How does codewars get the average of [15, 47, 17, 32, 17]
to equal 38? (first test case in bottom right code entry space).
that's just the minutes field
each one is hours/minutes/seconds encoding of a time
@noisesmith yes, but am I right that I'm supposed to take the average of the minutes field and put that in the middle of the result. So the result looks like Average: <average of hours>|<average of minutes>|<average of seconds>
or am I missing something? It's not making sense to me.
why would you average the fields instead of the times?
if I read it correctly, you need to break hh|mm|ss into a time value, average the time values, then convert back to hh|mm|ss
at least that seems like the only way the numbers would make sense