Fork me on GitHub
#clojure
<
2018-05-25
>
benzap06:05:34

I remember that article @arohner, I don't know where it is though. If you want something similar to what he suggested, you could check out mount

arohner13:05:03

yes, thanks!

Bravi08:05:17

can I refactor this somehow?

(let [uncategorized {:id   :uncategorized
                     :name "Uncategorized"}
      group-fn      #(if (-> % :gallery nil?)
                       uncategorized
                       (:gallery %))]
  (group-by group-fn projects))

Bravi08:05:09

coz with clojure it always feels like there’s a better way 😄

Grigory Glushko08:05:19

(group-by #(get-in % [:gallery] uncategorized) projects) should work

Bravi08:05:51

it doesn’t because :gallery in some cases is just nil

Bravi08:05:00

so the key exists there, but the value is nil

Bravi08:05:22

but that’d be nice 😞

Bravi08:05:14

ah I could wrap it up in or

schmee08:05:40

(group-by (fnil #(get % :gallery uncategorized) uncategorized) projects)

schmee08:05:48

something like that, fnil is the key

Bravi08:05:55

(group-by #(or (get % :gallery ) uncategorized-group) projects)

noisesmith16:05:44

alternatively #(:gallery % unrecognized-group)

Bravi21:05:51

that won’t work, because :gallery key is there, but the value is nil. so it doesn’t get to uncategorized-group part basically

benzap09:05:33

Is there a way to evaluate a symbol while in the current context? So far i've tried (let [x 10] (eval 'x)) which does not recognize the x

benzap09:05:45

Can let-bound values not be retrieved in this manner

bronsa09:05:13

they can’t

benzap10:05:32

@tristefigure thanks, i'll check it out

tristefigure10:05:48

This is my tote-bag repo where I start development on stuffs that I later extract to their own lib. I'll probably move this in a separate repo this weekend, I'll state it in the README.

benzap10:05:50

nice! lots of interesting stuff in here 🙂

benzap10:05:47

i'm trying to write a quote form, with escape sequencing

benzap10:05:51

so more specifically (let [x 10] (form-eval test value %= x)) ;; '[test value 10]

dominicm10:05:16

@benzap would a macro work for you here?

dominicm10:05:49

@benzap

(defmacro form-eval
  [& body]
  (:result
    (reduce
      (fn [{:keys [result eval-next?]} atom]
        (cond
          (= atom '%=)
          {:result result
           :eval-next? true}
          eval-next?
          {:result (conj result atom)}
          :else
          {:result (conj result `(quote ~atom))}))
      {:result []}
      body)))

(let [x 10] (form-eval test value %= x))
This gives the result you desired.

benzap10:05:56

oh interesting, thanks @dominicm, I think i'm going to steal this!

dominicm10:05:57

No problem, I wrote it just for you anyway

jumar12:05:04

What do you prefer for optional merging of maps?

(def errors [:a :b])
(def warnings [])
(def infos [:e :f])

;; 1. merge + 3x when
(merge {}
       (when (seq errors) {:errors [:a :b]})
       (when (seq warnings) {:warnings [:c :d]})
       (when (seq infos) {:infos [:e :f]}))
;;=> {:errors [:a :b], :infos [:e :f]}

;; 2.cond-> + 3x merge
(cond-> {}
  (seq errors) (merge {:errors [:a :b]})
  (seq warnings) (merge {:warnings [:c :d]})
  (seq infos) (merge {:infos [:e :f]}))
;;=> {:errors [:a :b], :infos [:e :f]}
Any other approach?

mpenet12:05:14

cond-> and assoc, not merge

mpenet12:05:32

Merge with only 2 args is usually a code smell

danm13:05:45

We've got 2 maps, 1 with keys a b c d e, the other with keys d e f g. You want a single end map with keys a b c from the first and d e f g from the second. Why would you not merge? Assoc would require you to add each key individually

danm13:05:05

Or did you mean 2 args as in the second map only has a single key?

mpenet13:05:15

Merge with 2 args = conj. And if you know the keys before assoc is better

drcode14:05:10

Hi everyone, I use the "checkouts" directory feature with leiningen when I want to use a project on my local machine as a dependency for a project. What is the appropriate way to do something similar with the new clojure CLI tools and deps.edn file? Thanks in advance for any tips!

drcode14:05:07

Never mind- Found my answer... "local coordinates"

Alex Miller (Clojure team)14:05:28

one note is that local deps must use a manifest definition in either deps.edn or pom.xml (project.clj not supported right now)

👍 4
Akka17:05:09

how use nrepl in spring?

johnj17:05:34

how do you use nrepl now?

johnj17:05:21

lein starts a nrepl

noisesmith17:05:33

nrepl has a server namespace for starting a repl from inside a running application. Don't listen to anything but local connections (listening for outside connections is a huge security issue, if you need to access it from another host use an ssh tunnel to make a local connection)

noisesmith17:05:20

if you only need it during dev, you can start your spring app main from inside a repl in a bacground thread

plins18:05:06

not sure if this is the right place to ask but Im having issues on how to deploy my lib to clojars (this is my first lib in clojure so sorry if im missing something obvious) Ive generated my gpg key, but Im not sure on how associate it with my clojars account

plins18:05:52

thanks 🙂

👍 4
the2bears18:05:54

Probably better luck there for your questions

Akka18:05:51

@noisesmith thank you I have succeeded!

👍 4
😂 4
Akka18:05:17

But i don't know how to call java method 😢

Akka18:05:42

yeah thanks

Akka18:05:39

In-ns Java class namespace then I Can’t call any

Akka18:05:31

It’s night。I need sleeping. My English so bad

dorab18:05:43

Not sure what exact issue you're having. If you have one example, perhaps we can help.

dorab18:05:49

In general, if you want to call method foo of an object of class Bar, then (def x (Bar. ...)) and then (.foo x)

Akka18:05:14

Wow so good。

dorab18:05:38

where x is a Clojure var that contains a Java object of class Bar.

Akka18:05:52

I write closure too

Akka18:05:20

I think I understand

dorab18:05:50

Great. The details are at the link I provided earlier. Maybe try again in the morning 🙂

Akka18:05:45

Ok sure Try it in the morning

Akka18:05:24

Thanks again .

plins20:05:05

hello everyone, I was searching for a macro that leverages pattern matching, and worked like Elixir`s with I’ve managed to get a working version, but this is my first macro, so any feedback is appreciated https://github.com/pablobcb/clj-with I hope the README is self explanatory

👍 4
dpsutton20:05:00

nice!. it's the matching with propagating else bindings?

plins20:05:47

there is an example in the test folder, maybe i should put all of them in the read me