This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-01
Channels
- # beginners (59)
- # cider (3)
- # clara (4)
- # cljsjs (4)
- # clojure (144)
- # clojure-finland (2)
- # clojure-italy (10)
- # clojure-russia (2)
- # clojure-spec (7)
- # clojure-uk (53)
- # clojurescript (81)
- # cursive (30)
- # datomic (36)
- # defnpodcast (2)
- # editors (3)
- # emacs (4)
- # events (1)
- # fulcro (12)
- # off-topic (11)
- # onyx (14)
- # parinfer (2)
- # pedestal (12)
- # re-frame (3)
- # reagent (26)
- # shadow-cljs (81)
- # spacemacs (10)
- # sql (59)
- # uncomplicate (4)
- # yada (4)
@hiredman Any examples of impure functions that you have used memoize on before? If the memoized thing is doing read-only behavior from a database that is never or slowly changing, I suppose memoize could be used there to improve performance and give the correct results (perhaps even past the time it gives up to date correct results, if you aren't careful).
I don't use memoize all that much, I think the last place I used it maybe spun up a thread to do something and return a core async promise-chan, but I don't entirely recall. What came to mind immediately was lein used to use memoize internally on tasks to stop them running multiple times
Hello, I would like to create lein-plugin for myself for esier deploy cycle. I try to use clojure/tools.cli but when I tested.. with “-h” flag not works the program.. if I use “-e” everything ok.
(def cli-options
"all optional and positional"
[["-e" "--helps" "Help me"
:default false]
["-u" "--sudo" "Configure passwordless sudo"
:default false]])
sb$ cd ../devops && sudo lein install && cd ../test-project/ && sudo lein devops -h
Created /Users/sb/Desktop/devops/target/devops-0.1.0.jar
Wrote /Users/sb/Desktop/devops/pom.xml
Installed jar and pom into local repo.
Main function called from Leiningen from original docs
Arguments: ([& args])
sb$ cd ../devops && sudo lein install && cd ../test-project/ && sudo lein devops -e
Created /Users/sb/Desktop/devops/target/devops-0.1.0.jar
Wrote /Users/sb/Desktop/devops/pom.xml
Installed jar and pom into local repo.
Lein-devops Leiningen plugin helper
Usage: ${0} (-h | -S | -u | -k | -s | -d [docker_ver] | -a [docker_ver])
ENVIRONMENT VARIABLES
Usage: (you can add in project.clj)
Example: :devops {:server-ip "123.12.12.232"}
..works
any idea how to fix it? is that possible or good example how to use -h option with tools.cli?
I modified to -e
, before this was -h
. I added tests for this code.. “validate-args cli-options” and come back a normal response. So, I don’t know what is really the problem..
Other characters.. works fine.. just problem with the “h” character.. when run the plugin (lein devops -h).
I’m trying to make something remove
based on two criteria:
(remove (and (comp #{"one"} :id) (comp #{"two"} :other-id)) '({:id "one" :other-id "two"}))
=>()
(remove (and (comp #{"one"} :id) (comp #{"two"} :other-id)) '({:id "not-one" :other-id "two"}))
=>() ;; should return '({:id "not-one" :other-id "two"})
i’m not surprised that this doesn’t work; i think it’s only comparing :id
because and
is evaling and returning the first comp
.
(i only picked and
because it semantically fits what i want; do this and
do this)point taken of course. i have not figured out how to write what i want. i want an expression that accepts a list of maps and removes them if they match two kv-pairs. but to be pedantic, it is a function! (and thing thing) returns thing, which is a function.
user> (and (comp #{"one"} :id) (comp #{"two"} :other-id))
#function[clojure.core/comp/fn--5360]
this does it, but is verbose:
(remove (fn [{:keys [id other-id] :as m}] (and (contains? #{"one"} id) (contains? #{"two"} other-id)) ) '( {:id "not-one" :other-id "two"}))
(remove #(= {:id "one" :other-id "two"} (select-keys % [:id :other-id])) '({:id "not-one" :other-id "two"}))
Does this satisfy your requirements?that does in that case! thanks. a requirement i didn’t say but that i have, is that i actually need it to support a set of values (hence my (contains #{“one”}), which easily supports more values. thanks though, i forgot about select-keys
i was looking in the docs for something like juxt. I want to be able to say
(foo (comp #{"one"} :id) (comp #{"two"} :other-id))
where foo
means “give as input the same to each”yeah, that would be useful. you could use something like:
(defn juxt? [f g]
(let [ps (juxt f g)]
#(apply and (ps %))))
cljs.user> (every? identity ((juxt (comp #{"one"} :id) (comp #{"two"} :other-id)) {:id "one" :other-id "two00"}))
false
cljs.user> (every? identity ((juxt (comp #{"one"} :id) (comp #{"two"} :other-id)) {:id "one" :other-id "two"}))
true
@U0HJ4RAGY i think you want every-pred
=> (remove (every-pred (comp #{"one"} :id) (comp #{"two"} :other-id)) [{:id "not-one" :other-id "two"} {:id "one" :other-id "two"}])
({:id "not-one", :other-id "two"})
so if i run an assert function in the repl and it does not give me an exception, does that mean it passed. it is returning nil which is why i wanted to clarify. nil means it's all good in this instance?
right
cool. i probably should have re-read the docs and asked here before I refactored my function 3 times. lol
I have two projects Project A
and Project B
that both use another project called Project C
If Project A
calls that function, everything succeeds and I get the expected result: 8e7d820ad9d3323edb541a72da4912148cb9c0c2
I bet lein deps :tree
in Project A and Project B would show the difference
@noisesmith I think I caught it with lein deps :tree
NP - I could have been more verbose and said the difference in behavior must reflect different dependency versions etc. but glad you saw the issue
it means that you won't use commons-codec, even if something you depend on depends on it
usually exclusions are useful on a specific dep (saying "I don't want the version of this that foo/bar asks for") - an exclusion at the top of your project says "I won't provide this dep at runtime even if something says it needs it"
Okay so in my Project C I am using a certain version of commons-codec that I want to use. In Project B I have some dependencies that seem to depend on an older version of commons-codec. How can I resolve this issue?
usually listing C before the conflicting dep will sort that out, otherwise you can add an exclusion to the specific dep asking for something different, and/or ask for the specific version that B wants
lein help sample
has examples of using exclusions
@noisesmith :thumbsup: