This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-28
Channels
- # beginners (33)
- # boot (58)
- # cider (21)
- # cljs-dev (197)
- # cljsrn (112)
- # clojure (136)
- # clojure-belgium (5)
- # clojure-dev (57)
- # clojure-greece (1)
- # clojure-italy (3)
- # clojure-russia (6)
- # clojure-spec (148)
- # clojure-uk (54)
- # clojurescript (29)
- # cursive (24)
- # datomic (36)
- # devops (4)
- # emacs (11)
- # figwheel (1)
- # graphql (18)
- # hoplon (6)
- # leiningen (2)
- # luminus (4)
- # off-topic (7)
- # om (4)
- # onyx (27)
- # precept (1)
- # protorepl (12)
- # quil (1)
- # re-frame (28)
- # reagent (10)
- # ring (9)
- # robots (1)
- # rum (2)
- # slack-help (5)
- # spacemacs (16)
- # sql (16)
- # untangled (16)
- # vim (3)
- # yada (2)
I am having a hard time deciding between (:foo (:bar bat))
vs (-> bat :bar :foo)
jcromartie: fwiw i like -> for aesthetic reasons, but also because it makes it really easy to inject other stuff in the pipeline during development.
there’s also (get-in bat [:bar :foo])
which could be handy if you’re generating the path into that nested map on the fly.
just for the case of two calls
a third option to complicate (i think this is a matter of preference, really) (get-in bat [:bar :foo])
there's only one solution: graph them
hold on
nah, threading macro wins in every case over 2
I just realized I'm in #beginners
but I also realize that was a pretty noob question 😄
but I have been using Clojure since 2009
@jcromartie I tend to prefer (-> bat :bar :foo)
unless I want to have a default value, then I use (get-in [:bar :foo] default-v)
so far i’ve got this: https://gist.github.com/swizzard/aa1cf41c93bc476d5693caf2930f3891
@swizzard just a small thing, more elegant than try catch I think ^
protocol methods don't need hints, but if you use the method call via interop, you can type hint with the interface the protocol creates
eg. if you have (defprotocol Foo (bar [this]))
you can either use (bar x)
or (.bar ^this.ns.Foo x)
no i meant could i (defprotocol MyProtocol (thing [foo] ...))
and then do (defn my-func [^MyProtocol mp1 ^MyProtocol mp2] (do-something-with (thing mp1) (thing mp2)))
you could but it doesn't do anything useful
protocol methods don't need hints
(the function version, non interop, that is)
if you think about it - clojure knows that the argument to thing (a function) will also be a MyProtocol
as opposed to .thing, which could hypothetically come from somewhere unknowable to the compiler
which is what makes reflective code needed, which is why we have hinting