DEV Community

Cover image for Taking n first elements from a list in Clojure
Marcos Henrique
Marcos Henrique

Posted on

6 3

Taking n first elements from a list in Clojure

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 



Enter fullscreen mode Exit fullscreen mode

Thanks for your time 🤗

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️