Fork me on GitHub
#clojure-uk
<
2017-04-19
>
Rachel Westmacott07:04:56

rcfotd:

-------------------------
clojure.core/empty
([coll])
  Returns an empty collection of the same category as coll, or nil

thomas07:04:44

@seancorfield I'd love to come, but as @yogidevbear has pointed out.. I have #brexit'ed already... and I am allergic to cats. But have fun anyway and enjoy blighty! :flag-gb:

kevin4207:04:26

bonjour 🙂

reborg09:04:08

(coll? (first {:a 1}))
true
(empty (first {:a 1}))
nil

dominicm09:04:50

@reborg why are map entry's nil when run via empty?

dominicm09:04:57

I suppose maybe an empty map entry doesn't make sense?

reborg09:04:48

@dominicm well, I don't have a logic answer, but the implementation says so: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/A MapEntry.java#L48

reborg09:04:36

for many other things, they are proper vectors ¯\(ツ)

seancorfield12:04:07

Ah, Heathrow....

maleghast12:04:32

Hello everyone... 🙂 Anyone got a quick answer to this: "What data type should I use to store lattitude and longitude in Datomic?"

maleghast12:04:48

(Yes I am going to ask in #datomic as well 😉 )

jonpither12:04:03

@stathissideris has trodden this path @maleghast - ping him

maleghast12:04:31

@jonpither - Thanks, will do 🙂

maleghast14:04:47

I am feeling stupid... I have a lazy-seq of vectors. I want to get all the vectors that are unique based on the first value. Any ideas?

minimal14:04:33

group-by first, then map first vals?

dominicm14:04:45

(I ❤️ medley. It's a sweet spot)

maleghast14:04:26

@dominicm Thx! @minimal I will look at that too and figure out which one fits best 🙂 Thanks

minimal14:04:46

ah group-by maybe not so useful for a big lazy-seq

minimal14:04:27

distinct-by looks nice

dominicm14:04:04

@minimal yeah, you picked up on my worry: large lazy sequences 😛

maleghast14:04:56

Right, I think I will look at medley in that case 🙂

dominicm14:04:09

distinct-by is very efficient, uses volatiles under the surface.

minimal14:04:51

yeah the source is interesting

maleghast14:04:18

I was just looking at that...

maleghast14:04:46

I think I may have a simpler / pure core solution in my particular use-case, actually... If I get the first 5 items in each vector and then turn the resulting seq into a set I will have my de-dupe, but I am going to hang onto medley for the future...

dominicm14:04:05

@maleghast Oh, you only wanted to dedupe the values inside the vector.

dominicm14:04:20

I thought you wanted to de-dupe the vectors.

maleghast14:04:46

No I want to de-dupe the vectors, but the vectors are duplicated across the first five values and once I am down to de-dupe I only want the first 5 values

maleghast14:04:17

(set (reduce (fn [acc coll] (cons (vec (take 5 coll)) acc)) '() (rest coll)))

dominicm14:04:19

I'm completely lost. 🙂 But that's okay. If it works.

maleghast14:04:28

^^ that should do it...

maleghast14:04:35

As ever, talking about the problem with other people makes the solution come to the fore - thanks both!

yogidevbear15:04:30

In my ColdFusion slack group we have a Friday puzzle channel where someone will occasionally post a coding puzzle. Someone posted this about an hour ago: https://gist.github.com/ryanguill/06ec5681ecff5ea2497f8ebcbcab3e33 I'd be really interested to see what a Clojure solution might look like if anyone here is interested in trying to solve it when they have some spare time.

dominicm15:04:06

I think a core.logic solution would look pretty good…

maleghast16:04:13

I was wondering if anyone has a better / more clojuric approach to "fixing" CSV data that is actually needed to be (let's say) Doubles than things like this:

(->> station-data-raw
     (map #(assoc % :station/elevation (Double/parseDouble (get % :station/elevation))))
     (map #(assoc % :station/latitude (Double/parseDouble (get % :station/latitude))))
     (map #(assoc % :station/longitude (Double/parseDouble (get % :station/longitude)))))

gjnoonan19:04:05

ColdFusion, now there's a blast from the past, bringing up some memories (both good and bad)

yogidevbear19:04:32

@gjnoonan, indeed. You might appreciate this simple_smile I mentioned it on that slack group this morning: >After learning a little bit of Clojure (which uses immutable data structures), seeing mutable CF code like this makes me feel really dirty: >`arguments.user = get( arguments.user.getUserID() );`

yogidevbear19:04:24

And a friend fairly pointed out that: >Sure, but isn't one of the major points of CF that it's loosely typed and mutable?

yogidevbear20:04:25

You get what you get from the tools you "choose" to use

yogidevbear20:04:06

I say "choose" as, with work situations, you don't always actually get a choice (at least not when you're setting out on a career). Sometimes the choices are made for you

reborg20:04:57

not a lot of spare time @yogidevbear but look for powersets and then filter them when the sum is the number you want 🙂

reborg20:04:02

you should come up with 5/6 line of clojure with at least a recursive call

yogidevbear20:04:02

Thanks @reborg. I'll look into that. I also don't have much spare time at the moment 🙂 When I'm not doing my day job, I'm doing some moonlighting and trying to get an online system going for my wife's business which is opening in about a month 😂