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)
I am particularly interested in developing a REST API, so I would like to dig more in ring’s handlers, compojure, security/authentication, etc., does anyone knows if those videos could be a good starting point?
@rcanepa: Collections, in Java, refers to a class hierarchy containing various interfaces & implementations of map/list/set/queue/deque. See https://docs.oracle.com/javase/tutorial/collections/
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. and the map could have more steps then 1 as my example have shown
or can I do something like this ( map (alter ....... ) withdraws) and the same for the deposits
I could but then I have to rethink how I can take care the amount of a particular account
now I have one ref which holds the amount of cash and one ref which holds the amount of the bank
till now I have this : https://www.refheap.com/112363
(def default-state {:my-lines {} :hover-pos nil :last-mouse-moment nil :labels-visible? false :in-sticky-time? false :labels [] :current-label nil}) (def state (atom default-state))
{ :accounts {:cash VAL :bank VAL}}
or something
and I have doubt for the best way to do the last step. Chancing the values of the refs
An atom can basically be whatever you need it to be
See @trancehime's example. But VAL can really be anything, like [{:what ""}{:what nil}]
Yeah, the atom can be modeled to suit your needs.
Modifying the atom's contents can be done using swap!
oke Can I have transactions on atoms. I need to have that so if a transactions like [ { :account cash :withdraw 100} ] [ :account bank :deposit 100] }
fails nothings has to happen
that's what swap!
is for
(swap! your-atom your-function)
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 ?
@eggsyntax: Thanks
@rcanepa: I stream here: https://www.livecoding.tv/sveri/ from time to time. I am happy to answer questions too if I can 😉
@roelof: Something like this could work: ((juxt :a :b) {:a 1 :b 2}
yields [1 2]
oops missing close paren
You could also do (map {:a 1 :b 2} [:a :b])
, which gives you the list (1 2)
@codonnell: thats a cool trick
If you don't want a lazy seq, you can use mapv
. Lazy and non-lazy have their own advantages and disadvantages.
You can handle things like infinite sequences with lazy operations.
Quoting stops the REPL from evaluatin what's inside. So the type of the + in '(+)
is a symbol, while in (list +)
, the + is evaluated and becomes a function type.
you're welcome
I am fighting with a simple problem and I can’t find the problem. I am sure that I am missing some detail, can anyone take a look a this?. It is a simple handler that I created to learn about ring and compojure. For some reason, I can’t coerce a string (request parameters) to an Integer.
No implementation of method: :render of protocol: #'compojure.response/Renderable found for class: java.lang.Long