aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2019-03-16 15:29:01 +0000
committerLouis Pilfold <louis@lpil.uk>2019-03-16 15:29:01 +0000
commitde6dca34edf5ab52bc7eab02745c59d8c0dd777d (patch)
tree57d893900d43d9fcfaa4a5697292649bb3147c91 /src
parent211984b23adae77cf4cf87b2a15e307df2fd7619 (diff)
downloadgleam_stdlib-de6dca34edf5ab52bc7eab02745c59d8c0dd777d.tar.gz
gleam_stdlib-de6dca34edf5ab52bc7eab02745c59d8c0dd777d.zip
Custom error types over unit
Diffstat (limited to 'src')
-rw-r--r--src/bool.gleam8
-rw-r--r--src/gleam__stdlib.erl3
-rw-r--r--src/iodata.gleam1
-rw-r--r--src/list.gleam2
-rw-r--r--src/map.gleam15
5 files changed, 15 insertions, 14 deletions
diff --git a/src/bool.gleam b/src/bool.gleam
index 89d39f0..b4e5287 100644
--- a/src/bool.gleam
+++ b/src/bool.gleam
@@ -27,16 +27,16 @@ test negate {
// test compare {
// compare(True, True)
-// |> expect:equal(_, Eq)
+// |> expect:equal(_, order:Eq)
// compare(True, False)
-// |> expect:equal(_, Gt)
+// |> expect:equal(_, order:Gt)
// compare(False, False)
-// |> expect:equal(_, Lt)
+// |> expect:equal(_, order:Lt)
// compare(False, True)
-// |> expect:equal(_, Gt)
+// |> expect:equal(_, order:Gt)
// }
pub fn max(a, b) {
diff --git a/src/gleam__stdlib.erl b/src/gleam__stdlib.erl
index 4af95eb..25abb25 100644
--- a/src/gleam__stdlib.erl
+++ b/src/gleam__stdlib.erl
@@ -4,7 +4,6 @@
-export([expect_equal/2, expect_not_equal/2, expect_true/1, expect_false/1, map_fetch/2,
iodata_append/2, iodata_prepend/2, identity/1]).
-
expect_equal(A, Expected) -> ?assertEqual(Expected, A).
expect_not_equal(A, Expected) -> ?assertNotEqual(Expected, A).
expect_true(A) -> ?assert(A).
@@ -12,7 +11,7 @@ expect_false(A) -> ?assertNot(A).
map_fetch(Map, Key) ->
case maps:find(Key, Map) of
- error -> {error, {}};
+ error -> {error, not_found};
OkFound -> OkFound
end.
diff --git a/src/iodata.gleam b/src/iodata.gleam
index 7bdecec..2d14ed0 100644
--- a/src/iodata.gleam
+++ b/src/iodata.gleam
@@ -1,4 +1,3 @@
-import any
import expect
pub external type Iodata;
diff --git a/src/list.gleam b/src/list.gleam
index dea8a19..527ec51 100644
--- a/src/list.gleam
+++ b/src/list.gleam
@@ -1,6 +1,6 @@
import expect
-pub enum Error =
+pub enum Empty =
| Empty
// Using the Erlang C BIF implementation.
diff --git a/src/map.gleam b/src/map.gleam
index a8f024f..56b4a6b 100644
--- a/src/map.gleam
+++ b/src/map.gleam
@@ -4,6 +4,9 @@ import expect
pub external type Map(key, value);
+pub enum NotFound =
+ | NotFound
+
pub external fn size(Map(k, v)) -> Int
= "maps" "size"
@@ -41,7 +44,7 @@ test has_key {
[
{1, 0},
- ]
+ ]
|> from_list
|> has_key(_, 1)
|> expect:true
@@ -49,7 +52,7 @@ test has_key {
[
{4, 0},
{1, 0},
- ]
+ ]
|> from_list
|> has_key(_, 1)
|> expect:true
@@ -91,7 +94,7 @@ test new {
// |> expect:equal(_, from_list([{"name", "Jane"}]))
// }
-pub external fn fetch(Map(key, value), key) -> Result(a, value)
+pub external fn fetch(Map(key, value), key) -> Result(value, NotFound)
= "gleam__stdlib" "map_fetch";
test fetch {
@@ -109,9 +112,9 @@ test fetch {
|> fetch(_, 1)
|> expect:equal(_, Ok(1))
- // map
- // |> fetch(_, 2)
- // |> expect:equal(_, Error(())
+ map
+ |> fetch(_, 2)
+ |> expect:equal(_, Error(NotFound))
}
external fn erl_put(key, value, Map(key, value)) -> Map(key, value)