Fork me on GitHub
#beginners
<
2017-07-16
>
jlmr11:07:15

Hi, i'm building a small microservice worker that needs to access a database. I find myself writing some database helper functions which I know a different service I will write later will also have to use. What is the recommended way of seperating the helper functions out so I can use them from both apps?

val_waeselynck12:07:16

@jlmr if they don't call for making a library out of them, I'd say duplicate them.

llsouder13:07:23

Learning to use the REPL with vim and fireplace. I did the Seesaw repl tutorial. The wen on to playing with some of my own stuff. I got this weird lower-case error:

user=> (use 'playground.core :reload)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: lower-case in this context, compiling:(clj_http/util.clj:97) 
using this:
(ns playground.core
  (:require [clj-http.client :as client]
            [cheshire.core :refer :all]))
It went away when I removed Seesaw from my project.clj.

llsouder13:07:56

I posted this here because I could not find a seesaw or http channel and because I was LEARNING the REPL. 🙂

noisesmith13:07:19

@llsouder lower-case is a function in clojure.string

llsouder01:07:10

Looking at this some more, I see this message in the REPL:

WARNING!!! version ranges found for:
[seesaw "1.4.2"] -> [j18n "1.0.1"] -> [org.clojure/clojure "[1.2,1.5)"]
Consider using [seesaw "1.4.2" :exclusions [org.clojure/clojure]].

llsouder01:07:27

Is seesaw for an older version of clojure?

noisesmith01:07:26

most of the time things written for older clojure versions can be made to work with a new clojure pretty easily, that version range warning is newer than 1.5, so the dev who specified a version range had never seen it

noisesmith01:07:32

lein is just being opinionated about this dependency feature (since it can lead to things breaking even when you didn't change your project, just because the version range sees a new version), but it shouldn't automatically make something not work

noisesmith13:07:06

which version of clj-http are you using?

jlmr14:07:33

@val_waeselynck Thanks, will do that for now. When would you consider it worth making a library out of it?

jlmr14:07:33

@val_waeselynck Thanks, will do that for now. When would you consider it worth making a library out of it?

val_waeselynck17:07:58

When you can express the rationale of the library in a sound, simple, non trivial way

mobileink19:07:57

also, a separate lib may making testing more manageable. plus if you're a beginner it may be useful to get the hang of lib development workflow. lein or boot?

llsouder01:07:11

sorry, replied to the wrong message 😊

jlmr07:07:37

@, sorry was offline for a couple of days. I'm using lein now.

josh_tackett19:07:52

Easiest way to update the :selection key to true or false based on the label of the inner map?

[{:label "Users"
    :display-order 1
    :choices
    [{:label "Login"
      :description "basic login page"
      :selection false
      :display-order 1}
     {:label "Reset/Forgot Password"
      :description "link to reset password via email"
      :selection false
      :display-order 2}]}]

schmee19:07:51

@josh_tackett with Specter: (setval [ALL :choices ALL #(= (:label %) "Login") :selection] :some-value your-map)

josh_tackett19:07:46

@schmee specter work for cljs?

josh_tackett19:07:25

what about a good json libaray for cljs? @schmee

schmee20:07:19

dunno one, sorry, I mostly use Clojure

josh_tackett20:07:00

[{:label "Users"
    :display-order 1
    :choices
    [{:label "Login"
      :description "basic login page"
      :selection false
      :display-order 1}
     {:label "Reset/Forgot Password"
      :description "link to reset password via email"
      :selection false
      :display-order 2}]}
{:label "NLP"
    :display-order 1
    :choices
    [{:label "ngrams"
      :description "basic sentence delimiters"
      :selection false
      :display-order 1}]}]

josh_tackett20:07:09

@schmee what about like this ^^^?

josh_tackett20:07:23

(spector/setval [ALL #(= (:label %) "Users")
                   :choices ALL #(= (:label %) "Login") :selection]
                  true app-selection-list)

josh_tackett20:07:59

@schmee does that work? ^^^

schmee20:07:05

should work, but you want specter/ALL instead of ALL

josh_tackett20:07:36

Caused by: java.lang.ClassCastException: clojure.lang.Var cannot be cast to clojure.lang.IObj
 at clojure.core/with_meta (core.clj:217)

clojure.lang.ExceptionInfo: clojure.lang.Var cannot be cast to clojure.lang.IObj at line 614 file:/Users/jtackett/.m2/repository/com/rpl/specter/1.0.2/specter-1.0.2.jar!/com/rpl/specter.cljc {:file "file:/Users/jtackett/.m2/repository/com/rpl/specter/1.0.2/specter-1.0.2.jar!/com/rpl/specter.cljc", :line 614, :column 1, :tag :cljs/analysis-error}

josh_tackett20:07:41

@schmee nope didn’t work

josh_tackett20:07:53

(spector/setval [specter/ALL
                   #(= (:label %) (:label group-data))
                   :choices
                   specter/ALL
                   #(= (:label %) (:label selection-option-data))
                   :selection]
                  selection app-selection-list)

schmee20:07:59

don’t know if this is the issue, but you have spector/setval instead of specter/setval

schmee20:07:06

(o instead of e)

schmee20:07:23

@josh_tackett ^

llsouder22:07:45

I am using [clj-http "3.6.1"]

cjhowe22:07:49

is there an easy way to do something like (-> {} my-fun print my-other-fun print)? i need print to return the value it prints for this to work, though

cjhowe22:07:00

(-> {} my-fun #(do (print %) %) my-other-fun #(do (print %) %)) doesn't seem to work

seancorfield23:07:31

(-> {} my-fun (doto print) my-other-fun (doto print))

seancorfield23:07:06

To make the anonymous function version work you need extra parens: (-> {} my-fun (#(do (print %) %)) my-other-fun (#(do (print %) %))) because -> just inserts the threaded value into the s-exp as the second item -- use macroexpand to see what happens...