diff --git a/README.md b/README.md index ec1b8a7..780f941 100644 --- a/README.md +++ b/README.md @@ -2034,10 +2034,9 @@ if the first element should sort before the second. #### -list `(&rest args)` -Return a list with `args`. - -If first item of `args` is already a list, simply return `args`. If -not, return a list with `args` as elements. +Return a list based on `args`. +If the first item of `args` is already a list, simply return it. +Otherwise, return a list with `args` as elements. ```el (-list 1) ;; => '(1) diff --git a/dash.el b/dash.el index e65a8d0..2303681 100644 --- a/dash.el +++ b/dash.el @@ -2515,13 +2515,11 @@ if the first element should sort before the second." `(-sort (lambda (it other) ,form) ,list)) (defun -list (&rest args) - "Return a list with ARGS. - -If first item of ARGS is already a list, simply return ARGS. If -not, return a list with ARGS as elements." + "Return a list based on ARGS. +If the first item of ARGS is already a list, simply return it. +Otherwise, return a list with ARGS as elements." (declare (pure t) (side-effect-free t)) - (let ((arg (car args))) - (if (listp arg) arg args))) + (if (listp (car args)) (car args) args)) (defun -repeat (n x) "Return a new list of length N with each element being X. diff --git a/dash.texi b/dash.texi index 3aea063..bf1bd7b 100644 --- a/dash.texi +++ b/dash.texi @@ -3116,10 +3116,9 @@ if the first element should sort before the second. @anchor{-list} @defun -list (&rest args) -Return a list with @var{args}. - -If first item of @var{args} is already a list, simply return @var{args}. If -not, return a list with @var{args} as elements. +Return a list based on @var{args}. +If the first item of @var{args} is already a list, simply return it. +Otherwise, return a list with @var{args} as elements. @example @group diff --git a/dev/examples.el b/dev/examples.el index a7a95ed..0715e20 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -926,7 +926,12 @@ value rather than consuming a list to produce a single value." (-list 1) => '(1) (-list 1 2 3) => '(1 2 3) (-list '(1 2 3)) => '(1 2 3) - (-list '((1) (2))) => '((1) (2))) + (-list '((1) (2))) => '((1) (2)) + (-list) => () + (-list ()) => () + (-list () 1) => () + (-list '(())) => '(()) + (-list '(() 1)) => '(() 1)) (defexamples -fix (-fix (lambda (l) (-non-nil (--mapcat (-split-at (/ (length it) 2) it) l))) '((1 2 3 4 5 6))) => '((1) (2) (3) (4) (5) (6))