This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-26
Channels
- # adventofcode (23)
- # babashka (13)
- # beginners (63)
- # calva (17)
- # circleci (2)
- # cljdoc (3)
- # cljfx (11)
- # clojure (23)
- # clojure-europe (2)
- # clojure-uk (1)
- # conjure (1)
- # depstar (4)
- # emacs (3)
- # fulcro (41)
- # graalvm (29)
- # joker (5)
- # malli (6)
- # reagent (6)
- # reitit (1)
- # remote-jobs (1)
- # shadow-cljs (19)
- # spacemacs (8)
- # testing (9)
- # tools-deps (33)
Trying to implement juxt for fun - The below using reduce works fine -
(fn [& fns]
(fn [& args]
(reduce (fn [acc f]
(cons (apply f args) acc))
[]
fns)))
however cant get the one with recursion to work -
(defn my-juxt-2
[f & fns]
(fn [& args]
(when f
(cons (apply f args) (my-juxt-2 fns)))))
((my-juxt-2 + max min) 2 3 5 1 6 4)
If you rewrite this to use loop/recur inside the innermost function it should work fine, right?
Currently this code is trying to cons the result of f
with the function returned from my-juxt-2
(defn my-juxt-2
[f & fns]
(fn [& args]
(letfn [(jr [[f & fns]]
(if f (cons (apply f args) (jr fns)) []))]
(jr (cons f fns)))))
loop/recur conceptually creates an inline function recursion too, so I think the answer is that you need one more internal function if you want to recur in that way
You want to return a function that takes any arguments just once, and do the recursion inside of that, to apply the functions received by juxt one-by-one.
In the original version you had the top level function returned from my-juxt-2
so you would return that each time you recursively call it to progress the recursion.
Hah, juxt
all the things! Contributing my little homage:
(defn yet-another-juxt
"Yet another juxt, because, why not? :)"
[& fns]
(fn [& args]
(mapv (fn [f args] (apply f args))
fns
(cycle [args])))) ; <-- but of course, we can omit this entirely (discussed in the thread to this message)
#_((yet-another-juxt inc dec identity) 1) ; => [2 0 1]
#_((yet-another-juxt + - *) 1 2 3 4 5) ; => [15 -13 120]
#_((yet-another-juxt + *)) ; => [0 1]
#_((yet-another-juxt inc)) ; Barf! (As it should...)
also, not sure if it matters, but at least as curiosity it is worth mentioning the the original juxt
does fail when you invoke it with 0
arguments
> Why can't you just leave them out altogether? Why not indeed... > also, not sure if it matters, but at least as curiosity it is worth mentioning the the original `juxt` does fail when you invoke it with `0` arguments True... On the other hand, if we're mucking around making cheap copies, why not take some creative license? 😁
(defn yet-another-yet-another-juxt
"Yet another yet another juxt, because, why not why not? :)"
[& fns]
(fn [& args]
(seq (mapv (fn [f] (apply f args))
fns))))
#_((yet-another-yet-another-juxt inc dec identity) 1) ; => (2 0 1)
#_((yet-another-yet-another-juxt + - *) 1 2 3 4 5) ; => (15 -13 120)
#_((yet-another-yet-another-juxt + *)) ; => (0 1)
#_((yet-another-yet-another-juxt inc)) ; Barf! (As it should...)
#_((yet-another-yet-another-juxt)) ; => nil ; The juxt of nothing over nothing can be nothing
Using map with fns as the input is something I really gotta remember to use more, can lead to really neat solutions. Nice one!
Good Morning Clojurians. I am trying to connect https://github.com/fulcrologic/fulcro-rad-demo to Postgres. Looking through the repo, I think that the only place you have to change is in https://github.com/fulcrologic/fulcro-rad-demo/blob/master/src/shared/config/defaults.edn file. So I replaced the :hikaricp/config
with:
:hikaricp/config
{"dataSourceClassName" "org.postgresql.ds.PGSimpleDataSource"
"dataSource.user" "me"
"dataSource.password" "mypwd"
"dataSource.databaseName" "mydb"
"dataSource.portNumber" "5432"
"dataSource.serverName" "localhost"
but when the app begins to seed, I get java.lang.IllegalArgumentException: No implementation of method: :-execute-one of protocol: #'next.jdbc.protocols/Executable found for class: nil
Am I missing a dependency somewhere? Attached is the complete terminal output.