From 2a024ef3784bf93f91ca1b27e07dbe1988212ae1 Mon Sep 17 00:00:00 2001 From: eksperimental Date: Sun, 8 Jul 2018 00:30:43 +0700 Subject: [PATCH] Improve specs and documentation for List.wrap/1 --- lib/elixir/lib/list.ex | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/elixir/lib/list.ex b/lib/elixir/lib/list.ex index 68a03423489..88677fee28f 100644 --- a/lib/elixir/lib/list.ex +++ b/lib/elixir/lib/list.ex @@ -390,10 +390,10 @@ defmodule List do end @doc """ - Wraps the argument in a list. + Wraps `term` in a list if this is not list. - If the argument is already a list, returns the list. - If the argument is `nil`, returns an empty list. + If `term` is already a list, it returns the list. + If `term` is `nil`, it returns an empty list. ## Examples @@ -407,7 +407,11 @@ defmodule List do [] """ - @spec wrap(list | any) :: list + @spec wrap(nil) :: [] + @spec wrap(list) :: list when list: maybe_improper_list() + @spec wrap(term) :: nonempty_list(term) when term: any() + def wrap(term) + def wrap(list) when is_list(list) do list end