aboutsummaryrefslogtreecommitdiff
path: root/src/gleam__stdlib.erl
diff options
context:
space:
mode:
authorMainShayne233 <shaynetremblay@hotmail.com>2019-04-05 18:51:13 -0400
committerLouis Pilfold <louis@lpil.uk>2019-04-07 08:54:47 +0000
commit673e9e907093bd448db3b108b3d654c13cdc66f7 (patch)
tree5d1b50f5ffb80b35c5d8a7c033e769f6337a1893 /src/gleam__stdlib.erl
parente6fc269473f9b60e12a3c4eb4d2e17d0bd0c8f4a (diff)
downloadgleam_stdlib-673e9e907093bd448db3b108b3d654c13cdc66f7.tar.gz
gleam_stdlib-673e9e907093bd448db3b108b3d654c13cdc66f7.zip
Implement parse_int
Diffstat (limited to 'src/gleam__stdlib.erl')
-rw-r--r--src/gleam__stdlib.erl11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/gleam__stdlib.erl b/src/gleam__stdlib.erl
index 8e288c0..7ee4ba8 100644
--- a/src/gleam__stdlib.erl
+++ b/src/gleam__stdlib.erl
@@ -6,7 +6,7 @@
atom_create_from_string/1, atom_to_string/1, map_fetch/2,
iodata_append/2, iodata_prepend/2, identity/1, decode_int/1,
decode_string/1, decode_bool/1, decode_float/1, decode_thunk/1,
- decode_tuple/1, decode_list/1, decode_field/2]).
+ decode_tuple/1, decode_list/1, decode_field/2, parse_int/1]).
expect_equal(Actual, Expected) -> ?assertEqual(Expected, Actual).
expect_not_equal(Actual, Expected) -> ?assertNotEqual(Expected, Actual).
@@ -69,3 +69,12 @@ decode_field(Data, Key) ->
_ ->
decode_error_msg(io_lib:format("a map with key `~p`", [Key]), Data)
end.
+
+parse_int(String) ->
+ case string:to_integer(binary:bin_to_list(String)) of
+ {Integer, []} ->
+ {ok, Integer};
+
+ _ ->
+ {error, parse_error}
+ end.