Fork me on GitHub
#beginners
<
2019-07-08
>
kari.pahula13:07:53

Why's (->> 1 #(+ % 2)) value "#object" something and not 3? What should I use instead?

clojurians97113:07:46

@kari.pahula

user=> (->> 1 (#(+ % 2)))
3

bronsa13:07:12

user=> (macroexpand '(->> 1 #(+ % 2)))
(fn* [p1__2#] (+ p1__2# 2) 1)

bronsa13:07:42

user=> (macroexpand '(->> 1 (#(+ % 2))))
((fn* [p1__141#] (+ p1__141# 2)) 1)

jayesh-bhoot13:07:04

@kari.pahula (->> 1 #(+ % 2)) evaluates to #(+ % 2 1)

bronsa13:07:45

no it doesn't

bronsa13:07:53

look at the macroexpansion from above :)

clojurians97113:07:11

It evaluates to a function that adds 2 to the argument, ignores the result and returns 1:

user=> ((->> 1 #(+ % 2)) 100)
1

jayesh-bhoot13:07:53

Ok so my first attempt of venturing in the clojure wild failed 😉

jayesh-bhoot13:07:56

Thanks for clearin up

jamesthibaudeau13:07:59

Do you need to provide the function? or would

(->> 1 (+ 2))
accomplish what you are trying to do?

kari.pahula13:07:16

My example was just a simpler version of what I'm trying to do.

noisesmith17:07:50

as-> and ->> are designed so they can be invoked inside -> and between those options you should never need an inline anonymous function inside a threading macro

noisesmith17:07:23

also you can simplify things with a def bound or let bound function of course

noisesmith17:07:55

but between all of those, extra parens to make a function literal work is the worst IMHO

finn.volkel19:07:18

Is there a channel for cider?

dpsutton19:07:28

#cider @finn.volkel

iagwanderson20:07:35

hi, how can I use toucan to perform a like operation inside the where clause?

noisesmith21:07:09

@iagwanderson for a start, it looks like all of toucan's queries are done via honeysql, though I can't tell you precisely how you would use like in honeysql, I know it is supported

noisesmith21:07:16

given how other things work in honeysql the first thing I would try is where [:like :f.a "baz"]

iagwanderson21:07:54

yes, actually what solve the problem was something similar where ["like" :f.a "baz%"]

noisesmith21:07:06

I wouldn't be surprised if it accepted :like instead of "like" given how the templating works

noisesmith21:07:16

but I don't have it set up to try and you do

iagwanderson21:07:56

I tried and didn't work for some reason