diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-11-24 22:13:34 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-11-25 11:22:45 +0000 |
commit | 69b0e8e1abb78db55cbdbd8db3ba4fe75b743e60 (patch) | |
tree | 47eec11c69fecb4033b33bd0987992e51b41f49c /src | |
parent | 09bd0a89dd80500d99589646a738c45c9537091a (diff) | |
download | gleam_stdlib-69b0e8e1abb78db55cbdbd8db3ba4fe75b743e60.tar.gz gleam_stdlib-69b0e8e1abb78db55cbdbd8db3ba4fe75b743e60.zip |
Update for Gleam v0.5
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/any.gleam | 4 | ||||
-rw-r--r-- | src/gleam/atom.gleam | 4 | ||||
-rw-r--r-- | src/gleam/list.gleam | 16 | ||||
-rw-r--r-- | src/gleam/map.gleam | 7 | ||||
-rw-r--r-- | src/gleam/pair.gleam | 31 | ||||
-rw-r--r-- | src/gleam/triple.gleam | 20 | ||||
-rw-r--r-- | src/gleam_stdlib.erl | 5 |
7 files changed, 25 insertions, 62 deletions
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). |