Elisp: Sequence Map Insert
Insert / Delete / Modify Items (At Arbitrary Positions)
seq-mapcat
-
(seq-mapcat FUNCTION SEQUENCE &optional TYPE)
Apply a function that return a list (can be empty list), but insert its elements into the sequence.
- if the function return a empty list (nil), the item is removed.
- if the function return a list of single item, the item is replaced.
- if the function return a non-empty list, the items are inserted.
💡 TIP: This function is more general than map because map cannot delete items, and more general than filter because filter cannot add item nor transform the items you want.
(setq xx (vector "aa" "bb" "m,n" "cc" )) ;; if the string contains a comma, split it into 2 items (seq-mapcat (lambda (x) (if (string-match "," x) (split-string x ",") (list x))) xx) ;; ("aa" "bb" "m" "n" "cc")
Elisp, sequence functions
- Elisp: Sequence Type
- Elisp: Sequence Functions
- Elisp: Sequence, Take, Drop, Slice
- Elisp: Map to Sequence
- Elisp: Foreach (Side-Effect)
- Elisp: Sequence Iteration, Conditional Exit
- Elisp: Sequence Filter
- Elisp: Sequence Map Insert
- Elisp: Sequence Iteration
- Elisp: Sequence Find
- Elisp: Sequence, Sort, Reverse
- Elisp: Sequence Join, Convert
- Elisp: Sequence Union, Intersection, Difference
- Elisp: More Sequence Functions
- Elisp: Destructure Binding (seq-setq, seq-let)