list*

added
1.0

ns
clojure.core

type
function

(list* args) (list* a args) (list* a b args) (list* a b c args) (list* a b c d & more)

Creates a new seq containing the items prepended to the rest, the
last of which will be treated as a sequence.

                ;; `list*` function:
user=> (list* 1 [2 3])
(1 2 3)
user=> (list* 1 2 [3 4])
(1 2 3 4)

;; compared to regular `list` function:
user=> (list 1 [2 3])
(1 [2 3])
user=> (list 1 2 [3 4])
(1 2 [3 4])

;; Corner cases:
user=> (list* nil [1 2])
(nil 1 2)
user=> (list* 1 nil)
(1)
user=> (list* () [1 2])
(() 1 2)
user=> (list* 1 ())
(1)

            
                ;;Prepend a map to a list
user=> (list* {:name "Anne"} [{:city "NJ"}]) 
({:name "Anne"} {:city "NJ"})
            
                ;; Useful if you want to get all the arguments of a function into a list
(defn args-to-list [a b c & args]
  (list* a b c args))

user=> (args-to-list 1 2 3 4 5 6)
(1 2 3 4 5 6)

; same as list, but it expects the last element to be a sequence which is then unpacked