Skip to content

Commit

Permalink
Merge pull request #432 from Uthar/master
Browse files Browse the repository at this point in the history
add CONCATENATE
  • Loading branch information
davazp authored Mar 29, 2022
2 parents 9837658 + c55c0ad commit ffccdb1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/sequence.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,19 @@
(funcall result-collector (apply function args))
(apply function args)))))

(defun check-sequence-type-specifier (specifier)
(unless (member specifier '(vector string list))
(error "Not a valid sequence type specifier")))

(defun concatenate (result-type &rest sequences)
(check-sequence-type-specifier result-type)
(let ((iterators (mapcar #'make-iterator sequences))
(result-collector (make-collector result-type)))
(dolist (it iterators)
(do ((arg (funcall it) (funcall it)))
((eq *iterator-done* arg))
(funcall result-collector arg)))
(funcall result-collector)))

;;; remove duplicates
(defun %remove-duplicates (seq from-end test test-not key start end)
Expand Down
18 changes: 18 additions & 0 deletions tests/seq.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,24 @@
(list acc result))
'((3 2 1) t))

;;; CONCATENATE
(test-equal
(concatenate 'string "all" " " "together" " " "now")
"all together now")

(test-equal
(concatenate 'list "ABC" '(d e f) #(1 2 3) "1011")
'(#\A #\B #\C D E F 1 2 3 #\1 #\0 #\1 #\1))

(test-equal
(concatenate 'list)
nil)

(test-equal
(handler-case
(concatenate '(vector * 2) "a" "bc")
(error () :signalled))
:signalled)


;;; REMOVE-DUPLICATES
Expand Down

0 comments on commit ffccdb1

Please sign in to comment.