This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-22
Channels
- # aws (1)
- # bangalore-clj (3)
- # beginners (103)
- # boot (15)
- # cider (29)
- # cljs-dev (17)
- # cljsrn (43)
- # clojure (156)
- # clojure-gamedev (2)
- # clojure-italy (11)
- # clojure-spec (55)
- # clojure-uk (4)
- # clojurescript (76)
- # data-science (2)
- # datomic (7)
- # defnpodcast (2)
- # emacs (4)
- # leiningen (2)
- # luminus (3)
- # off-topic (11)
- # parinfer (3)
- # pedestal (1)
- # quil (1)
- # re-frame (3)
- # reagent (2)
- # ring-swagger (1)
- # timbre (3)
- # unrepl (10)
- # untangled (1)
- # vim (3)
- # yada (1)
@sundarj with Specter:
user=> (def numbers (s/walker number?))
#'user/numbers
user=> (s/transform numbers inc [1 2 3])
[2 3 4]
user=> (s/transform numbers inc [[1 2] [3 4 5]])
[[2 3] [4 5 6]]
user=> (s/transform numbers inc [[1 2] [3 4 5] 6 [7]])
[[2 3] [4 5 6] 7 [8]]
code like this (transform [MAP-VALS ALL MAP-VALS even?] inc data)
or (setval [:a END] [4 5] data)
seems to basically be a DSL rather than a simple function
if i wanted to use it first-class, and compose it with other functions and such, i think i'd need to write wrappers around Specter's stuff to hide the DSL
the capital letters stuff is called navigators, and itās a completely open system and itās easy to implement your own
do you have a concrete example of where you want to use it first-class where it doesnāt work for you?
sorry, no concrete example, just an ignorant first impression š good to know it's an open system, maybe i'll give it a try š
for some reason the CAPITAL LETTERS freak people out, but I urge you to give it a shot!
it's just the fact you have to buy into Specter-specific knowledge, unless Navigators can be used outside of Specter?
as for Specter-specfic knowledge, that is certainly true, as with every library/dependency you have to evaluate whether the increased complexity is worth the added benefit š
given how much easier a certain class of problems become with Specter, for me it is worth it most of the time
but if I only use it in a few places, I might replace it with core clojure just to have less stuff
for me, i care vastly more about simplicity than ease. Specter seems to ask for a lot more upfront compared to, say, Hiccup or Garden
Hi, folks, I try to run migrations on the server, I need to run function forest-community-blog.db/migrate but on server I have only server.jar which I start by running java -jar server.jar
, is it possible somehow run function which is not main from the jar file? š
@crashtown I'd probably modify main to either run migrations automatically on run, or let it run the migration function when a certain command line flag is given
@crashtown java -cp server.jar clojure.main forest-community.blog.db
the key here is that forest-community.blog.db must have a -main function - but I'm sure you could arrange that
clojure.main is sufficient
avoid gen-class whenever possible
also if you skip the last arg you get a bare bones repl where you can require any of your namespaces that are in the jar
@rorysmith reduce takes a function, a collection, and optionally a starting value
so reduce will keep calling your function with values from a collection and passing the resulting value into the function you are reducing with
so (reduce str ["a" "b" "c"])
will not see an initial value and it will use the first value of your collection, "a". So this will start the reduction with "a". And reduce will call your function, here str
, with the value that's been accumulated and the next value of the coll
so this will call (str "a" "b")
which is the initial value of the collection and then the next value of the collection. This yields "ab" as str
will just concatenate
and then reduce passes this accumulated value to your function str
along with the next value in the collection, "c"
i never know what level understanding there is so i didn't mean to explain things you already knew
clojure has some lazy datastructures, meaning it tries to only perform computatoins that you actually consume
(range)
returns an infinite list of the non-negative integers, which is obviously impossible without some kind of bound
and if you call str
on one of these you'll get its string representation, which is something like #lazysez[] or something
thanks, i'm going through some exercises on codewars and very much enjoying functional programming
@rorysmith a nice aid to understanding reduce is another function called reductions - which is just like reduce except it returns a lazy sequence of every result (and the last one will be the same one reduce would return)
@noisesmith nice, thanks
(I would have used your example with the bot, but the bot breaks when you give it strings sadly)
@noisesmith @rorysmith I personally like the fold
name sometimes used in place of reduce
. Itās very visual
also the name "reduce" implies you can't use it to create outputs with larger or more complex structures than the inputs, which tends to make people less likely to realize when it's useful
Yeah. I am not sure about the reasons why some people prefer the word āreduceā, I am sure there are some very valid ones, but for a beginner āfoldā is more visual imo
it's one of the "historical reasons" things - making clojure more like lisp
like cons
iāve got a lein project; iāve written some tests in test/mover.clj
, but lein canāt find them
Do you have :test-paths
set in project.clj @U090G4C05 ?