Fork me on GitHub
#clojure-uk
<
2019-05-29
>
dominicm06:05:26

I really didn't want to get out of bed today, but I was in bed reasonably early. I'm so tired still.

thomas07:05:16

morning, tomorrow and Friday off due to Ascension Day. can't wait... lots of prod problems at the moment :face_vomiting:

dominicm07:05:16

ascension day? Sounds like a cult to me :D What is it?

thomas07:05:33

it is the day Jesus went to heaven.

thomas07:05:31

he does so every year 40 days after Easter

dharrigan07:05:37

Sounds like better time keeping than british trains

😂 4
dominicm08:05:42

It's strange how different countries have different christianity.

rickmoynihan08:05:38

I guess if you export anything you need to adapt it to adapt it to regional customs; religion is probably one of the first examples of that.

rickmoynihan08:05:29

I’ve heard one of the factors of Buddhism’s proliferation in the east over Hinduism was that it was essentially Hinduism stripped down to its essentials for export. In particular I think it was decoupled somewhat from Indian culture and the caste system. Hugely simplifying things of course.

thomas08:05:01

and the split between (Roman) Catholic and Protestant made a big difference as well.

thomas08:05:58

and Orthodox Christians being different again.

👍 4
djtango09:05:52

IIRC Jesus was born actually born around Spring time but the Roman Church decided to move it to Winter to align it better with the harvest festival [citation needed]

djtango09:05:27

so it's mostly humans being humans

djtango09:05:17

China and Korea celebrate Lunar New Year, while Japan decided to use the Gregorian Calendar but in all three cases the festival is pretty big (and is basically again roughly near Christmas)

jasonbell10:05:55

Or as Kris Kristofferson put it, “Jesus was a Capricorn” 🙂

dharrigan10:05:51

is there a channel that can offer some code review/suggestions? As the only one here in the office playing with clojure, I'm unsure if what I'm doing is good or not - just want to get some feedback on a very simple project that queries a REST API and displays results

practicalli-johnny12:05:14

There is also #code-reviews channel

dharrigan12:05:09

thanks John! 🙂

dharrigan10:05:17

I'll stick it on github and perhaps get some solicitation from this venerable channel

dharrigan11:05:08

So, here's a little plaything, to help me learn. I'm wondering if is fine. The thing that sorta irks me, is the call to (first dps) twice, at line 32 and 33. Is there a better, more idomatic way of writing this?

dharrigan11:05:32

(btw, if you want to check it out, there are tests that run with example json files)

djtango11:05:12

any reason you need loop recur there?

dharrigan11:05:01

I'm building up a new map of values, based upon another map (which contains far too many values)

djtango11:05:27

from what I can see you're just walking the delivery points

dharrigan11:05:33

so for each delivery point, extract out only the keys I'm interested in and build up a new map

djtango11:05:44

right but does that need loop recur ?

dharrigan11:05:02

I don't know 🙂 My experience isn't tremendous 🙂

djtango11:05:31

sorry I'm trying not to spell out my thoughts in case you may get the chance to see improvements yourself

djtango11:05:32

if that makes sense

dharrigan11:05:49

Of coursee, you're pointing the finger, not taking me by the hand 🙂

dharrigan11:05:00

I think you're trying to suggest a map function?

jasonbell11:05:16

Wondering if select-keys would make things simpler and I’m not sure of why the loop/recur I’d personally go for a map.

djtango11:05:29

can you rewrite it to use map

dharrigan11:05:38

Thanks! I'll give it a whirl 🙂

dharrigan11:05:43

(jase and dj)

djtango11:05:01

if you are doing an element-wise transformation where each transformation can be thought of as being independent map is usually the one to reach for

jasonbell11:05:07

Very high level ideas, be aware I’ve not seen the data.

dharrigan11:05:00

