Fork me on GitHub
#clojure
<
2020-12-26
>
murtaza5204:12:38

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)

andarp05:12:34

I feel like the call to the top of my-juxt-2 inside the cons isn’t quite right

andarp06:12:34

If you rewrite this to use loop/recur inside the innermost function it should work fine, right?

andarp06:12:52

Currently this code is trying to cons the result of f with the function returned from my-juxt-2

murtaza5206:12:43

yup, with loop-recur I can make it work, I am stuck on the regular recursion one.

Tamas07:12:13

(defn my-juxt-2
  [f & fns]
  (fn [& args]
    (letfn [(jr [[f & fns]]
              (if f (cons (apply f args) (jr fns)) []))]
      (jr (cons f fns)))))

andarp07:12:22

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

andarp07:12:25

Yep, like that 😄

Tamas07:12:29

how about something like this?

Tamas07:12:35

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.

Tamas07:12:59

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.

adi08:12:12

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...)

p-himik08:12:46

I think (cycle [args]) can be replaced with (repeat args).

adi08:12:29

And I think that would work juxt fine too...

Tamas08:12:00

Why can't you just leave them out altogether?

Tamas08:12:27

ie. do the mapv just on the fns

Tamas08:12:53

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

adi09:12:35

> 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

andarp10:12:33

Using map with fns as the input is something I really gotta remember to use more, can lead to really neat solutions. Nice one!

🎉 3
Timofey Sitnikov14:12:06

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.

thegeez18:12:54

The clj -M:dev:sql looks suspicious to me, try clj -A:dev:sql <the rest>

murtaza5208:12:37

@U012GN57FJ9 there is a fulcro channel, have you tried asking there ?

3