Fork me on GitHub
#clojure-uk
<
2019-02-19
>
Conor08:02:38

If I want to use a goofy looking keyboard, it'll be my Model F (which hopefully isn't vapourware)

dominicm09:02:48

I really like keyboards which are vertical, I have thought about setting up extreme tilting for my ergodox

guy09:02:48

Morning 👋

guy09:02:21

Dumb clojure question of the day.

(->> some-coll
     (sort-by :year)
     (sort-by :type))
If you have a collection of things and you want them sorted by say year, then type, is this the best way to do it? It work’s but it seems like there must be a better way to do it. Any thoughts?

flefik09:02:11

guy, you mean the other way around right?

flefik09:02:47

(->> some-coll
     (sort-by :type)
     (sort-by :year))

guy09:02:58

Er potentially, but the output should look something like

[ {:type A :year 2014}
  {:type A :year 2016}
  {:type B :year 2013}
 {:type B :year 2017}]

guy09:02:08

i mean thats how it outputs it at the moment which is what i want

flefik09:02:17

well sort-by is guaranteed to be stable

flefik09:02:37

so in your example, (sort-by :year) will sort it by year

flefik09:02:52

then (sort-by :type) would sort it by type

flefik09:02:10

so that would get the output you want, type then year

flefik09:02:20

which is the opposite of what you wrote 🙂

guy09:02:41

ah ok sorry!

flefik09:02:07

but if the list is long, you’d probably want to implement your own comparator so that you don’t have to (partially) sort the list twice

flefik09:02:14

just to make it a little faster

flefik09:02:54

you can use normal sort for that

guy09:02:58

ok cool, so my question has evolved into, using comparator’s to sort a collection of items. Thanks I’ll do a google and try again 😄

flefik09:02:22

this is the guide you want https://clojure.org/guides/comparators

5
👍 5
guy09:02:46

wow nice i didn’t even know about that haha. I should really check the clojure docs more 😅

flefik09:02:06

🙂

👍 5
dominicm09:02:12

@guy fwiw, you can compare vectors, so I think this would work: (sort-by (juxt :type :year) coll)

👍 5
dominicm09:02:01

user=> (sort-by (juxt :type :year) [{:type "B" :year 2017} {:type "B" :year 2013} {:type "A" :year 2016} {:type "A" :year 2014}])
({:type "A", :year 2014} {:type "A", :year 2016} {:type "B", :year 2013} {:type "B", :year 2017})

guy09:02:20

what does fwiw mean sorry? 😅

guy09:02:26

and thanks ill check it out!

yogidevbear09:02:29

>for what it's worth

guy09:02:49

aha! thanks 😄

yogidevbear10:02:38

@guy, +1 to @U09LZR36F's solution. As an aside, I extended the initial collection to have a bit more of a mixed example:

(def m
  [{:type "A", :year 2014}
   {:type "A", :year 2012}
   {:type "B", :year 2017}
   {:type "B", :year 2013}
   {:type "A", :year 2019}
   {:type "B", :year 2016}])
I think your initial approach of sorting by :year and then :type was correct:
user=> (clojure.pprint/pprint (->> m (sort-by :year) (sort-by :type)))
({:type "A", :year 2012}
 {:type "A", :year 2014}
 {:type "A", :year 2019}
 {:type "B", :year 2013}
 {:type "B", :year 2016}
 {:type "B", :year 2017})
Compared to doing it by :type and then :year
user=> (clojure.pprint/pprint (->> m (sort-by :type) (sort-by :year)))
({:type "A", :year 2012}
 {:type "B", :year 2013}
 {:type "A", :year 2014}
 {:type "B", :year 2016}
 {:type "B", :year 2017}
 {:type "A", :year 2019})
And using Dominic's solution 🙂
user=> (clojure.pprint/pprint (sort-by (juxt :type :year) m))
({:type "A", :year 2012}
 {:type "A", :year 2014}
 {:type "A", :year 2019}
 {:type "B", :year 2013}
 {:type "B", :year 2016}
 {:type "B", :year 2017})

flefik10:02:43

oh i didnt know you could pass vecs to sort-by

danielneal10:02:40

I think its more passing a function that returns a vector, which is then used for the sorting

danielneal10:02:20

or something

guy11:02:36

😮 thanks all!

maleghast13:02:44

Hello All 🙂

guy13:02:56

👋 sup

otfrom13:02:15

lol. It is quiet in here when we aren't moaning about #brexit 😉

otfrom13:02:59

I'm enjoying Star Trek Discovery season 2 and am happy that The Expanse seasons 2&3 are now on Amazon Prime.

flefik13:02:53

oh wow i’ve been waiting diligently for expanse s2 to come to Netflix.

danm13:02:12

We've just finished watching Lucifer S3, which will now migrate the other way to Netflix