(there's example data in the resources/test folder)

djtango11:05:36

if you want to process a sequence where you have access to some intermediate state or do something to combine each individual element then it might be a reduce

djtango11:05:09

do you not care about the other throughfares?

dharrigan11:05:35

Not at this point in time, I'm assuming just one atm.

mccraigmccraig11:05:50

@dharrigan looks like you maybe want something like (->> delivery_points (map delivery-point->address) (reduce conj [])) instead of the loop

dominicm11:05:38

reduce conj [] is just mapv?

mccraigmccraig13:05:24

doh, yeah, i repeatedly forget about mapv

Ben Hammond12:05:24

or (apply vector

dominicm12:05:06

I just mean that map is already happening :)

dominicm12:05:52

maybe we need spectre for this?

danielneal12:05:31

cc @bronsa is a bit of an expert maybe he can chime in

😂 4
practicalli-johnny12:05:35

surely we need a transducer for this 🙂

dominicm12:05:32

I'm glad someone said it

dharrigan12:05:35

re: my postcode thingie, thanks everyone! learnt a lot. I've updated it now and it's much simpler

dharrigan12:05:14

Yup, definately learnt a lot

djtango12:05:41

looks good 👍

dharrigan12:05:49

tests still pass 🙂

dharrigan12:05:56

So, the take-away is that if I see a loop...recur, then perhaps I should look to see if a map(v) may be more suitable first?

practicalli-johnny13:05:05

I found starting from loop recur and then refactoring to higher abstractions has been a useful way to understand those abstractions. For example, I did this in for the first Advent of Code challenge https://www.youtube.com/watch?v=opM7fU7IAV8&amp;list=PLy9I_IfUBzKJSgctCJaRYcnF6kZdiZ5ku&amp;index=6

practicalli-johnny13:05:56

I also do examples of going from loop recur to higher abstractions in https://github.com/jr0cket/four-clojure

practicalli-johnny13:05:11

Number 30 and 53 are interesting examples

danielneal12:05:17

I guess or anyone of the built in sequence functions...

danielneal12:05:53

I think someone built a tool that finds functions based of input and output but I can't remember what it's called

danielneal13:05:22

ah yeah that's it

rickmoynihan13:05:24

@dharrigan > So, the take-away is that if I see a loop...recur, then perhaps I should look to see if a map(v) may be more suitable first? as @danieleneal says, if you’re reaching for loop/`recur` look to the whole sequence api; as it depends why you’re wanting to loop in the first place. e.g. typically - If you want to apply a transformation to each element reach for map/`mapv` - If you’re looking to remove items, look at things like distinct, set, filter, remove, keep… - If you want to apply a side effect for each element reach for run! / doseq / doall… - If you want to produce a single compound value from many look for specialised functions first, then at reduce - If you want to produce a sequence of values that depend on the previous value look at iterate… - If you need to manipulate something stateful into being a sequence-like thing look at lazy-seq or a transducers. There are many many more — for example you might also wonder about using transducers etc; but hopefully the above will give you some clues. Btw the code you have at the moment looks reasonable.

❤️ 8
dominicm13:05:23

^ this is the useful answer

rickmoynihan13:05:12

Oh and also loop/`recur` is occasionally exactly the right tool for the job, but it’s usually only the best option for lower level stuff… e.g. if you’re doing interop; or implementing transducers that do interop, that kinda thing. If you’re looking to do that someone has probably done it for you and put it in a library

dharrigan13:05:06

thanks again! man! everyone is very helpful

dharrigan13:05:11

have a 🍰 everyone!

rickmoynihan13:05:35

I think everyone’s just excited to have an on topic question for a change 😉

🇬🇧 8
djtango13:05:42

TIL iterate

Wes Hall17:05:58

Holy shit! I am away for a couple of hours and you guys start talking about Clojure!! 😉

😂 8
jasonbell18:05:36

But now you’re back @wesley.hall it’s all back to normal 🙂

Wes Hall18:05:29

Hah! Looks like I jinxed it!