This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-05
Channels
- # admin-announcements (8)
- # beginners (73)
- # boot (14)
- # cljsrn (4)
- # clojure (157)
- # clojure-indonesia (1)
- # clojure-poland (1)
- # clojure-russia (3)
- # clojurecup (32)
- # clojurescript (123)
- # clojurex (4)
- # core-async (8)
- # cursive (7)
- # datavis (26)
- # datomic (5)
- # hoplon (2)
- # off-topic (3)
- # om (41)
- # portland-or (6)
- # random (1)
- # re-frame (11)
- # slack-help (3)
- # specter (1)
The section about priorities was targeted at the language rather than tools
I just started using/learning Clojure =o Had no idea there was a community survey for that
I have 2 refs which represent a account like cash or bank. Now I want to calculate the new amount of the accounts. A transaction could look like this [ { :account cash :withdraw 100} ] [ :account bank :deposit 100] }
I know I have to use alter but how do I do it when everything step of a transaction is in a map.
or can I do something like this ( map (alter ....... ) withdraws) and the same for the deposits
I don't understand that question.
What is a "descending infinite sequence"?
Whether it is possible or not you would want to start not with range
but repeat
or iterate
- something that returns an infinite sequence.
guess there were multiple ways to interpret that. I was looking for something like -1, -2, -3 ….
here’s my non-infinite hack:
(defn neg-range []
(range -1 (- (java.lang.Long/MAX_VALUE)) -1))
Oh, an infinite sequence of negative values?
So literally descending from some positive value down to "negative infinity" (emphasis on quotes)
It seems you got it though while I was in the shower
so lol
Hi. let's say I have a list of maps. What is the best way to find a map in that list, update the map and replace the old map with the new one? Is there an idiom for this?
Right now I'd do it manually by splitting it into the described three steps, but I wonder if it could be done better?
Is your list of maps kept in a vector
Or is it literally just a list of maps
@trancehime: They are kept in a vector
Well I guess to update a map you could use assoc
Yea, I get that. What I find repetitive is: get map from list, update map, put back into the same spot in the list
assoc
is basically your step 2 and 3 merged into 1 single step.
Well, possibly run map-indexed
on the vector?
update-in
the index of the map you want to update
I wonder if stuff like that is easier done with specter. Anyone tried it to that extent?
I personally haven't used specter
Didn't have a need to use it yet either, but it's probably more noticeable with more complex data structures/selectors.
That depends on what the level more means, I suppose - if it means you have to recursively find an index, then yeah, that starts to look annoying; if that just means the map is nested that's probably not much of an issue.
the map looks like this: {...some...stuff... :new-entity {:columns [{:key "val"}{...}...]}} so yea, it's not index based
I suppose it starts to looks like something lenses or specter could help with, for sure.
Oh god yeah, you might want to look into that then
(spec/transform [:new-entity :columns spec/ALL #(= (:id %) 1)] #(assoc % :nullable true) tm)
where 1 is the id of the entity and tm is the whole data structure. Looks better than get-in and update-in, at least, to me
Another question : I have a vector of maps like this [ {:arg1 test :arg2 test2}] Now I need to have the contents of arg1 and arg2 for another function. So I could use map to iterate over the vector and get the first element. So far so good. Then I need a anymous function which as far as I know needs 2 arguments. But the arguments are not known till the first element is chosen. I can named it "it" so I can do (get :arg1 it) but I see then that I need to have 2 arguments. How to solve this one ?
so basically im doing this (map (fn [ ??? it ] ) (alter (get :arg it) (get :arg2 it) coll)))
@roelof: Maybe you could provide a real example with input and outcome you want to have via pastebin?
Let's say I have a example input of [ { :account cash :deposit 100} {:account bank :withdraw 100} ]
Then I want the first time as function (alter deposit cash 100) and the second time (alter withdraw bank 100)
#C075TNSSC Talks were recorded and I think majority are now available. https://skillsmatter.com/conferences/6861-clojure-exchange-2015#program Enjoy. Check out Bozhidar on CIDER. Very entertaining.
Hm, using schema I found that (s/one Keyword "name") requires the "name" part. Anyone knows the reasoning behind it?
Basically either I have [:varchar 300] or :text but schema tells me this: No implementation of method: :spec of protocol: #'schema.core/Schema found for class: schema.core.One. It looks like it is not supported by schema, is that right?
Maybe more this way : `[ {:debet {:account "cash" :amount 100 }} { :credit {:account "bank" :amount 100}} ]'
Well it would be easy if the keys were always consistent, in my opinion. [{:account "cash" :type :deposit :amount 100} {:account "bank" :type :withdraw :amount 100}]
What are you trying to accomplish with that vector @roelof ?
and how can I convert this so alter could use the type , the account and the amount part
@sveri: ok, this seems all right, it turns out I was kinda confused about something instead. You can totally use (s/either varchar other-type)
though, no need to resort to using the record directly.
So you have some account information in a ref, then? What does that ref look like?
@sveri: yeah, but as I understand it Either
is an implementation detail of either
, so both are deprecated.
But I'm not really sure how to replicate either
behaviour with the conditional schema they suggest.
@codonnell: like this (def cash (ref {:amount 0}))
Ok, another schema problem where I dont know how to handle it conceptually. My vecs may also look like this:
I got the first two parts like :email and :time. But how would I specify that if something comes afterwards it has to contain two things. and then they are also dependent. so a :boolean type can only have :default boolean. But a :text type might have a :default string. and :null can only be followed by a boolean
something like that should work @roelof
Though I think it would be fine to put all of the accounts into one ref.
@jaen I see there are ifs and stuff. That might be part of the solution. But how would I type :null must be followed by false and if one is there the other one has to be there too?
Hi. Is there a way to show list of public resources on classpath?
You do. In my code snippet, all of the alter
calls are made within a call to dosync
I'm glad. There are a couple problems I already see with my snippet above, but I think you should be able to iron them out. I really think it would be better to put all of your accounts into a single ref.
I think I ask on their mailing list, have not found anything scrolling through their API doc
You're welcome.
has anyone ever tried to do a static validator for prismatic/Schema? Certainly not something that would restrict you (it would probably need to be overly optimistic in lots of cases), but something that can give you some type errors w/o running your code?
That's the idea behind core.typed, but it doesn't use the same type language as Schema.
I mean, you have to specify the types differently.
I get the feeling people like prismatic schema b/c core.typed isn't expressive enough to capture common clojure idioms (http://blog.getprismatic.com/schema-for-clojurescript-data-shape-declaration-and-validation/)
And I thought it would be cool to have a tool that gives "best effort" static type errors for Schema
Right, yeah. As far as I know that's about the only option for validations like that at compile time, though.
@codonnell: one question. Does this work also when I do something like this : [{:account "sales " :type :deposit :amount 100} {:account "taxes" :type :withdraw :amount 20} {:account: "payable" :type: withdraw :amount 80 ]
so when there are more then 1 deposit or withdraw.
@roelof: Indeed, the (doseq [t transactions]
bit means the following code will execute on each element of the transactions collection, binding t
to the transaction value.
Hi. In Clojure, what's a best way to locate my project's destination in the filesystem? I want to have "file upload" folder's location to be automatically defined
though I could create "upload" folder somewhere in ~/.myprogram
directory of the server, I don't know the way of serving particular folder in Compojure, other than resources/public
@codonnell: thanks, learned another thing. I Always thought that I can only use map or reduce.
no problem