aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/int.gleam5
-rw-r--r--src/gleam/list.gleam19
-rw-r--r--src/gleam/map.gleam9
-rw-r--r--src/gleam__stdlib.erl4
4 files changed, 11 insertions, 26 deletions
diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam
index 2fed6bd..7a83fba 100644
--- a/src/gleam/int.gleam
+++ b/src/gleam/int.gleam
@@ -1,9 +1,6 @@
import gleam/order
-pub enum NotAnInt =
- | NotAnInt
-
-pub external fn parse(String) -> Result(Int, NotAnInt) = "gleam__stdlib" "parse_int";
+pub external fn parse(String) -> Result(Int, Nil) = "gleam__stdlib" "parse_int";
pub external fn to_string(Int) -> String = "erlang" "integer_to_binary"
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index ed63a4b..2df547c 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -2,14 +2,7 @@ import gleam/int
import gleam/order
import gleam/pair
-pub enum Empty =
- | Empty
-
-pub enum NotFound =
- | NotFound
-
-pub enum LengthMismatch =
- | LengthMismatch
+pub struct LengthMismatch {}
// Using the Erlang C BIF implementation.
//
@@ -32,14 +25,14 @@ pub fn contains(list, elem) {
pub fn head(list) {
case list {
- | [] -> Error(Empty)
+ | [] -> Error(Nil)
| [x | _] -> Ok(x)
}
}
pub fn tail(list) {
case list {
- | [] -> Error(Empty)
+ | [] -> Error(Nil)
| [_ | xs] -> Ok(xs)
}
}
@@ -157,7 +150,7 @@ pub fn fold_right(list, acc, fun) {
pub fn find(haystack, f) {
case haystack {
- | [] -> Error(NotFound)
+ | [] -> Error(Nil)
| [x | rest] ->
case f(x) {
| Ok(x) -> Ok(x)
@@ -213,10 +206,10 @@ pub fn intersperse(list, elem) {
pub fn at(list, i) {
case i < 0 {
- | True -> Error(NotFound)
+ | True -> Error(Nil)
| False ->
case list {
- | [] -> Error(NotFound)
+ | [] -> Error(Nil)
| [x | rest] ->
case i == 0 {
| True -> Ok(x)
diff --git a/src/gleam/map.gleam b/src/gleam/map.gleam
index 935f3cb..b46590d 100644
--- a/src/gleam/map.gleam
+++ b/src/gleam/map.gleam
@@ -5,9 +5,6 @@ import gleam/pair
pub external type MapDict(key, value);
-pub enum NotFound =
- | NotFound
-
pub external fn size(MapDict(k, v)) -> Int
= "maps" "size"
@@ -27,7 +24,7 @@ pub fn has_key(map, key) {
pub external fn new() -> MapDict(key, value)
= "maps" "new"
-pub external fn fetch(MapDict(key, value), key) -> Result(value, NotFound)
+pub external fn fetch(MapDict(key, value), key) -> Result(value, Nil)
= "gleam__stdlib" "map_fetch";
external fn erl_put(key, value, MapDict(key, value)) -> MapDict(key, value)
@@ -79,12 +76,10 @@ pub fn drop(map, keys) {
})
}
-pub external type NotFound;
-
pub fn update(dict, key, f) {
case fetch(dict, key) {
| Ok(value) -> put(dict, key, f(Ok(value)))
- | Error(_) -> put(dict, key, f(Error(NotFound)))
+ | Error(_) -> put(dict, key, f(Error(Nil)))
}
}
diff --git a/src/gleam__stdlib.erl b/src/gleam__stdlib.erl
index 55e847d..b9236ed 100644
--- a/src/gleam__stdlib.erl
+++ b/src/gleam__stdlib.erl
@@ -17,7 +17,7 @@ expect_is_error(A) -> ?assertMatch({error, _}, A).
map_fetch(Map, Key) ->
case maps:find(Key, Map) of
- error -> {error, not_found};
+ error -> {error, nil};
OkFound -> OkFound
end.
@@ -79,7 +79,7 @@ parse_int(String) ->
{ok, Integer};
_ ->
- {error, parse_error}
+ {error, nil}
end.
parse_float(String) ->