Fork me on GitHub
#beginners
<
2017-06-28
>
a1309:06:51

isn't it the same as

(constantly true)
?

curlyfry12:06:39

@a13 It also has built-in gen support like the other core predicates

jcromartie16:06:30

I am having a hard time deciding between (:foo (:bar bat)) vs (-> bat :bar :foo)

mobileink23:06:24

jcromartie: fwiw i like -> for aesthetic reasons, but also because it makes it really easy to inject other stuff in the pipeline during development.

gonewest81800:06:10

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.

jcromartie16:06:02

just for the case of two calls

jstokes16:06:50

a third option to complicate (i think this is a matter of preference, really) (get-in bat [:bar :foo])

jcromartie16:06:23

there's only one solution: graph them

jcromartie16:06:11

nah, threading macro wins in every case over 2

curlyfry16:06:08

My guess is ‘get-in‘ is the most idiomatic as it was created for this use case

jcromartie16:06:29

I just realized I'm in #beginners

jcromartie16:06:45

but I also realize that was a pretty noob question 😄

jcromartie16:06:55

but I have been using Clojure since 2009

seancorfield16:06:13

@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)

swizzard18:06:57

i’m trying to implement an idiomatic-ish version of processing’s PVector

swizzard18:06:02

i’m not sure if that’s the right way to go, however

noisesmith18:06:26

@swizzard just a small thing, more elegant than try catch I think ^

swizzard18:06:35

i didn’t know about that 🙂

swizzard19:06:21

can you use protocols as type hints?

noisesmith19:06:50

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

noisesmith19:06:03

eg. if you have (defprotocol Foo (bar [this])) you can either use (bar x) or (.bar ^this.ns.Foo x)

swizzard19:06:11

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)))

noisesmith19:06:16

you could but it doesn't do anything useful

noisesmith19:06:23

protocol methods don't need hints

noisesmith19:06:37

(the function version, non interop, that is)

noisesmith19:06:28

if you think about it - clojure knows that the argument to thing (a function) will also be a MyProtocol

noisesmith19:06:53

as opposed to .thing, which could hypothetically come from somewhere unknowable to the compiler

noisesmith19:06:20

which is what makes reflective code needed, which is why we have hinting