Hey guys, I just made this thing https://github.com/fp-alice/cljmcs Aside from not having any tests, am I doing anything wrong?
this could be expressed as (set/rename-keys x {:download :file :href :location})
https://github.com/fp-alice/cljmcs/blob/master/src/cljmcs/http/scraper.clj#L11
never seen that function before, good tip
subjectively, sometimes (first (filter f coll))
is better than constructing a predicate that returns its input so you can use some
https://github.com/fp-alice/cljmcs/blob/master/src/cljmcs/minecraft/servers.clj#L16
the predicate there could be (comp #{minecraft-version} :version)
- returns truthy if the value under the key matches any value in the set
(that's also subjective)
How does that work?
i understand compose
a keys is a function from a map to the value under the key
a set is a function from a potential member to itself only if contained in the set
(#{foo} foo)
-> foo
Oh so it's like getting the version and then checking if it's equal to the given one with the set
(#{foo baz} bar)
-> nil
right
I always read comp backwards
I had this same problem. But apparently every functional language that has compose does it from right to left.
yeah, if the devs in your team (you) don't find that straightforward, it's probably a bad style choice
but it's an idiom I personally like
I love function composition I just always have to read the sexps twice
you use http://clojure.java.io here already, so you could use io/file
, but you could also import java.io.File
so that you can just use File
https://github.com/fp-alice/cljmcs/blob/master/src/cljmcs/os/files.clj#L15
this could be clojure.string/join https://github.com/fp-alice/cljmcs/blob/master/src/cljmcs/os/files.clj#L8
oops, io/file makes sense
that too
the portable version of this is (System/getProperty "user.dir")
https://github.com/fp-alice/cljmcs/blob/master/src/cljmcs/os/shell.clj#L8
If I want to make it work on windows too I'll keep that in mind thanks for the tip
an extra "print-generic-help" type thing as the odd numbered element at the end of the case will make more sense to the user than the runtime error clojure gives if no case is matched https://github.com/fp-alice/cljmcs/blob/master/src/cljmcs/core.clj#L14
well, the getProperty is also a single method call, instead of a chain of functions as well
good point
thanks for the criticism it's really valuable to me 🙂
it's all my opinions so far, no bugs
in fact this
(if action
(case action
"download" (download-command/download! arguments)
"list" (list-command/list! (first arguments))
"help" (help-command/help!))
(help-command/help!))))
could be (case action "download" (download-command/download! ...) "list" (list-command/list! ...) "help" (help-command/help!) (help-command/help!))
- both the lack of an action and an unrecognized action often map to the same help output in shell utilsDidn't think of that
or for style you could differentiate the help output from unmatched by adding a prefixing "no matching command"
Whenever I look at (comp f g h)
, I tend to see #(f (g (h ...)))
.
Of course if you transform it to #(-> ... f g h)
it will seem backwards.