aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gen/src/gleam@any.erl5
-rw-r--r--gen/src/gleam@pair.erl20
-rw-r--r--gen/src/gleam@triple.erl16
-rw-r--r--gen/test/gleam@any_test.erl32
-rw-r--r--gen/test/gleam@triple_test.erl16
-rw-r--r--src/gleam/any.gleam4
-rw-r--r--src/gleam/atom.gleam4
-rw-r--r--src/gleam/list.gleam16
-rw-r--r--src/gleam/map.gleam7
-rw-r--r--src/gleam/pair.gleam31
-rw-r--r--src/gleam/triple.gleam20
-rw-r--r--src/gleam_stdlib.erl5
-rw-r--r--test/gleam/any_test.gleam30
-rw-r--r--test/gleam/list_test.gleam42
-rw-r--r--test/gleam/map_test.gleam135
-rw-r--r--test/gleam/pair_test.gleam46
-rw-r--r--test/gleam/result_test.gleam5
-rw-r--r--test/gleam/triple_test.gleam32
18 files changed, 151 insertions, 315 deletions
diff --git a/gen/src/gleam@any.erl b/gen/src/gleam@any.erl
index 9f2a8e6..2cedd83 100644
--- a/gen/src/gleam@any.erl
+++ b/gen/src/gleam@any.erl
@@ -1,7 +1,7 @@
-module(gleam@any).
-compile(no_auto_import).
--export([from/1, unsafe_coerce/1, string/1, int/1, float/1, atom/1, bool/1, thunk/1, list/2, pair/1, field/2]).
+-export([from/1, unsafe_coerce/1, string/1, int/1, float/1, atom/1, bool/1, thunk/1, list/2, field/2]).
from(A) ->
gleam_stdlib:identity(A).
@@ -36,8 +36,5 @@ list(Any, DecoderType) ->
fun(Capture1) -> gleam@list:traverse(Capture1, DecoderType) end
).
-pair(A) ->
- gleam_stdlib:decode_pair(A).
-
field(A, B) ->
gleam_stdlib:decode_field(A, B).
diff --git a/gen/src/gleam@pair.erl b/gen/src/gleam@pair.erl
index 0f8e8be..3c07918 100644
--- a/gen/src/gleam@pair.erl
+++ b/gen/src/gleam@pair.erl
@@ -3,22 +3,22 @@
-export([first/1, second/1, swap/1, map_first/2, map_second/2]).
-first(Tup) ->
- {A, _} = Tup,
+first(Pair) ->
+ {A, _} = Pair,
A.
-second(Tup) ->
- {_, A} = Tup,
+second(Pair) ->
+ {_, A} = Pair,
A.
-swap(Tup) ->
- {A, B} = Tup,
+swap(Pair) ->
+ {A, B} = Pair,
{B, A}.
-map_first(Tup, Fun) ->
- {A, B} = Tup,
+map_first(Pair, Fun) ->
+ {A, B} = Pair,
{Fun(A), B}.
-map_second(Tup, Fun) ->
- {A, B} = Tup,
+map_second(Pair, Fun) ->
+ {A, B} = Pair,
{A, Fun(B)}.
diff --git a/gen/src/gleam@triple.erl b/gen/src/gleam@triple.erl
deleted file mode 100644
index 62a32da..0000000
--- a/gen/src/gleam@triple.erl
+++ /dev/null
@@ -1,16 +0,0 @@
--module(gleam@triple).
--compile(no_auto_import).
-
--export([first/1, second/1, third/1]).
-
-first(Trip) ->
- {A, _, _} = Trip,
- A.
-
-second(Trip) ->
- {_, A, _} = Trip,
- A.
-
-third(Trip) ->
- {_, _, A} = Trip,
- A.
diff --git a/gen/test/gleam@any_test.erl b/gen/test/gleam@any_test.erl
index ed58ebf..b7e472d 100644
--- a/gen/test/gleam@any_test.erl
+++ b/gen/test/gleam@any_test.erl
@@ -1,7 +1,7 @@
-module(gleam@any_test).
-compile(no_auto_import).
--export([string_test/0, int_test/0, float_test/0, thunk_test/0, bool_test/0, atom_test/0, list_test/0, pair_test/0, field_test/0]).
+-export([string_test/0, int_test/0, float_test/0, thunk_test/0, bool_test/0, atom_test/0, list_test/0, field_test/0]).
string_test() ->
gleam@expect:equal(gleam@any:string(gleam@any:from(<<"">>)), {ok, <<"">>}),
@@ -117,36 +117,6 @@ list_test() ->
)
).
-pair_test() ->
- gleam@expect:equal(
- gleam@any:pair(gleam@any:from({1, []})),
- {ok, {gleam@any:from(1), gleam@any:from([])}}
- ),
- gleam@expect:equal(
- gleam@any:pair(gleam@any:from({<<"ok">>, <<"ok">>})),
- {ok, {gleam@any:from(<<"ok">>), gleam@any:from(<<"ok">>)}}
- ),
- gleam@expect:equal(
- gleam@result:then(
- gleam@result:then(
- gleam@any:pair(gleam@any:from({1, 2.0})),
- fun(X) ->
- gleam@result:map(
- gleam@any:int(gleam@pair:first(X)),
- fun(F) -> {F, gleam@pair:second(X)} end
- )
- end
- ),
- fun(X) ->
- gleam@result:map(
- gleam@any:float(gleam@pair:second(X)),
- fun(F) -> {gleam@pair:first(X), F} end
- )
- end
- ),
- {ok, {1, 2.0}}
- ).
-
field_test() ->
{ok, OkAtom} = gleam@atom:from_string(<<"ok">>),
{ok, ErrorAtom} = gleam@atom:from_string(<<"error">>),
diff --git a/gen/test/gleam@triple_test.erl b/gen/test/gleam@triple_test.erl
deleted file mode 100644
index b143e31..0000000
--- a/gen/test/gleam@triple_test.erl
+++ /dev/null
@@ -1,16 +0,0 @@
--module(gleam@triple_test).
--compile(no_auto_import).
-
--export([first_test/0, second_test/0, third_test/0]).
-
-first_test() ->
- gleam@expect:equal(gleam@triple:first({1, 2, 3}), 1),
- gleam@expect:equal(gleam@triple:first({[], <<"abc">>, 3}), []).
-
-second_test() ->
- gleam@expect:equal(gleam@triple:second({1, 2, 3}), 2),
- gleam@expect:equal(gleam@triple:second({[], <<"abc">>, 3}), <<"abc">>).
-
-third_test() ->
- gleam@expect:equal(gleam@triple:third({1, 2, 3}), 3),
- gleam@expect:equal(gleam@triple:third({[], <<"abc">>, 3}), 3).
diff --git a/src/gleam/any.gleam b/src/gleam/any.gleam
index 6384c89..a54f632 100644
--- a/src/gleam/any.gleam
+++ b/src/gleam/any.gleam
@@ -1,7 +1,6 @@
import gleam/list as list_mod
import gleam/atom
import gleam/result
-import gleam/pair.{Pair}
// `Any` data is data that we don"t know the type of yet.
// We likely get data like this from interop with Erlang, or from
@@ -47,8 +46,5 @@ pub fn list(from any, containing decoder_type) {
|> result.then(_, list_mod.traverse(_, decoder_type))
}
-pub external fn pair(from: Any) -> Result(Pair(Any, Any), String)
- = "gleam_stdlib" "decode_pair"
-
pub external fn field(from: Any, named: a) -> Result(Any, String)
= "gleam_stdlib" "decode_field"
diff --git a/src/gleam/atom.gleam b/src/gleam/atom.gleam
index e870178..b37ae14 100644
--- a/src/gleam/atom.gleam
+++ b/src/gleam/atom.gleam
@@ -1,8 +1,6 @@
pub external type Atom;
-pub enum AtomNotLoaded {
- AtomNotLoaded
-}
+pub struct AtomNotLoaded {}
pub external fn from_string(String) -> Result(Atom, AtomNotLoaded) =
"gleam_stdlib" "atom_from_string";
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index b0a601d..101e24e 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -1,10 +1,8 @@
import gleam/int
import gleam/order
-import gleam/pair.{Pair}
+import gleam/pair
-pub enum LengthMismatch {
- LengthMismatch
-}
+pub struct LengthMismatch {}
// Using the Erlang C BIF implementation.
//
@@ -198,7 +196,7 @@ pub fn zip(xs, ys) {
case xs, ys {
[], _ -> []
_, [] -> []
- [x | xs], [y | ys] -> [ Pair(x, y) | zip(xs, ys) ]
+ [x | xs], [y | ys] -> [ struct(x, y) | zip(xs, ys) ]
}
}
@@ -292,10 +290,10 @@ pub fn repeat(item a, times times) {
fn do_split(list, n, taken) {
case n <= 0 {
- True -> Pair(reverse(taken), list)
+ True -> struct(reverse(taken), list)
False ->
case list {
- [] -> Pair(reverse(taken), [])
+ [] -> struct(reverse(taken), [])
[x | xs] -> do_split(xs, n - 1, [x | taken])
}
}
@@ -307,10 +305,10 @@ pub fn split(list list, on target) {
fn do_split_while(list, f, acc) {
case list {
- [] -> Pair(reverse(acc), [])
+ [] -> struct(reverse(acc), [])
[x | xs] ->
case f(x) {
- False -> Pair(reverse(acc), list)
+ False -> struct(reverse(acc), list)
_ -> do_split_while(xs, f, [x | acc])
}
}
diff --git a/src/gleam/map.gleam b/src/gleam/map.gleam
index 49ca618..4f11f89 100644
--- a/src/gleam/map.gleam
+++ b/src/gleam/map.gleam
@@ -1,17 +1,16 @@
import gleam/any
import gleam/result
import gleam/list
-import gleam/pair.{Pair}
pub external type Map(key, value);
pub external fn size(Map(k, v)) -> Int
= "maps" "size"
-pub external fn to_list(Map(key, value)) -> List(Pair(key, value))
+pub external fn to_list(Map(key, value)) -> List(struct(key, value))
= "maps" "to_list"
-pub external fn from_list(List(Pair(key, value))) -> Map(key, value)
+pub external fn from_list(List(struct(key, value))) -> Map(key, value)
= "maps" "from_list"
external fn is_key(key, Map(key, v)) -> Bool
@@ -86,7 +85,7 @@ pub fn update(in map, update key, with fun) {
fn do_fold(list, initial, fun) {
case list {
[] -> initial
- [Pair(k, v) | tail] -> do_fold(tail, fun(k, v, initial), fun)
+ [struct(k, v) | tail] -> do_fold(tail, fun(k, v, initial), fun)
}
}
diff --git a/src/gleam/pair.gleam b/src/gleam/pair.gleam
index 7d6bc45..aaa336f 100644
--- a/src/gleam/pair.gleam
+++ b/src/gleam/pair.gleam
@@ -1,29 +1,24 @@
-pub struct Pair(a, b) {
- first: a
- second: b
-}
-
-pub fn first(tup) {
- let Pair(a, _) = tup
+pub fn first(pair) {
+ let struct(a, _) = pair
a
}
-pub fn second(tup) {
- let Pair(_, a) = tup
+pub fn second(pair) {
+ let struct(_, a) = pair
a
}
-pub fn swap(tup) {
- let Pair(a, b) = tup
- Pair(b, a)
+pub fn swap(pair) {
+ let struct(a, b) = pair
+ struct(b, a)
}
-pub fn map_first(of tup, with fun) {
- let Pair(a, b) = tup
- Pair(fun(a), b)
+pub fn map_first(of pair, with fun) {
+ let struct(a, b) = pair
+ struct(fun(a), b)
}
-pub fn map_second(of tup, with fun) {
- let Pair(a, b) = tup
- Pair(a, fun(b))
+pub fn map_second(of pair, with fun) {
+ let struct(a, b) = pair
+ struct(a, fun(b))
}
diff --git a/src/gleam/triple.gleam b/src/gleam/triple.gleam
deleted file mode 100644
index ef9f6ea..0000000
--- a/src/gleam/triple.gleam
+++ /dev/null
@@ -1,20 +0,0 @@
-pub struct Triple(a, b, c) {
- first: a
- second: b
- third: c
-}
-
-pub fn first(trip) {
- let Triple(a, _, _) = trip
- a
-}
-
-pub fn second(trip) {
- let Triple(_, a, _) = trip
- a
-}
-
-pub fn third(trip) {
- let Triple(_, _, a) = trip
- a
-}
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 95fa252..8a4a290 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_get/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, compare_strings/2]).
+ 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).
@@ -58,9 +58,6 @@ decode_bool(Data) -> decode_error_msg("a Bool", Data).
decode_thunk(Data) when is_function(Data, 0) -> {ok, Data};
decode_thunk(Data) -> decode_error_msg("a zero arity function", Data).
-decode_pair(Data = {_, _}) -> {ok, Data};
-decode_pair(Data) -> decode_error_msg("a 2 element tuple", Data).
-
decode_list(Data) when is_list(Data) -> {ok, Data};
decode_list(Data) -> decode_error_msg("a List", Data).
diff --git a/test/gleam/any_test.gleam b/test/gleam/any_test.gleam
index 21a10b5..dc0c859 100644
--- a/test/gleam/any_test.gleam
+++ b/test/gleam/any_test.gleam
@@ -4,7 +4,6 @@ import gleam/list
import gleam/expect
import gleam/result
import gleam/map
-import gleam/pair.{Pair}
pub fn string_test() {
""
@@ -188,34 +187,7 @@ pub fn list_test() {
|> expect.is_error
}
-pub fn pair_test() {
- Pair(1, [])
- |> any.from
- |> any.pair
- |> expect.equal(_, Ok(Pair(any.from(1), any.from([]))))
-
- Pair("ok", "ok")
- |> any.from
- |> any.pair
- |> expect.equal(_, Ok(Pair(any.from("ok"), any.from("ok"))))
-
- Pair(1, 2.0)
- |> any.from
- |> any.pair
- |> result.then(_, fn(x) {
- x
- |> pair.first
- |> any.int
- |> result.map(_, fn(f) { Pair(f, pair.second(x)) })
- })
- |> result.then(_, fn(x) {
- x
- |> pair.second
- |> any.float
- |> result.map(_, fn(f) { Pair(pair.first(x), f) })
- })
- |> expect.equal(_, Ok(Pair(1, 2.0)))
-}
+// TODO: struct2
pub fn field_test() {
let Ok(ok_atom) = atom.from_string("ok")
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam
index fcab9ce..a24fe5b 100644
--- a/test/gleam/list_test.gleam
+++ b/test/gleam/list_test.gleam
@@ -3,7 +3,7 @@ import gleam/list
import gleam/int
import gleam/float
import gleam/string
-import gleam/pair.{Pair}
+import gleam/pair
pub fn length_test() {
list.length([])
@@ -222,13 +222,13 @@ pub fn zip_test() {
|> expect.equal(_, [])
list.zip([1, 2, 3], [4, 5, 6])
- |> expect.equal(_, [Pair(1, 4), Pair(2, 5), Pair(3, 6)])
+ |> expect.equal(_, [struct(1, 4), struct(2, 5), struct(3, 6)])
list.zip([5, 6], [1, 2, 3])
- |> expect.equal(_, [Pair(5, 1), Pair(6, 2)])
+ |> expect.equal(_, [struct(5, 1), struct(6, 2)])
list.zip([5, 6, 7], [1, 2])
- |> expect.equal(_, [Pair(5, 1), Pair(6, 2)])
+ |> expect.equal(_, [struct(5, 1), struct(6, 2)])
}
pub fn strict_zip_test() {
@@ -240,9 +240,9 @@ pub fn strict_zip_test() {
list.strict_zip([1, 2, 3], [4, 5, 6])
|> expect.equal(_, Ok([
- Pair(1, 4),
- Pair(2, 5),
- Pair(3, 6),
+ struct(1, 4),
+ struct(2, 5),
+ struct(3, 6),
]))
list.strict_zip([5, 6], [1, 2, 3])
@@ -307,8 +307,8 @@ pub fn sort_test() {
}
pub fn index_map_test() {
- list.index_map([3, 4, 5], fn(i, x) { Pair(i, x) })
- |> expect.equal(_, [Pair(0, 3), Pair(1, 4), Pair(2, 5)])
+ list.index_map([3, 4, 5], fn(i, x) { struct(i, x) })
+ |> expect.equal(_, [struct(0, 3), struct(1, 4), struct(2, 5)])
let f = fn(i, x) {
string.append(x, int.to_string(i))
@@ -353,44 +353,44 @@ pub fn repeat_test() {
pub fn split_test() {
list.split([], 0)
- |> expect.equal(_, Pair([], []))
+ |> expect.equal(_, struct([], []))
list.split([0, 1, 2, 3, 4], 0)
- |> expect.equal(_, Pair([], [0, 1, 2, 3, 4]))
+ |> expect.equal(_, struct([], [0, 1, 2, 3, 4]))
list.split([0, 1, 2, 3, 4], -2)
- |> expect.equal(_, Pair([], [0, 1, 2, 3, 4]))
+ |> expect.equal(_, struct([], [0, 1, 2, 3, 4]))
list.split([0, 1, 2, 3, 4], 1)
- |> expect.equal(_, Pair([0], [1, 2, 3, 4]))
+ |> expect.equal(_, struct([0], [1, 2, 3, 4]))
list.split([0, 1, 2, 3, 4], 3)
- |> expect.equal(_, Pair([0, 1, 2], [3, 4]))
+ |> expect.equal(_, struct([0, 1, 2], [3, 4]))
list.split([0, 1, 2, 3, 4], 9)
- |> expect.equal(_, Pair([0, 1, 2, 3, 4], []))
+ |> expect.equal(_, struct([0, 1, 2, 3, 4], []))
}
pub fn split_while_test() {
list.split_while([], fn(x) { x <= 5 })
- |> expect.equal(_, Pair([], []))
+ |> expect.equal(_, struct([], []))
list.split_while([1, 2, 3, 4, 5], fn(x) { x <= 5 })
- |> expect.equal(_, Pair([1, 2, 3, 4, 5], []))
+ |> expect.equal(_, struct([1, 2, 3, 4, 5], []))
list.split_while([1, 2, 3, 4, 5], fn(x) { x == 2 })
- |> expect.equal(_, Pair([], [1, 2, 3, 4, 5]))
+ |> expect.equal(_, struct([], [1, 2, 3, 4, 5]))
list.split_while([1, 2, 3, 4, 5], fn(x) { x <= 3 })
- |> expect.equal(_, Pair([1, 2, 3], [4, 5]))
+ |> expect.equal(_, struct([1, 2, 3], [4, 5]))
list.split_while([1, 2, 3, 4, 5], fn(x) { x <= -3 })
- |> expect.equal(_, Pair([], [1, 2, 3, 4, 5]))
+ |> expect.equal(_, struct([], [1, 2, 3, 4, 5]))
}
pub fn key_find_test() {
- let proplist = [Pair(0, "1"), Pair(1, "2")]
+ let proplist = [struct(0, "1"), struct(1, "2")]
proplist
|> list.key_find(_, 0)
diff --git a/test/gleam/map_test.gleam b/test/gleam/map_test.gleam
index 4c7b371..def91be 100644
--- a/test/gleam/map_test.gleam
+++ b/test/gleam/map_test.gleam
@@ -1,12 +1,11 @@
import gleam/string
import gleam/expect
import gleam/map
-import gleam/pair.{Pair}
pub fn from_list_test() {
[
- Pair(4, 0),
- Pair(1, 0),
+ struct(4, 0),
+ struct(1, 0),
]
|> map.from_list
|> map.size
@@ -20,23 +19,23 @@ pub fn has_key_test() {
|> expect.false
[
- Pair(1, 0),
+ struct(1, 0),
]
|> map.from_list
|> map.has_key(_, 1)
|> expect.true
[
- Pair(4, 0),
- Pair(1, 0),
+ struct(4, 0),
+ struct(1, 0),
]
|> map.from_list
|> map.has_key(_, 1)
|> expect.true
[
- Pair(4, 0),
- Pair(1, 0),
+ struct(4, 0),
+ struct(1, 0),
]
|> map.from_list
|> map.has_key(_, 0)
@@ -55,8 +54,8 @@ pub fn new_test() {
pub fn get_test() {
let proplist = [
- Pair(4, 0),
- Pair(1, 1),
+ struct(4, 0),
+ struct(1, 1),
]
let m = map.from_list(proplist)
@@ -79,32 +78,32 @@ pub fn insert_test() {
|> map.insert(_, "b", 1)
|> map.insert(_, "c", 2)
|> expect.equal(_, map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]))
}
pub fn map_values_test() {
[
- Pair(1, 0),
- Pair(2, 1),
- Pair(3, 2),
+ struct(1, 0),
+ struct(2, 1),
+ struct(3, 2),
]
|> map.from_list
|> map.map_values(_, fn(k, v) { k + v })
|> expect.equal(_, map.from_list([
- Pair(1, 1),
- Pair(2, 3),
- Pair(3, 5),
+ struct(1, 1),
+ struct(2, 3),
+ struct(3, 5),
]))
}
pub fn keys_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.keys
@@ -113,9 +112,9 @@ pub fn keys_test() {
pub fn values_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.values
@@ -124,72 +123,72 @@ pub fn values_test() {
pub fn take_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.take(_, ["a", "b", "d"])
- |> expect.equal(_, map.from_list([Pair("a", 0), Pair("b", 1)]))
+ |> expect.equal(_, map.from_list([struct("a", 0), struct("b", 1)]))
}
pub fn drop_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.drop(_, ["a", "b", "d"])
- |> expect.equal(_, map.from_list([Pair("c", 2)]))
+ |> expect.equal(_, map.from_list([struct("c", 2)]))
}
pub fn merge_test() {
let a = map.from_list([
- Pair("a", 2),
- Pair("c", 4),
- Pair("d", 3),
+ struct("a", 2),
+ struct("c", 4),
+ struct("d", 3),
])
let b = map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
])
map.merge(a, b)
|> expect.equal(_, map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
- Pair("d", 3),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ struct("d", 3),
]))
map.merge(b, a)
|> expect.equal(_, map.from_list([
- Pair("a", 2),
- Pair("b", 1),
- Pair("c", 4),
- Pair("d", 3),
+ struct("a", 2),
+ struct("b", 1),
+ struct("c", 4),
+ struct("d", 3),
]))
}
pub fn delete_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.delete(_, "a")
|> map.delete(_, "d")
- |> expect.equal(_, map.from_list([Pair("b", 1), Pair("c", 2)]))
+ |> expect.equal(_, map.from_list([struct("b", 1), struct("c", 2)]))
}
pub fn update_test() {
let dict = map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
])
let inc_or_zero = fn(x) {
@@ -202,35 +201,35 @@ pub fn update_test() {
dict
|> map.update(_, "a", inc_or_zero)
|> expect.equal(_, map.from_list([
- Pair("a", 1),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 1),
+ struct("b", 1),
+ struct("c", 2),
]))
dict
|> map.update(_, "b", inc_or_zero)
|> expect.equal(_, map.from_list([
- Pair("a", 0),
- Pair("b", 2),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 2),
+ struct("c", 2),
]))
dict
|> map.update(_, "z", inc_or_zero)
|> expect.equal(_, map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
- Pair("z", 0),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ struct("z", 0),
]))
}
pub fn fold_test() {
let dict = map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
- Pair("d", 3),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ struct("d", 3),
])
let add = fn(_, v, acc) {
diff --git a/test/gleam/pair_test.gleam b/test/gleam/pair_test.gleam
index 4ec4f05..057c343 100644
--- a/test/gleam/pair_test.gleam
+++ b/test/gleam/pair_test.gleam
@@ -1,62 +1,62 @@
import gleam/expect
-import gleam/pair.{Pair}
+import gleam/pair
pub fn first_test() {
- Pair(1, 2)
+ struct(1, 2)
|> pair.first
|> expect.equal(_, 1)
- Pair("abc", [])
+ struct("abc", [])
|> pair.first
|> expect.equal(_, "abc")
}
pub fn second_test() {
- Pair(1, 2)
+ struct(1, 2)
|> pair.second
|> expect.equal(_, 2)
- Pair("abc", [])
+ struct("abc", [])
|> pair.second
|> expect.equal(_,[])
}
pub fn swap_test() {
- Pair(1, "2")
+ struct(1, "2")
|> pair.swap
- |> expect.equal(_, Pair("2", 1))
+ |> expect.equal(_, struct("2", 1))
}
pub fn map_first_test() {
let inc = fn(a) {
a + 1
}
- pair.map_first(Pair(1, 2), inc)
- |> expect.equal(_, Pair(2, 2))
+ pair.map_first(struct(1, 2), inc)
+ |> expect.equal(_, struct(2, 2))
- pair.map_first(Pair(8,2), inc)
- |> expect.equal(_, Pair(9, 2))
+ pair.map_first(struct(8,2), inc)
+ |> expect.equal(_, struct(9, 2))
- pair.map_first(Pair(0,-2), inc)
- |> expect.equal(_, Pair(1, -2))
+ pair.map_first(struct(0,-2), inc)
+ |> expect.equal(_, struct(1, -2))
- pair.map_first(Pair(-10, 20), inc)
- |> expect.equal(_, Pair(-9, 20))
+ pair.map_first(struct(-10, 20), inc)
+ |> expect.equal(_, struct(-9, 20))
}
pub fn map_second_test() {
let dec = fn(a) {
a - 1
}
- pair.map_second(Pair(1, 2), dec)
- |> expect.equal(_, Pair(1, 1))
+ pair.map_second(struct(1, 2), dec)
+ |> expect.equal(_, struct(1, 1))
- pair.map_second(Pair(8,2), dec)
- |> expect.equal(_, Pair(8, 1))
+ pair.map_second(struct(8,2), dec)
+ |> expect.equal(_, struct(8, 1))
- pair.map_second(Pair(0,-2), dec)
- |> expect.equal(_, Pair(0, -3))
+ pair.map_second(struct(0,-2), dec)
+ |> expect.equal(_, struct(0, -3))
- pair.map_second(Pair(-10, 20), dec)
- |> expect.equal(_, Pair(-10, 19))
+ pair.map_second(struct(-10, 20), dec)
+ |> expect.equal(_, struct(-10, 19))
}
diff --git a/test/gleam/result_test.gleam b/test/gleam/result_test.gleam
index d28b622..10d2cf6 100644
--- a/test/gleam/result_test.gleam
+++ b/test/gleam/result_test.gleam
@@ -1,6 +1,5 @@
import gleam/expect
import gleam/result
-import gleam/pair.{Pair}
pub fn is_ok_test() {
result.is_ok(Ok(1))
@@ -38,8 +37,8 @@ pub fn map_error_test() {
|> expect.equal(_, Ok(1))
Error(1)
- |> result.map_error(_, fn(x) { Pair("ok", x + 1) })
- |> expect.equal(_, Error(Pair("ok", 2)))
+ |> result.map_error(_, fn(x) { struct("ok", x + 1) })
+ |> expect.equal(_, Error(struct("ok", 2)))
}
pub fn flatten_test() {
diff --git a/test/gleam/triple_test.gleam b/test/gleam/triple_test.gleam
deleted file mode 100644
index 53ac7d0..0000000
--- a/test/gleam/triple_test.gleam
+++ /dev/null
@@ -1,32 +0,0 @@
-import gleam/expect
-import gleam/triple.{Triple}
-
-pub fn first_test() {
- Triple(1, 2, 3)
- |> triple.first
- |> expect.equal(_, 1)
-
- Triple([], "abc", 3)
- |> triple.first
- |> expect.equal(_, [])
-}
-
-pub fn second_test() {
- Triple(1, 2, 3)
- |> triple.second
- |> expect.equal(_, 2)
-
- Triple([], "abc", 3)
- |> triple.second
- |> expect.equal(_, "abc")
-}
-
-pub fn third_test() {
- Triple(1, 2, 3)
- |> triple.third
- |> expect.equal(_, 3)
-
- Triple([], "abc", 3)
- |> triple.third
- |> expect.equal(_, 3)
-}