diff options
author | MainShayne233 <shaynetremblay@gmail.com> | 2019-09-29 22:30:41 -0400 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-10-01 10:14:39 +0100 |
commit | f5995d3490dd5e17d31c68bdd69eed3dbe121528 (patch) | |
tree | 1c81648acb1afd5930a3373284d460fc75c8deb8 /src | |
parent | dbb13018f405b98140e52206158b94e744efcc24 (diff) | |
download | gleam_stdlib-f5995d3490dd5e17d31c68bdd69eed3dbe121528.tar.gz gleam_stdlib-f5995d3490dd5e17d31c68bdd69eed3dbe121528.zip |
Implement string.compare/2
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/string.gleam | 4 | ||||
-rw-r--r-- | src/gleam_stdlib.erl | 12 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index 9714220..9c5791c 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -1,5 +1,6 @@ import gleam/iodata import gleam/list +import gleam/order pub external fn length(String) -> Int = "string" "length" @@ -7,6 +8,9 @@ pub external fn lowercase(String) -> String = "string" "lowercase" pub external fn uppercase(String) -> String = "string" "uppercase" +pub external fn compare(String, String) -> order.Order = + "gleam_stdlib" "compare_strings" + pub fn reverse(string) { string |> iodata.new diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl index 3bb762d..03f26e6 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_atom/1, - decode_pair/1, decode_list/1, decode_field/2, parse_int/1, parse_float/1]). + decode_pair/1, decode_list/1, decode_field/2, parse_int/1, parse_float/1, compare_strings/2]). expect_equal(Actual, Expected) -> ?assertEqual(Expected, Actual). expect_not_equal(Actual, Expected) -> ?assertNotEqual(Expected, Actual). @@ -90,3 +90,13 @@ parse_float(String) -> _ -> {error, nil} end. + +compare_strings(Lhs, Rhs) -> + if + Lhs == Rhs -> + eq; + Lhs < Rhs -> + lt; + true -> + gt + end. |