Fork me on GitHub
#beginners
<
2016-04-01
>
adamkowalski05:04:42

Hey can you guys recommend any good tutorials for building a whole web app from start to finish with clojure/script? I feel like the vast majority of tutorials are either very specific to one topic, or are very trivial and essentially just get a basic server up with a hello world response. I was hoping for something similar to https://www.meteor.com/tutorials/blaze/creating-an-app where they build a whole app including getting a server, database, and even basic authentication working. Then they hook it all up on the client side and demonstrate how to talk back and forth over the server and even show you how to do optimistic updates.

urbanslug08:04:16

Can I destructure a lambda that uses #()

rauh08:04:26

@urbanslug: You could with let but in that case (fn would be 2 characters shorter

urbanslug08:04:02

So it seems simple_smile

urbanslug08:04:47

Clojure’s map is not cool. Sucks that I can’t make it return another type.

sveri09:04:04

@urbanslug: What would you want it to return?

urbanslug09:04:49

@sveri: A map. into {} … did it.

sveri09:04:53

I remember when starting with clojure I had these kind of thoughts too. Today map is perfectly fine as it is, given there is a mapv too. Are there languages that handle map differenlty?

lmergen09:04:43

is there a less ugly solution to 'force' evaluation of a sequence, similar to (into [] (map fn xs)) ? or is it actually a sign of bad design if this is an issue ?

sveri10:04:25

@lmergen: Most of the times I just use mapv. Doing webstuff for instance will evaluate sequences anyway when passing them to the client or using them in a template. Also I like working with vecs more than with lazy seqs.

mull10:04:19

If you want map to return another type then you’re probably looking for reduce no?

sveri10:04:06

I would argue that map and reduce are not about return types, but about the operations they excecute.

lmergen11:04:43

exactly, and a sequence or vector is about the representation

lmergen11:04:33

having said that, it's perfectly possible to build a reduce operation that converts from a lazy seq to a vector

sveri11:04:47

@lmergen: This is true, but this has another problem, readability. Seeing a reduce operation I would expect some reduction. Walking through the code to see that it converts a lazy seq into a vec is therefore a code smell, from my POV.

lmergen11:04:58

yes exactly

lmergen11:04:09

i was just pointing out that it is possible

lmergen11:04:15

but it's definitely not the way to go

Chris O’Donnell12:04:07

@lmergen: You've basically described transducers. They split sequence operations into a transform step and a reduction step.

lmergen12:04:48

@codonnell: awesome, i didn't have the time to dive into them, so they always sounded a bit scary...

Chris O’Donnell12:04:08

the book clojure applied has a really nice introduction to them. that's what really made them click for me, personally.

lmergen12:04:09

but as with most things in FP, they always sound more complicated than they are simple_smile

Chris O’Donnell12:04:51

yeah, it's all about getting a simple model for them in your head before trying to understand the details

lmergen12:04:09

yes... and academics are not very good at choosing simple words to describe simple models simple_smile

prozz15:04:04

hello. i got this little problem: function should put \n every nth char in string params: “K.K.”, 2 result: "K.\nK." my solution: (apply str (map (partial apply str) (interpose "\n" (partition 2 "K.K.")))) seem bloated. any tip how to do it easier way?

rauh15:04:45

@prozz: I'd use flatten instead of the map

prozz15:04:43

@rauh: indeed works

prozz15:04:43

(apply str (flatten (interpose "\n" (partition 2 "K.K."))))

prozz15:04:18

thanks for the tip 😉

noisesmith16:04:30

sveri: reduce can create outputs larger or smaller than the input, and to claim it shouldn't seems very narrow minded to me. Similarly mapcat can produce a sequence shorter or longer than the input sequence. These are inherent properties of reduce and mapcat, they are key parts of what makes these useful functions, and I will continue using reduce and mapcat regardless of the size comparison of input and output collections.

noisesmith16:04:15

perhaps this issue could be avoided if I do (def fold reduce)

noisesmith16:04:25

and then proceed to use fold

sveri16:04:57

@noisesmith: That was basically what I meant, I dont differ them on their return type, but on what they do.

noisesmith16:04:07

this is the statement I was disagreeing with: "Walking through the code to see that it converts a lazy seq into a vec is therefore a code smell, from my POV.", perhaps I misinterpreted

sveri16:04:36

@noisesmith: Ah ok, I thought you meant the other statement I meant before. I just meant that I would not want to see reduce being used to convert a lazy seq into a vec, while the content remains the same. That was everything.

noisesmith16:04:48

sveri: oh, ok, yeah I would expect (into [] ...) and not a reduce

noisesmith16:04:56

or just vec even

sveri16:04:22

exactly, that was the whole point.

noisesmith16:04:33

aha! sorry for the rant then

sveri17:04:00

No problem, sometimes it is hard to understand what I write, it was my fault most probably.