Elisp: Sequence. Take, Drop, Slice
Take First N
seq-take-
(seq-take SEQUENCE N)take first n.
(seq-take (vector 1 2 3 4 5) 3) ;; [1 2 3]
seq-take-while-
(seq-take-while PRED SEQUENCE)take elements until PRED returns
nil.(seq-take-while (lambda (x) (< x 4)) (vector 1 2 3 4 5)) ;; [1 2 3]
Remove First N
seq-drop→ remove first n.seq-drop-while→ remove first n, with a condition to stop.
Get Subsequence (aka slice)
seq-subseq-
(seq-subseq SEQUENCE START &optional END)Get a subsequence specified by start index and end index (exclude the end index). End index default to get all.
Index can be negative. It means count from right.
(seq-subseq (vector 0 1 2 3 4 5 6 7) 3) ;; [3 4 5 6 7] ;; not including end (seq-subseq (vector 0 1 2 3 4 5 6 7) 3 6) ;; [3 4 5]