This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-13
Channels
- # babashka (10)
- # beginners (27)
- # calva (91)
- # cestmeetup (3)
- # cider (27)
- # clj-kondo (12)
- # cljs-dev (4)
- # clojars (13)
- # clojure (35)
- # clojure-europe (30)
- # clojure-france (3)
- # clojure-houston (1)
- # clojure-nl (11)
- # clojure-norway (29)
- # clojure-spec (23)
- # clojure-sweden (5)
- # clojure-uk (128)
- # clojurescript (69)
- # conjure (44)
- # core-async (27)
- # cursive (13)
- # emacs (9)
- # events (3)
- # fulcro (52)
- # graphql (4)
- # jobs (2)
- # jobs-discuss (46)
- # kaocha (4)
- # luminus (12)
- # nrepl (10)
- # off-topic (29)
- # re-frame (17)
- # reitit (20)
- # remote-jobs (4)
- # rewrite-clj (1)
- # ring (4)
- # rum (13)
- # shadow-cljs (40)
- # sql (1)
- # xtdb (1)
What’s an idiomatic way to pass a map to a function that receives keys and values without the wrapping curly braces? For instance,
(defn do-great-stuff [& {:keys [price time}]
...)
And I have the info in a map
(def the-deal {:price 1000 :time 1})
How do I call do-great-stuff
with the-deal
?
I can make it with:
(apply my-keys (apply concat the-deal))
Is there a better way?I am looking for a solution that doesn’t mention explicitly the keys :price
and :time
@vlaaad why do you think it’s better?
What do you mean?
Anyway, currently this is the way to pass a map to a kwarg function. There are rumors it might be supported out of the box in the future by language itself
Good point
Where did you hear the rumors?
Here's a little discussion on apply concat
and mapcat identity
. https://stuartsierra.com/2019/09/25/sequences-in-flatland
Thanks for the info
Hi! I came into this one on twitter
user> (reduce + ["1" "2" "3"])
java.lang.String cannot be cast to java.lang.Number
user> (reduce + ["1"])
"1"
I thought it was because of the +
implementation when it receives just one parameter
([x] (cast Number x))
but then I tried
user=> (+ "3")
Execution error (ClassCastException) at java.lang.Class/cast (Class.java:3369).
Cannot cast java.lang.String to java.lang.Number
I was sure that the last one was not going to return an integer,
And now i’m confused 😅
Can someone explain me, why that behavior in the reduce?? (sorry about my english), thanks in advanceFrom the reduce
docstring: "if coll has only 1 item, it is returned and f is not called."
Also worth noting is that behavior only applies when there is no initialization argument.
So if you start with an empty string: (reduce + "" ["1" "2" "3"])
then it would fail because the first call would be to: (+ "" "1")
Ghadi’s comment about +
is important. It’s easy to mix it up because of Java and JavaScript! But you were looking for str
OK… so now I have a TIL as well! This made me wonder, because I know that ClojureScript uses JavaScript’s + operator
cljs.user=> (+ "" "1")
WARNING: cljs.core/+, all arguments must be numbers, got [string string] instead at line 1 <cljs repl>
"1"
thanks for the feedback @U083D6HK9, @U050ECB92, @U051N6TTC
Also worth mentioning this case:
user=> (reduce + "" [])
""
If you specify an init
value and an empty collection, the init
value is returned and f
is not called then either.yes, I understand that, I just considered it was a weird behavior in the reduce, and like @U083D6HK9 told me in the other thread: from the `reduce` docstring: “if coll has only 1 item, it is returned and f is not called.”
It is not recommended to use the reduce arity that is missing the explicit init
arg
Is anyone else having trouble deploying to clojars or know what I might be doing wrong? I keep getting the following error:
Could not transfer metadata com.phronemophobic:membrane/maven-metadata.xml from/to snapshots ( ): Access denied to: , ReasonPhrase: Forbidden - S3 request failed.
Failed to deploy metadata: Could not transfer metadata com.phronemophobic:membrane/maven-metadata.xml from/to snapshots ( ): Access denied to: , ReasonPhrase: Forbidden - S3 request failed.
I've deployed successfully previously, but haven't been able to deploy today. Neither snapshots or releases for two separate projects seem to work.
I'm deploying using the latest leiningen with `lein deploy clojars`