aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinoas <mail@inoas.com>2022-08-10 21:26:46 +0200
committerLouis Pilfold <louis@lpil.uk>2022-08-11 09:56:08 +0100
commit6cf891dff792d5685c6328aedae54693c92a61dc (patch)
tree7f7c54e9137b4faa86609301b2b3e7f366c7e709
parentaa6a32fdb1d8f43db1c9957c9966f4c46b898229 (diff)
downloadgleam_stdlib-6cf891dff792d5685c6328aedae54693c92a61dc.tar.gz
gleam_stdlib-6cf891dff792d5685c6328aedae54693c92a61dc.zip
simplify code
-rw-r--r--src/gleam_stdlib.erl28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index c06854a..5d83e9d 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -349,9 +349,9 @@ inspect(Binary) when is_binary(Binary) ->
["<<", lists:join(", ", Segments), ">>"]
end;
inspect(List) when is_list(List) ->
- case inspect_list(firstCall, properList, List) of
- {properList, Elements} -> ["[", Elements, "]"];
- {improperList, Elements} -> ["//erl[", Elements, "] %% improper list"]
+ case inspect_list(List) of
+ {proper, Elements} -> ["[", Elements, "]"];
+ {improper, Elements} -> ["//erl[", Elements, "]"]
end;
inspect(Any) when is_tuple(Any) % Record constructors
andalso is_atom(element(1, Any))
@@ -377,18 +377,16 @@ inspect(Any) when is_function(Any) ->
inspect(Any) ->
["//erl(", io_lib:format("~p", [Any]), ")"].
-inspect_list(_recursionCount, properList, []) ->
- {properList, []};
-inspect_list(firstCall, properList, [Head]) ->
- {properList, [inspect(Head)]};
-inspect_list(firstCall, properList, [First | Rest]) ->
- {ListKind, Elements} = inspect_list(nthCall, properList, Rest),
- {ListKind, [inspect(First) | Elements]};
-inspect_list(nthCall, properList, [First | Rest]) ->
- {ListKind, Elements} = inspect_list(nthCall, properList, Rest),
- {ListKind, [<<", ">>, inspect(First) | Elements]};
-inspect_list(nthCall, properList, ImproperTail) ->
- {improperList, [<<" | ">>, inspect(ImproperTail)]}.
+
+inspect_list([]) ->
+ {proper, []};
+inspect_list([Head]) ->
+ {proper, [inspect(Head)]};
+inspect_list([First | Rest]) when is_list(Rest) ->
+ {Kind, Inspected} = inspect_list(Rest),
+ {Kind, [inspect(First), <<", ">> | Inspected]};
+inspect_list([First | ImproperTail]) ->
+ {improper, [inspect(First), <<" | ">>, inspect(ImproperTail)]}.
float_to_string(Float) when is_float(Float) ->
erlang:iolist_to_binary(io_lib_format:fwrite_g(Float)).