From 010c4cf5e2c1688218382bf86b2352d7d853526c Mon Sep 17 00:00:00 2001 From: eksperimental Date: Mon, 28 Jan 2019 14:06:06 +0700 Subject: [PATCH 1/2] IEx h: sort results by arity The results were not sorted, when calling: h Module.function_name Example: ``` iex)> h :erlang.float_to_binary :erlang.float_to_binary/2 @spec float_to_binary(float, options) :: binary() when float: float(), options: [option], option: {:decimals, decimals :: 0..253} | {:scientific, decimals :: 0..249} | :compact Module was compiled without docs. Showing only specs. :erlang.float_to_binary/1 @spec float_to_binary(float) :: binary() when float: float() Module was compiled without docs. Showing only specs. ``` Now the results are sorted by arity. --- lib/iex/lib/iex/introspection.ex | 1 + lib/iex/test/iex/helpers_test.exs | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/iex/lib/iex/introspection.ex b/lib/iex/lib/iex/introspection.ex index d7d305eba13..049950e3d9f 100644 --- a/lib/iex/lib/iex/introspection.ex +++ b/lib/iex/lib/iex/introspection.ex @@ -283,6 +283,7 @@ defmodule IEx.Introspection do true -> module.module_info(:exports) end + |> Enum.sort_by(fn {_function_name, arity} -> arity end) result = for {^function, arity} <- exports, diff --git a/lib/iex/test/iex/helpers_test.exs b/lib/iex/test/iex/helpers_test.exs index 41ed813abd6..fc07469a40e 100644 --- a/lib/iex/test/iex/helpers_test.exs +++ b/lib/iex/test/iex/helpers_test.exs @@ -343,6 +343,12 @@ defmodule IEx.HelpersTest do """ assert capture_io(fn -> h(:timer.send_interval()) end) == """ + * :timer.send_interval/2 + + @spec send_interval(time, message) :: {:ok, tRef} | {:error, reason} + when time: time(), message: term(), tRef: tref(), reason: term() + + Module was compiled without docs. Showing only specs. * :timer.send_interval/3 @spec send_interval(time, pid, message) :: {:ok, tRef} | {:error, reason} @@ -352,12 +358,6 @@ defmodule IEx.HelpersTest do tRef: tref(), reason: term() - Module was compiled without docs. Showing only specs. - * :timer.send_interval/2 - - @spec send_interval(time, message) :: {:ok, tRef} | {:error, reason} - when time: time(), message: term(), tRef: tref(), reason: term() - Module was compiled without docs. Showing only specs. """ end From d46687e91e60ede0f3575484e00755b04ea404f2 Mon Sep 17 00:00:00 2001 From: eksperimental Date: Mon, 28 Jan 2019 21:10:51 +0700 Subject: [PATCH 2/2] Use Enum.sort() --- lib/iex/lib/iex/introspection.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iex/lib/iex/introspection.ex b/lib/iex/lib/iex/introspection.ex index 049950e3d9f..36b84f7ea46 100644 --- a/lib/iex/lib/iex/introspection.ex +++ b/lib/iex/lib/iex/introspection.ex @@ -283,7 +283,7 @@ defmodule IEx.Introspection do true -> module.module_info(:exports) end - |> Enum.sort_by(fn {_function_name, arity} -> arity end) + |> Enum.sort() result = for {^function, arity} <- exports,