mccraigmccraig13:02:30

i tried lucifer - found it quite disappointing and didn't get beyond S1

danm13:02:26

It's not particularly clever, and has got a bit samey by the end of S3, but it's something we can watch together and poke fun at

danm13:02:45

Whereas The Punisher and Daredevil we actually paid proper attention to and thought were good 😉

mccraigmccraig13:02:14

aha, i'll check those out then 🙂

danm13:02:59

Missed a good Haskell talk at LambdaLounge last night @alex.lynham 🙂

alexlynham13:02:22

@otfrom I’m super worried that there’s no way the expanse can catch up with the books before it gets cancelled

alexlynham13:02:48

@carr0t yeah was gutted, helped to organise it and all

otfrom13:02:42

surely the books are designed to just spin out forever so it will never catch up

otfrom13:02:12

the authors are probably enjoying getting all the money for it. 🙂

jasonbell14:02:42

Watchlist: Currently on Goliath on Prime but did the full five series of Luther, the Russian Doll (which I loved)

jasonbell14:02:53

May have to go back to Fargo 1-3 again.

danm14:02:46

We got 4 episodes into Russian Doll last night

danm14:02:00

Nice that they're only 25-30 mins each, instead of an hour or more

minimal14:02:15

Kantaro is a recent find and it’s gold

agile_geek14:02:29

I've almost finished Russian Doll but I need to put any other series on hold.... got a 40 min conference talk and two blogs to write to deadlines!

alexlynham15:02:08

on my lunch break I finished my newest most garish emacs theme hack https://github.com/the-frey/emacs/blob/cyberpunk_overhaul/README.md

alexlynham15:02:35

(there’s a screenshot on the actual GH page)

dominicm15:02:43

what's the russian doll about?

dominicm15:02:51

we just started "the good place"

👍 5
guy15:02:19

I really love the good place

danm15:02:03

Groundhog Day but more 'gritty'

dominicm15:02:55

what's groundhog day about

guy15:02:36

Cult classic 😄

guy15:02:04

Not really sure how to summarise it without spoiling it 😅 , defo worth a watch though

agile_geek16:02:47

Cult classic 😄

agile_geek16:02:49

Cult classic 😄

agile_geek16:02:50

Cult classic 😄

agile_geek16:02:51

Cult classic 😄

agile_geek16:02:52

Cult classic 😄

agile_geek16:02:52

Cult classic 😄

agile_geek16:02:53

Cult classic 😄

agile_geek16:02:54

Cult classic 😄

guy19:02:26

@U05390U2P :thinking_face:

guy19:02:44

Aggressive 😂

dominicm15:02:06

Assume I'm an uncultured animal 🙂

yogidevbear17:02:52

more that we're all older animals 😉

danm15:02:33

Female Russian (ish. Russian sounding name, American sounding accent) software engineer with a penchant for drugs and partying keeps dying and resetting to the same point in time, waking up in the bathroom at her birthday party with memory of the future events up to her death

😱 15
🤯 5
mccraigmccraig15:02:24

anyone got any reccs for elementary clojure learning resources ?

guy15:02:52

I think theres a clojure bridge github somewhere too :thinking_face:

guy15:02:17

Hmm maybe its outdated now

guy15:02:29

I remember there being a really nice tutorial when i looked at it like 4 years ago

practicalli-johnny18:02:07

This ClojureBridge workshop is a bit more up to date https://clojurebridgelondon.github.io/workshop/

practicalli-johnny18:02:24

I’ll be adding more content soon. If you want some video content, take a look at my YouTube playlist https://www.youtube.com/playlist?list=PLy9I_IfUBzKJSgctCJaRYcnF6kZdiZ5ku

alexlynham15:02:45

clojure for the brave and true isn’t bad

alexlynham15:02:28

although it depends on the goal

alexlynham15:02:10

I ended up doing that web apps workshop for (mainly) python folks and had a lot more success

mccraigmccraig15:02:15

yeah, it's for ilayda - she's learning to program!

mccraigmccraig15:02:22

which workshop is that

alexlynham15:02:27

that blog has a dump of all the gists and links you need

mccraigmccraig15:02:56

nice - that looks spot on

alexlynham15:02:01

there’s an interactive repl with clojure basics and a heroku ready repo with a ring app in it

alexlynham15:02:20

takes about 2hrs to get through

seancorfield17:02:05

Anyone watching The Umbrella Academy? We're about five or six eps in and loving it.

dominicm17:02:21

I'm a broken record: what's it about?

😂 10
dominicm17:02:31

I'm hoping someone can add something to our list

dominicm17:02:40

Discovery is such a hard problem with media

dominicm18:02:52

Sounds a bit like watchmen

guy19:02:55

its pretty good

guy19:02:03

not really my cup of tea but worth a watch