Taking n first elements from a list in Clojure

github logo ・1 min read

Faster than a hadron collider 🤓


We have a list of orders and want to get the first 2 elements

How we can do that?

(def order [
 {:id 15 :quantity 3 :price 5}
 {:id 3 :quantity 24 :price 1}
 {:id 7 :quantity 6 :price 9}])

(println (take 2 order)) ;take [0, 1] from list of elements
(println (nth order 2)) ;better than (get _ _) to get elements from a list 

Thanks for your time 🤗

twitter logo DISCUSS
Classic DEV Post from Oct 31

What Alternative Text Editors Does DEV Use? (Not VS Code 🐱‍👓)

Marcos Henrique profile image
"Programming isn't about what you know; it's about what you can figure out.” - Chris Pine (println (🔮 reality)) Learning public adept.

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️