This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-02
Channels
- # adventofcode (63)
- # announcements (21)
- # babashka-sci-dev (1)
- # beginners (24)
- # biff (2)
- # calva (78)
- # cherry (6)
- # clj-commons (3)
- # clj-kondo (7)
- # clojure (91)
- # clojure-austin (2)
- # clojure-bay-area (6)
- # clojure-denmark (1)
- # clojure-europe (45)
- # clojure-nl (1)
- # clojure-norway (16)
- # clojure-portugal (3)
- # clojure-uk (1)
- # clojurescript (20)
- # conjure (11)
- # datalevin (13)
- # datomic (5)
- # emacs (14)
- # etaoin (15)
- # events (7)
- # fulcro (9)
- # funcool (1)
- # honeysql (26)
- # joyride (4)
- # kaocha (3)
- # lambdaisland (2)
- # malli (7)
- # off-topic (22)
- # pathom (29)
- # portal (58)
- # practicalli (8)
- # rdf (25)
- # reagent (14)
- # sci (3)
- # scittle (37)
- # shadow-cljs (10)
- # slack-help (2)
- # spacemacs (7)
- # sql (7)
- # tools-deps (1)
- # xtdb (2)
Hi All, I have a postgres function returning below result : {"title" : "ABC", "currentDate": "11/21/2022" , "data": [{"makeOver":"8","Parallel":"9"}]} {"title" : "XYZ", "currentDate": "12/21/2022" , "data": [{"makeOver":"9","Parallel":"12"}]} {"title" : "XXX", "currentDate": "01/20/2022" , "data": [{"makeOver":"10","Parallel":"9"}]} (all are individual maps) How can I iterate through each one of them if I have to change the Date format. Do I need to first convert it into a single collection or is there another way to achieve this where I can modify them with as-is structure.
Assuming xs
is your data (sequence of maps), and f
is a function that takes a date and returns it in the desired-format, you can do (map #(update % "currentDate" f) xs)
.
When you have a problem that involves many things, solve it for one and then map the solution over the many things. Not necessarily limited to programming problems 😛
Hi Everyone,
I have a list, (["1000" "2000"] ["3000" "4000" "5000"])
but it could be (["1000" "2000"] ["3000" "4000" "5000"] ["6000" "7000" "8000" "9000"])
.
This is a two part problem but I suspect the answer might be the same or very different for each part. I want to convert each string into a number and then sum the numbers in each vector.
If I do something like:
(let [[numb1 numb2] (["1000" "2000"] ["3000" "4000" "5000"])]
[(reduce + (map #(Integer. %) numb1))
(reduce + (map #(Integer. %) numb2))])
Then I can get [3000 12000]
but that only works when the vector has a known size. Is there a more general way to do this?map
(or mapv
) will iterate over the collection. For each of those iterations, you have the inner collection where you also want to map
to parse the integer and then reduce
to get the sum:
(mapv (fn [coll]
(reduce + 0 (map parse-long coll)))
[["1000" "2000"] ["3000" "4000" "5000"]])
parse-long
is part of Clojure 1.11; otherwise you can replace with #(Integer/parseInt %)
For your first solution I get an "Execution error" ... "Expected string, got clojure.lang.PersistenVector" and then variations on a theme when I poke it.
are you sure?
user=> (mapv (fn [coll]
(reduce + 0 (map parse-long coll)))
[["1000" "2000"] ["3000" "4000" "5000"]])
;;=> [3000 12000]
Yes but it was the classic interface between the keyboard and chair bug. I made a typo in (map parse-long coll)
... I typed (amp
.
I apologise, sorry.
heh, no apology necessary! I wasn't sure I didn't make a typo myself, but that's why a REPL is really useful - you can quickly remove parts of a complex operation and re-evaluate until you find the source of the bug :)
I will play with your solution and try to understand it. Thank you!
How do I connect clojure to a neo4j db? Any good reference. I want to apply core.logic in my database.
https://neo4j.com/developer/clojure/#neo4j-clojure there are few connectors mentioned in neo4j documentation
Reading SICP with Clojure in mind - I have a question regarding iterative processes vs. recursive processes:
When used - loop recur
is an example of an iterative process - yeah?
thanks lol
hey no spoilers
just kidding its ok- also thank you