diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-12-23 14:55:31 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-12-23 14:55:31 +0000 |
commit | 1b8fd2a16ca588dfa53b644a312f21dee4c610e4 (patch) | |
tree | 786b660ccdb0a900bf1cb98bb0b3959902ea2b43 | |
parent | 0c165bcee923e698d0a4c46f221f2e62f2a6d5ab (diff) | |
download | gleam_stdlib-1b8fd2a16ca588dfa53b644a312f21dee4c610e4.tar.gz gleam_stdlib-1b8fd2a16ca588dfa53b644a312f21dee4c610e4.zip |
Update for Gleam v0.6.0
-rw-r--r-- | gen/test/gleam@dynamic_test.erl | 10 | ||||
-rw-r--r-- | src/gleam/atom.gleam | 4 | ||||
-rw-r--r-- | src/gleam/iodata.gleam | 2 | ||||
-rw-r--r-- | src/gleam/list.gleam | 14 | ||||
-rw-r--r-- | src/gleam/map.gleam | 6 | ||||
-rw-r--r-- | src/gleam/order.gleam | 2 | ||||
-rw-r--r-- | src/gleam/pair.gleam | 16 | ||||
-rw-r--r-- | test/gleam/dynamic_test.gleam | 12 | ||||
-rw-r--r-- | test/gleam/list_test.gleam | 40 | ||||
-rw-r--r-- | test/gleam/map_test.gleam | 134 | ||||
-rw-r--r-- | test/gleam/pair_test.gleam | 56 | ||||
-rw-r--r-- | test/gleam/result_test.gleam | 4 |
12 files changed, 151 insertions, 149 deletions
diff --git a/gen/test/gleam@dynamic_test.erl b/gen/test/gleam@dynamic_test.erl index df03621..6f99980 100644 --- a/gen/test/gleam@dynamic_test.erl +++ b/gen/test/gleam@dynamic_test.erl @@ -171,20 +171,20 @@ field_test() -> element_test() -> {ok, OkAtom} = gleam@atom:from_string(<<"ok">>), - OkOneStruct = {OkAtom, 1}, + OkOneTuple = {OkAtom, 1}, gleam@expect:equal( - gleam@dynamic:element(gleam@dynamic:from(OkOneStruct), 0), + gleam@dynamic:element(gleam@dynamic:from(OkOneTuple), 0), {ok, gleam@dynamic:from(OkAtom)} ), gleam@expect:equal( - gleam@dynamic:element(gleam@dynamic:from(OkOneStruct), 1), + gleam@dynamic:element(gleam@dynamic:from(OkOneTuple), 1), {ok, gleam@dynamic:from(1)} ), gleam@expect:is_error( - gleam@dynamic:element(gleam@dynamic:from(OkOneStruct), 2) + gleam@dynamic:element(gleam@dynamic:from(OkOneTuple), 2) ), gleam@expect:is_error( - gleam@dynamic:element(gleam@dynamic:from(OkOneStruct), -1) + gleam@dynamic:element(gleam@dynamic:from(OkOneTuple), -1) ), gleam@expect:is_error(gleam@dynamic:element(gleam@dynamic:from(1), 0)), gleam@expect:is_error( diff --git a/src/gleam/atom.gleam b/src/gleam/atom.gleam index b37ae14..9b69127 100644 --- a/src/gleam/atom.gleam +++ b/src/gleam/atom.gleam @@ -1,6 +1,8 @@ pub external type Atom; -pub struct AtomNotLoaded {} +pub type AtomNotLoaded { + AtomNotLoaded +} pub external fn from_string(String) -> Result(Atom, AtomNotLoaded) = "gleam_stdlib" "atom_from_string"; diff --git a/src/gleam/iodata.gleam b/src/gleam/iodata.gleam index 3a7f5f2..ed993d1 100644 --- a/src/gleam/iodata.gleam +++ b/src/gleam/iodata.gleam @@ -36,7 +36,7 @@ pub external fn uppercase(Iodata) -> Iodata = "string" "uppercase" pub external fn reverse(Iodata) -> Iodata = "string" "reverse" -enum Direction { +type Direction { All } diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index 101e24e..221311a 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -2,7 +2,9 @@ import gleam/int import gleam/order import gleam/pair -pub struct LengthMismatch {} +pub type LengthMismatch { + LengthMismatch +} // Using the Erlang C BIF implementation. // @@ -196,7 +198,7 @@ pub fn zip(xs, ys) { case xs, ys { [], _ -> [] _, [] -> [] - [x | xs], [y | ys] -> [ struct(x, y) | zip(xs, ys) ] + [x | xs], [y | ys] -> [ tuple(x, y) | zip(xs, ys) ] } } @@ -290,10 +292,10 @@ pub fn repeat(item a, times times) { fn do_split(list, n, taken) { case n <= 0 { - True -> struct(reverse(taken), list) + True -> tuple(reverse(taken), list) False -> case list { - [] -> struct(reverse(taken), []) + [] -> tuple(reverse(taken), []) [x | xs] -> do_split(xs, n - 1, [x | taken]) } } @@ -305,10 +307,10 @@ pub fn split(list list, on target) { fn do_split_while(list, f, acc) { case list { - [] -> struct(reverse(acc), []) + [] -> tuple(reverse(acc), []) [x | xs] -> case f(x) { - False -> struct(reverse(acc), list) + False -> tuple(reverse(acc), list) _ -> do_split_while(xs, f, [x | acc]) } } diff --git a/src/gleam/map.gleam b/src/gleam/map.gleam index d103d01..00e6f1c 100644 --- a/src/gleam/map.gleam +++ b/src/gleam/map.gleam @@ -6,10 +6,10 @@ 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(struct(key, value)) +pub external fn to_list(Map(key, value)) -> List(tuple(key, value)) = "maps" "to_list" -pub external fn from_list(List(struct(key, value))) -> Map(key, value) +pub external fn from_list(List(tuple(key, value))) -> Map(key, value) = "maps" "from_list" external fn is_key(key, Map(key, v)) -> Bool @@ -84,7 +84,7 @@ pub fn update(in map, update key, with fun) { fn do_fold(list, initial, fun) { case list { [] -> initial - [struct(k, v) | tail] -> do_fold(tail, fun(k, v, initial), fun) + [tuple(k, v) | tail] -> do_fold(tail, fun(k, v, initial), fun) } } diff --git a/src/gleam/order.gleam b/src/gleam/order.gleam index cf3bc40..0b90d01 100644 --- a/src/gleam/order.gleam +++ b/src/gleam/order.gleam @@ -1,4 +1,4 @@ -pub enum Order { +pub type Order { Lt Eq Gt diff --git a/src/gleam/pair.gleam b/src/gleam/pair.gleam index aaa336f..1637034 100644 --- a/src/gleam/pair.gleam +++ b/src/gleam/pair.gleam @@ -1,24 +1,24 @@ pub fn first(pair) { - let struct(a, _) = pair + let tuple(a, _) = pair a } pub fn second(pair) { - let struct(_, a) = pair + let tuple(_, a) = pair a } pub fn swap(pair) { - let struct(a, b) = pair - struct(b, a) + let tuple(a, b) = pair + tuple(b, a) } pub fn map_first(of pair, with fun) { - let struct(a, b) = pair - struct(fun(a), b) + let tuple(a, b) = pair + tuple(fun(a), b) } pub fn map_second(of pair, with fun) { - let struct(a, b) = pair - struct(a, fun(b)) + let tuple(a, b) = pair + tuple(a, fun(b)) } diff --git a/test/gleam/dynamic_test.gleam b/test/gleam/dynamic_test.gleam index 8b57648..2e51517 100644 --- a/test/gleam/dynamic_test.gleam +++ b/test/gleam/dynamic_test.gleam @@ -187,8 +187,6 @@ pub fn list_test() { |> expect.is_error } -// TODO: struct2 - pub fn field_test() { let Ok(ok_atom) = atom.from_string("ok") let Ok(error_atom) = atom.from_string("error") @@ -224,24 +222,24 @@ pub fn field_test() { pub fn element_test() { let Ok(ok_atom) = atom.from_string("ok") - let ok_one_struct = struct(ok_atom, 1) + let ok_one_tuple = tuple(ok_atom, 1) - ok_one_struct + ok_one_tuple |> dynamic.from |> dynamic.element(_, 0) |> expect.equal(_, Ok(dynamic.from(ok_atom))) - ok_one_struct + ok_one_tuple |> dynamic.from |> dynamic.element(_, 1) |> expect.equal(_, Ok(dynamic.from(1))) - ok_one_struct + ok_one_tuple |> dynamic.from |> dynamic.element(_, 2) |> expect.is_error - ok_one_struct + ok_one_tuple |> dynamic.from |> dynamic.element(_, -1) |> expect.is_error diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index 3b6d2ff..a8654d7 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -222,13 +222,13 @@ pub fn zip_test() { |> expect.equal(_, []) list.zip([1, 2, 3], [4, 5, 6]) - |> expect.equal(_, [struct(1, 4), struct(2, 5), struct(3, 6)]) + |> expect.equal(_, [tuple(1, 4), tuple(2, 5), tuple(3, 6)]) list.zip([5, 6], [1, 2, 3]) - |> expect.equal(_, [struct(5, 1), struct(6, 2)]) + |> expect.equal(_, [tuple(5, 1), tuple(6, 2)]) list.zip([5, 6, 7], [1, 2]) - |> expect.equal(_, [struct(5, 1), struct(6, 2)]) + |> expect.equal(_, [tuple(5, 1), tuple(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([ - struct(1, 4), - struct(2, 5), - struct(3, 6), + tuple(1, 4), + tuple(2, 5), + tuple(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) { struct(i, x) }) - |> expect.equal(_, [struct(0, 3), struct(1, 4), struct(2, 5)]) + list.index_map([3, 4, 5], fn(i, x) { tuple(i, x) }) + |> expect.equal(_, [tuple(0, 3), tuple(1, 4), tuple(2, 5)]) let f = fn(i, x) { string.append(x, int.to_string(i)) @@ -354,54 +354,54 @@ pub fn repeat_test() { pub fn split_test() { [] |> list.split(_, 0) - |> expect.equal(_, struct([], [])) + |> expect.equal(_, tuple([], [])) [0, 1, 2, 3, 4] |> list.split(_, 0) - |> expect.equal(_, struct([], [0, 1, 2, 3, 4])) + |> expect.equal(_, tuple([], [0, 1, 2, 3, 4])) [0, 1, 2, 3, 4] |> list.split(_, -2) - |> expect.equal(_, struct([], [0, 1, 2, 3, 4])) + |> expect.equal(_, tuple([], [0, 1, 2, 3, 4])) [0, 1, 2, 3, 4] |> list.split(_, 1) - |> expect.equal(_, struct([0], [1, 2, 3, 4])) + |> expect.equal(_, tuple([0], [1, 2, 3, 4])) [0, 1, 2, 3, 4] |> list.split(_, 3) - |> expect.equal(_, struct([0, 1, 2], [3, 4])) + |> expect.equal(_, tuple([0, 1, 2], [3, 4])) [0, 1, 2, 3, 4] |> list.split(_, 9) - |> expect.equal(_, struct([0, 1, 2, 3, 4], [])) + |> expect.equal(_, tuple([0, 1, 2, 3, 4], [])) } pub fn split_while_test() { [] |> list.split_while(_, fn(x) { x <= 5 }) - |> expect.equal(_, struct([], [])) + |> expect.equal(_, tuple([], [])) [1, 2, 3, 4, 5] |> list.split_while(_, fn(x) { x <= 5 }) - |> expect.equal(_, struct([1, 2, 3, 4, 5], [])) + |> expect.equal(_, tuple([1, 2, 3, 4, 5], [])) [1, 2, 3, 4, 5] |> list.split_while(_, fn(x) { x == 2 }) - |> expect.equal(_, struct([], [1, 2, 3, 4, 5])) + |> expect.equal(_, tuple([], [1, 2, 3, 4, 5])) [1, 2, 3, 4, 5] |> list.split_while(_, fn(x) { x <= 3 }) - |> expect.equal(_, struct([1, 2, 3], [4, 5])) + |> expect.equal(_, tuple([1, 2, 3], [4, 5])) [1, 2, 3, 4, 5] |> list.split_while(_, fn(x) { x <= -3 }) - |> expect.equal(_, struct([], [1, 2, 3, 4, 5])) + |> expect.equal(_, tuple([], [1, 2, 3, 4, 5])) } pub fn key_find_test() { - let proplist = [struct(0, "1"), struct(1, "2")] + let proplist = [tuple(0, "1"), tuple(1, "2")] proplist |> list.key_find(_, 0) diff --git a/test/gleam/map_test.gleam b/test/gleam/map_test.gleam index def91be..6dcd3a1 100644 --- a/test/gleam/map_test.gleam +++ b/test/gleam/map_test.gleam @@ -4,8 +4,8 @@ import gleam/map pub fn from_list_test() { [ - struct(4, 0), - struct(1, 0), + tuple(4, 0), + tuple(1, 0), ] |> map.from_list |> map.size @@ -19,23 +19,23 @@ pub fn has_key_test() { |> expect.false [ - struct(1, 0), + tuple(1, 0), ] |> map.from_list |> map.has_key(_, 1) |> expect.true [ - struct(4, 0), - struct(1, 0), + tuple(4, 0), + tuple(1, 0), ] |> map.from_list |> map.has_key(_, 1) |> expect.true [ - struct(4, 0), - struct(1, 0), + tuple(4, 0), + tuple(1, 0), ] |> map.from_list |> map.has_key(_, 0) @@ -54,8 +54,8 @@ pub fn new_test() { pub fn get_test() { let proplist = [ - struct(4, 0), - struct(1, 1), + tuple(4, 0), + tuple(1, 1), ] let m = map.from_list(proplist) @@ -78,32 +78,32 @@ pub fn insert_test() { |> map.insert(_, "b", 1) |> map.insert(_, "c", 2) |> expect.equal(_, map.from_list([ - struct("a", 0), - struct("b", 1), - struct("c", 2), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), ])) } pub fn map_values_test() { [ - struct(1, 0), - struct(2, 1), - struct(3, 2), + tuple(1, 0), + tuple(2, 1), + tuple(3, 2), ] |> map.from_list |> map.map_values(_, fn(k, v) { k + v }) |> expect.equal(_, map.from_list([ - struct(1, 1), - struct(2, 3), - struct(3, 5), + tuple(1, 1), + tuple(2, 3), + tuple(3, 5), ])) } pub fn keys_test() { [ - struct("a", 0), - struct("b", 1), - struct("c", 2), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), ] |> map.from_list |> map.keys @@ -112,9 +112,9 @@ pub fn keys_test() { pub fn values_test() { [ - struct("a", 0), - struct("b", 1), - struct("c", 2), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), ] |> map.from_list |> map.values @@ -123,72 +123,72 @@ pub fn values_test() { pub fn take_test() { [ - struct("a", 0), - struct("b", 1), - struct("c", 2), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), ] |> map.from_list |> map.take(_, ["a", "b", "d"]) - |> expect.equal(_, map.from_list([struct("a", 0), struct("b", 1)])) + |> expect.equal(_, map.from_list([tuple("a", 0), tuple("b", 1)])) } pub fn drop_test() { [ - struct("a", 0), - struct("b", 1), - struct("c", 2), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), ] |> map.from_list |> map.drop(_, ["a", "b", "d"]) - |> expect.equal(_, map.from_list([struct("c", 2)])) + |> expect.equal(_, map.from_list([tuple("c", 2)])) } pub fn merge_test() { let a = map.from_list([ - struct("a", 2), - struct("c", 4), - struct("d", 3), + tuple("a", 2), + tuple("c", 4), + tuple("d", 3), ]) let b = map.from_list([ - struct("a", 0), - struct("b", 1), - struct("c", 2), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), ]) map.merge(a, b) |> expect.equal(_, map.from_list([ - struct("a", 0), - struct("b", 1), - struct("c", 2), - struct("d", 3), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), + tuple("d", 3), ])) map.merge(b, a) |> expect.equal(_, map.from_list([ - struct("a", 2), - struct("b", 1), - struct("c", 4), - struct("d", 3), + tuple("a", 2), + tuple("b", 1), + tuple("c", 4), + tuple("d", 3), ])) } pub fn delete_test() { [ - struct("a", 0), - struct("b", 1), - struct("c", 2), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), ] |> map.from_list |> map.delete(_, "a") |> map.delete(_, "d") - |> expect.equal(_, map.from_list([struct("b", 1), struct("c", 2)])) + |> expect.equal(_, map.from_list([tuple("b", 1), tuple("c", 2)])) } pub fn update_test() { let dict = map.from_list([ - struct("a", 0), - struct("b", 1), - struct("c", 2), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), ]) let inc_or_zero = fn(x) { @@ -201,35 +201,35 @@ pub fn update_test() { dict |> map.update(_, "a", inc_or_zero) |> expect.equal(_, map.from_list([ - struct("a", 1), - struct("b", 1), - struct("c", 2), + tuple("a", 1), + tuple("b", 1), + tuple("c", 2), ])) dict |> map.update(_, "b", inc_or_zero) |> expect.equal(_, map.from_list([ - struct("a", 0), - struct("b", 2), - struct("c", 2), + tuple("a", 0), + tuple("b", 2), + tuple("c", 2), ])) dict |> map.update(_, "z", inc_or_zero) |> expect.equal(_, map.from_list([ - struct("a", 0), - struct("b", 1), - struct("c", 2), - struct("z", 0), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), + tuple("z", 0), ])) } pub fn fold_test() { let dict = map.from_list([ - struct("a", 0), - struct("b", 1), - struct("c", 2), - struct("d", 3), + tuple("a", 0), + tuple("b", 1), + tuple("c", 2), + tuple("d", 3), ]) let add = fn(_, v, acc) { diff --git a/test/gleam/pair_test.gleam b/test/gleam/pair_test.gleam index 057c343..96b771b 100644 --- a/test/gleam/pair_test.gleam +++ b/test/gleam/pair_test.gleam @@ -2,61 +2,61 @@ import gleam/expect import gleam/pair pub fn first_test() { - struct(1, 2) + tuple(1, 2) |> pair.first |> expect.equal(_, 1) - struct("abc", []) + tuple("abc", []) |> pair.first |> expect.equal(_, "abc") } pub fn second_test() { - struct(1, 2) + tuple(1, 2) |> pair.second |> expect.equal(_, 2) - struct("abc", []) + tuple("abc", []) |> pair.second |> expect.equal(_,[]) } pub fn swap_test() { - struct(1, "2") + tuple(1, "2") |> pair.swap - |> expect.equal(_, struct("2", 1)) + |> expect.equal(_, tuple("2", 1)) } pub fn map_first_test() { - let inc = fn(a) { - a + 1 - } - pair.map_first(struct(1, 2), inc) - |> expect.equal(_, struct(2, 2)) + let inc = fn(a) { + a + 1 + } + pair.map_first(tuple(1, 2), inc) + |> expect.equal(_, tuple(2, 2)) - pair.map_first(struct(8,2), inc) - |> expect.equal(_, struct(9, 2)) + pair.map_first(tuple(8,2), inc) + |> expect.equal(_, tuple(9, 2)) - pair.map_first(struct(0,-2), inc) - |> expect.equal(_, struct(1, -2)) + pair.map_first(tuple(0,-2), inc) + |> expect.equal(_, tuple(1, -2)) - pair.map_first(struct(-10, 20), inc) - |> expect.equal(_, struct(-9, 20)) + pair.map_first(tuple(-10, 20), inc) + |> expect.equal(_, tuple(-9, 20)) } pub fn map_second_test() { - let dec = fn(a) { - a - 1 - } - pair.map_second(struct(1, 2), dec) - |> expect.equal(_, struct(1, 1)) + let dec = fn(a) { + a - 1 + } + pair.map_second(tuple(1, 2), dec) + |> expect.equal(_, tuple(1, 1)) - pair.map_second(struct(8,2), dec) - |> expect.equal(_, struct(8, 1)) + pair.map_second(tuple(8,2), dec) + |> expect.equal(_, tuple(8, 1)) - pair.map_second(struct(0,-2), dec) - |> expect.equal(_, struct(0, -3)) + pair.map_second(tuple(0,-2), dec) + |> expect.equal(_, tuple(0, -3)) - pair.map_second(struct(-10, 20), dec) - |> expect.equal(_, struct(-10, 19)) + pair.map_second(tuple(-10, 20), dec) + |> expect.equal(_, tuple(-10, 19)) } diff --git a/test/gleam/result_test.gleam b/test/gleam/result_test.gleam index 10d2cf6..4fab1ad 100644 --- a/test/gleam/result_test.gleam +++ b/test/gleam/result_test.gleam @@ -37,8 +37,8 @@ pub fn map_error_test() { |> expect.equal(_, Ok(1)) Error(1) - |> result.map_error(_, fn(x) { struct("ok", x + 1) }) - |> expect.equal(_, Error(struct("ok", 2))) + |> result.map_error(_, fn(x) { tuple("ok", x + 1) }) + |> expect.equal(_, Error(tuple("ok", 2))) } pub fn flatten_test() { |