This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-30
Channels
- # admin-announcements (42)
- # alda (8)
- # aws (10)
- # beginners (22)
- # boot (165)
- # bristol-clojurians (1)
- # cider (6)
- # clara (21)
- # cljs-dev (23)
- # clojure (74)
- # clojure-dev (8)
- # clojure-russia (41)
- # clojurescript (180)
- # core-async (11)
- # cursive (26)
- # datascript (2)
- # datavis (7)
- # datomic (29)
- # editors (1)
- # hoplon (7)
- # jobs (3)
- # ldnclj (4)
- # lein-figwheel (47)
- # leiningen (2)
- # mount (26)
- # off-topic (3)
- # om (163)
- # onyx (56)
- # proton (4)
- # reagent (6)
- # remote-jobs (1)
- # ring-swagger (4)
- # spacemacs (9)
@room With clojure, how can I grab the amounts in this lazy sequence? (#USD 19.95 #USD 36.37)
@frankk38506: Depends on how you want to identify the amounts? For example, assuming that seq is bound to currencies
in the code below - by type:
(filter number? currencies)
or by position
(map second (partition 2 currencies))
(filter number? (#USD 19.95 #USD 36.37)) - so something like this?
I’d like a vector or list returned containing only (19.95 36.37)
Yes. Except I'm confused by your sequence - what are #USD
is this a symbol? In which case it would be 'USD
. Also if the sequence is a list in needs quoting in literal form e.g. '(1 2 3 4)
Either of my examples would return a lazy sequence of just the amounts. The filter does it by returning only numbers the second example does it by splitting the seq into a sequence of pairs and then takes the second item in each pair.
i’m not sure what #USD
is, i’ll find out from another dev on my team, i’ll give your suggestions a try, thank you @agile_geek
No problem.
@frankk38506 @agile_geek #USD
is likely a tagged literal:
http://clojure.org/reader#The%20Reader--Tagged%20Literals
I don't know what your #USD
implementation looks like though. I'm guessing it either creates a currency object of some kind, or it's just converting the number to a non-floating point representation or something.
@solicode so in the sequence the #USD is just the tag, in which case you need to take every element?
@agile_geek: Yeah, it's just a tag. But I don't know what type it returns. Is it a Java object of some kind? Do you have to call .getValue
or something on it? I can't know without knowing what #USD
does.
It would be easy for @frankk38506 to check though. For example, what does (type #USD 19.95)
return?
Thank you @solicode. I’ll see what i can find out
@frankk38506: Oh, sorry, I was assuming you had quick access to the REPL right now. Maybe not so "easy" then... 😛
In REPL, i get something like this - RuntimeException No reader function for tag USD clojure.lang.LispReader$CtorReader.readTagged (LispReader.java:1245)
Hmm, that's strange. Is that a plain REPL, or your project REPL with everything loaded already (like dependencies and so on)?
Or the other possibility is that these tagged literals are in EDN? So you wouldn't have access to it in the REPL like that.
just a plain repl