Fork me on GitHub
#beginners
<
2021-03-28
>
zackteo10:03:02

Hello! Could someone explain to how I should think about (apply map ....) I understand apply and map but don't quite understand how something like (apply map list ((0 1 2) (3 4 5) (6 7 8))` ;; => ((0 3 6) (1 4 7) (2 5 8)) works

Mno10:03:42

Map can take multiple seqs from which it takes an element of each sequence and passes it to the function

Mno10:03:17

You could do: (map list [1 2 3] [4 5 6]) and get ((1 4)(2 5)(3 6))

Mno10:03:29

In the first iteration it takes 1 and 4 and passes it to list so it would end up (list 1 4)

Mno10:03:59

Or to give another example you can do (apply map + [[1 2] [3 4]) and get ((+ 1 3) (+ 2 4)) and then (4 6)

zackteo10:03:42

Got it! Thank you!!

Mno12:03:22

My pleasure 🙂

sova-soars-the-sora23:03:11

any tips on making paginated links ? example: collection of 500 maps each with a timestamp. show first 50 elements on page 1 page 1: 0-50, page2: 51-100... page 3: 101-150... etc and have 10 clickable "page" buttons to go between them is there take for specific ranges in a sequence? I notice there is subvec ...

dpsutton23:03:59

this is normally done with some implicit page size and a way to efficiently skip items in the collection. if you're just using a clojure datastructure, skip and take can get this with obviously linear performance

sova-soars-the-sora23:03:28

oh I see. like (drop 50 (take 50 coll))

sova-soars-the-sora23:03:38

or maybe I did that backwards...

sova-soars-the-sora23:03:53

(take 50 (drop 50 coll))

sova-soars-the-sora23:03:09

linear performance is probably Ok.