diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/dynamic.gleam | 45 | ||||
-rw-r--r-- | src/gleam/iterator.gleam | 12 | ||||
-rw-r--r-- | src/gleam/list.gleam | 78 | ||||
-rw-r--r-- | src/gleam/map.gleam | 12 | ||||
-rw-r--r-- | src/gleam/os.gleam | 2 | ||||
-rw-r--r-- | src/gleam/pair.gleam | 26 | ||||
-rw-r--r-- | src/gleam/queue.gleam | 8 | ||||
-rw-r--r-- | src/gleam/set.gleam | 13 | ||||
-rw-r--r-- | src/gleam/string.gleam | 10 | ||||
-rw-r--r-- | src/gleam/uri.gleam | 18 |
10 files changed, 107 insertions, 117 deletions
diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam index 696031e..15fcaef 100644 --- a/src/gleam/dynamic.gleam +++ b/src/gleam/dynamic.gleam @@ -169,12 +169,11 @@ pub external fn list(from: Dynamic) -> Result(List(Dynamic), String) = /// Error("Expected a 2 element tuple, got an int") /// pub fn result(from: Dynamic) -> Result(Result(Dynamic, Dynamic), String) { - try tuple(key, val) = tuple2(from) - try tag = atom(key) + try #(key, val) = tuple2(from) + try tag = atom(key) let ok_atom = atom.create_from_string("ok") let error_atom = atom.create_from_string("error") - case tag { tag if tag == ok_atom -> Ok(Ok(val)) tag if tag == error_atom -> Ok(Error(val)) @@ -334,7 +333,7 @@ pub external fn element(from: Dynamic, position: Int) -> Result(Dynamic, String) /// > tuple2(from("")) /// Error("Expected a tuple, got a binary") /// -pub external fn tuple2(from: Dynamic) -> Result(tuple(Dynamic, Dynamic), String) = +pub external fn tuple2(from: Dynamic) -> Result(#(Dynamic, Dynamic), String) = "gleam_stdlib" "decode_tuple2" /// Checks to see if the Dynamic value is a 2 element tuple containing two @@ -361,11 +360,11 @@ pub fn typed_tuple2( from tup: Dynamic, first decode_first: Decoder(a), second decode_second: Decoder(b), -) -> Result(tuple(a, b), String) { - try tuple(first, second) = tuple2(tup) +) -> Result(#(a, b), String) { + try #(first, second) = tuple2(tup) try a = decode_first(first) try b = decode_second(second) - Ok(tuple(a, b)) + Ok(#(a, b)) } /// Checks to see if the Dynamic value is a 3 element tuple. @@ -386,7 +385,7 @@ pub fn typed_tuple2( /// pub external fn tuple3( from: Dynamic, -) -> Result(tuple(Dynamic, Dynamic, Dynamic), String) = +) -> Result(#(Dynamic, Dynamic, Dynamic), String) = "gleam_stdlib" "decode_tuple3" /// Checks to see if the Dynamic value is a 3 element tuple containing two @@ -414,12 +413,12 @@ pub fn typed_tuple3( first decode_first: Decoder(a), second decode_second: Decoder(b), third decode_third: Decoder(c), -) -> Result(tuple(a, b, c), String) { - try tuple(first, second, third) = tuple3(tup) +) -> Result(#(a, b, c), String) { + try #(first, second, third) = tuple3(tup) try a = decode_first(first) try b = decode_second(second) try c = decode_third(third) - Ok(tuple(a, b, c)) + Ok(#(a, b, c)) } /// Checks to see if the Dynamic value is a 4 element tuple. @@ -440,7 +439,7 @@ pub fn typed_tuple3( /// pub external fn tuple4( from: Dynamic, -) -> Result(tuple(Dynamic, Dynamic, Dynamic, Dynamic), String) = +) -> Result(#(Dynamic, Dynamic, Dynamic, Dynamic), String) = "gleam_stdlib" "decode_tuple4" /// Checks to see if the Dynamic value is a 4 element tuple containing two @@ -469,13 +468,13 @@ pub fn typed_tuple4( second decode_second: Decoder(b), third decode_third: Decoder(c), fourth decode_fourth: Decoder(d), -) -> Result(tuple(a, b, c, d), String) { - try tuple(first, second, third, fourth) = tuple4(tup) +) -> Result(#(a, b, c, d), String) { + try #(first, second, third, fourth) = tuple4(tup) try a = decode_first(first) try b = decode_second(second) try c = decode_third(third) try d = decode_fourth(fourth) - Ok(tuple(a, b, c, d)) + Ok(#(a, b, c, d)) } /// Checks to see if the Dynamic value is a 5 element tuple. @@ -496,7 +495,7 @@ pub fn typed_tuple4( /// pub external fn tuple5( from: Dynamic, -) -> Result(tuple(Dynamic, Dynamic, Dynamic, Dynamic, Dynamic), String) = +) -> Result(#(Dynamic, Dynamic, Dynamic, Dynamic, Dynamic), String) = "gleam_stdlib" "decode_tuple5" /// Checks to see if the Dynamic value is a 5 element tuple containing two @@ -526,14 +525,14 @@ pub fn typed_tuple5( third decode_third: Decoder(c), fourth decode_fourth: Decoder(d), fifth decode_fifth: Decoder(e), -) -> Result(tuple(a, b, c, d, e), String) { - try tuple(first, second, third, fourth, fifth) = tuple5(tup) +) -> Result(#(a, b, c, d, e), String) { + try #(first, second, third, fourth, fifth) = tuple5(tup) try a = decode_first(first) try b = decode_second(second) try c = decode_third(third) try d = decode_fourth(fourth) try e = decode_fifth(fifth) - Ok(tuple(a, b, c, d, e)) + Ok(#(a, b, c, d, e)) } /// Checks to see if the Dynamic value is a 6 element tuple. @@ -554,7 +553,7 @@ pub fn typed_tuple5( /// pub external fn tuple6( from: Dynamic, -) -> Result(tuple(Dynamic, Dynamic, Dynamic, Dynamic, Dynamic, Dynamic), String) = +) -> Result(#(Dynamic, Dynamic, Dynamic, Dynamic, Dynamic, Dynamic), String) = "gleam_stdlib" "decode_tuple6" /// Checks to see if the Dynamic value is a 6 element tuple containing two @@ -585,15 +584,15 @@ pub fn typed_tuple6( fourth decode_fourth: Decoder(d), fifth decode_fifth: Decoder(e), sixth decode_sixth: Decoder(f), -) -> Result(tuple(a, b, c, d, e, f), String) { - try tuple(first, second, third, fourth, fifth, sixth) = tuple6(tup) +) -> Result(#(a, b, c, d, e, f), String) { + try #(first, second, third, fourth, fifth, sixth) = tuple6(tup) try a = decode_first(first) try b = decode_second(second) try c = decode_third(third) try d = decode_fourth(fourth) try e = decode_fifth(fifth) try f = decode_sixth(sixth) - Ok(tuple(a, b, c, d, e, f)) + Ok(#(a, b, c, d, e, f)) } /// Checks to see if the Dynamic value is map. diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam index 10f51a8..a6af2ef 100644 --- a/src/gleam/iterator.gleam +++ b/src/gleam/iterator.gleam @@ -478,12 +478,12 @@ pub fn find( fn do_index( continuation: fn() -> Action(element), next: Int, -) -> fn() -> Action(tuple(Int, element)) { +) -> fn() -> Action(#(Int, element)) { fn() { case continuation() { Stop -> Stop Continue(e, continuation) -> - Continue(tuple(next, e), do_index(continuation, next + 1)) + Continue(#(next, e), do_index(continuation, next + 1)) } } } @@ -495,7 +495,7 @@ fn do_index( /// > from_list(["a", "b", "c"]) |> index |> to_list /// [tuple(0, "a"), tuple(1, "b"), tuple(2, "c")] /// -pub fn index(over iterator: Iterator(element)) -> Iterator(tuple(Int, element)) { +pub fn index(over iterator: Iterator(element)) -> Iterator(#(Int, element)) { iterator.continuation |> do_index(0) |> Iterator @@ -616,7 +616,7 @@ pub fn scan( fn do_zip( left: fn() -> Action(a), right: fn() -> Action(b), -) -> fn() -> Action(tuple(a, b)) { +) -> fn() -> Action(#(a, b)) { fn() { case left() { Stop -> Stop @@ -624,7 +624,7 @@ fn do_zip( case right() { Stop -> Stop Continue(el_right, next_right) -> - Continue(tuple(el_left, el_right), do_zip(next_left, next_right)) + Continue(#(el_left, el_right), do_zip(next_left, next_right)) } } } @@ -638,7 +638,7 @@ fn do_zip( /// > from_list(["a", "b", "c"]) |> zip(range(20, 30)) |> to_list /// [tuple("a", 20), tuple("b", 21), tuple("c", 22)] /// -pub fn zip(left: Iterator(a), right: Iterator(b)) -> Iterator(tuple(a, b)) { +pub fn zip(left: Iterator(a), right: Iterator(b)) -> Iterator(#(a, b)) { do_zip(left.continuation, right.continuation) |> Iterator } diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index 4745f43..0102d98 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -262,15 +262,15 @@ pub fn map(list: List(a), with fun: fn(a) -> b) -> List(b) { pub fn map_fold( over list: List(a), from memo: memo, - with fun: fn(a, memo) -> tuple(b, memo), -) -> tuple(List(b), memo) { + with fun: fn(a, memo) -> #(b, memo), +) -> #(List(b), memo) { fold( over: list, - from: tuple([], memo), + from: #([], memo), with: fn(item, acc) { - let tuple(items, current_memo) = acc - let tuple(next_item, next_memo) = fun(item, current_memo) - tuple([next_item, ..items], next_memo) + let #(items, current_memo) = acc + let #(next_item, next_memo) = fun(item, current_memo) + #([next_item, ..items], next_memo) }, ) |> pair.map_first(reverse) @@ -694,9 +694,9 @@ pub fn any(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool { } } -fn do_zip(xs: List(a), ys: List(b), acc: List(tuple(a, b))) -> List(tuple(a, b)) { +fn do_zip(xs: List(a), ys: List(b), acc: List(#(a, b))) -> List(#(a, b)) { case xs, ys { - [x, ..xs], [y, ..ys] -> do_zip(xs, ys, [tuple(x, y), ..acc]) + [x, ..xs], [y, ..ys] -> do_zip(xs, ys, [#(x, y), ..acc]) _, _ -> reverse(acc) } } @@ -720,7 +720,7 @@ fn do_zip(xs: List(a), ys: List(b), acc: List(tuple(a, b))) -> List(tuple(a, b)) /// > zip([1, 2], [3, 4]) /// [tuple(1, 3), tuple(2, 4)] /// -pub fn zip(xs: List(a), ys: List(b)) -> List(tuple(a, b)) { +pub fn zip(xs: List(a), ys: List(b)) -> List(#(a, b)) { do_zip(xs, ys, []) } @@ -745,7 +745,7 @@ pub fn zip(xs: List(a), ys: List(b)) -> List(tuple(a, b)) { pub fn strict_zip( l1: List(a), l2: List(b), -) -> Result(List(tuple(a, b)), LengthMismatch) { +) -> Result(List(#(a, b)), LengthMismatch) { case length(of: l1) == length(of: l2) { True -> Ok(zip(l1, l2)) False -> Error(LengthMismatch) @@ -754,8 +754,8 @@ pub fn strict_zip( fn do_unzip(input, xs, ys) { case input { - [] -> tuple(reverse(xs), reverse(ys)) - [tuple(x, y), ..rest] -> do_unzip(rest, [x, ..xs], [y, ..ys]) + [] -> #(reverse(xs), reverse(ys)) + [#(x, y), ..rest] -> do_unzip(rest, [x, ..xs], [y, ..ys]) } } @@ -769,7 +769,7 @@ fn do_unzip(input, xs, ys) { /// > unzip([]) /// tuple([], []) /// -pub fn unzip(input: List(tuple(a, b))) -> tuple(List(a), List(b)) { +pub fn unzip(input: List(#(a, b))) -> #(List(a), List(b)) { do_unzip(input, [], []) } @@ -930,12 +930,12 @@ pub fn repeat(item a: a, times times: Int) -> List(a) { do_repeat(a, times, []) } -fn do_split(list: List(a), n: Int, taken: List(a)) -> tuple(List(a), List(a)) { +fn do_split(list: List(a), n: Int, taken: List(a)) -> #(List(a), List(a)) { case n <= 0 { - True -> tuple(reverse(taken), list) + True -> #(reverse(taken), list) False -> case list { - [] -> tuple(reverse(taken), []) + [] -> #(reverse(taken), []) [x, ..xs] -> do_split(xs, n - 1, [x, ..taken]) } } @@ -957,7 +957,7 @@ fn do_split(list: List(a), n: Int, taken: List(a)) -> tuple(List(a), List(a)) { /// > split([6, 7, 8, 9], 4) /// tuple([6, 7, 8, 9], []) /// -pub fn split(list list: List(a), at index: Int) -> tuple(List(a), List(a)) { +pub fn split(list list: List(a), at index: Int) -> #(List(a), List(a)) { do_split(list, index, []) } @@ -965,12 +965,12 @@ fn do_split_while( list: List(a), f: fn(a) -> Bool, acc: List(a), -) -> tuple(List(a), List(a)) { +) -> #(List(a), List(a)) { case list { - [] -> tuple(reverse(acc), []) + [] -> #(reverse(acc), []) [x, ..xs] -> case f(x) { - False -> tuple(reverse(acc), list) + False -> #(reverse(acc), list) _ -> do_split_while(xs, f, [x, ..acc]) } } @@ -993,7 +993,7 @@ fn do_split_while( pub fn split_while( list list: List(a), satisfying predicate: fn(a) -> Bool, -) -> tuple(List(a), List(a)) { +) -> #(List(a), List(a)) { do_split_while(list, predicate, []) } @@ -1017,13 +1017,13 @@ pub fn split_while( /// Error(Nil) /// pub fn key_find( - in keyword_list: List(tuple(k, v)), + in keyword_list: List(#(k, v)), find desired_key: k, ) -> Result(v, Nil) { find_map( keyword_list, fn(keyword) { - let tuple(key, value) = keyword + let #(key, value) = keyword case key == desired_key { True -> Ok(value) False -> Error(Nil) @@ -1037,7 +1037,7 @@ fn do_pop(haystack, predicate, checked) { [] -> Error(Nil) [x, ..rest] -> case predicate(x) { - True -> Ok(tuple(x, append(reverse(checked), rest))) + True -> Ok(#(x, append(reverse(checked), rest))) False -> do_pop(rest, predicate, [x, ..checked]) } } @@ -1062,7 +1062,7 @@ fn do_pop(haystack, predicate, checked) { pub fn pop( in haystack: List(a), one_that is_desired: fn(a) -> Bool, -) -> Result(tuple(a, List(a)), Nil) { +) -> Result(#(a, List(a)), Nil) { do_pop(haystack, is_desired, []) } @@ -1071,7 +1071,7 @@ fn do_pop_map(haystack, mapper, checked) { [] -> Error(Nil) [x, ..rest] -> case mapper(x) { - Ok(y) -> Ok(tuple(y, append(reverse(checked), rest))) + Ok(y) -> Ok(#(y, append(reverse(checked), rest))) Error(_) -> do_pop_map(rest, mapper, [x, ..checked]) } } @@ -1097,7 +1097,7 @@ fn do_pop_map(haystack, mapper, checked) { pub fn pop_map( in haystack: List(a), one_that is_desired: fn(a) -> Result(b, c), -) -> Result(tuple(b, List(a)), Nil) { +) -> Result(#(b, List(a)), Nil) { do_pop_map(haystack, is_desired, []) } @@ -1119,13 +1119,13 @@ pub fn pop_map( /// Error(Nil) /// pub fn key_pop( - haystack: List(tuple(k, v)), + haystack: List(#(k, v)), key: k, -) -> Result(tuple(v, List(tuple(k, v))), Nil) { +) -> Result(#(v, List(#(k, v))), Nil) { pop_map( haystack, fn(entry) { - let tuple(k, v) = entry + let #(k, v) = entry case k { k if k == key -> Ok(v) _ -> Error(Nil) @@ -1148,10 +1148,10 @@ pub fn key_pop( /// > key_set([tuple(5, 0), tuple(4, 1)], 1, 100) /// [tuple(5, 0), tuple(4, 1), tuple(1, 100)] /// -pub fn key_set(list: List(tuple(a, b)), key: a, value: b) -> List(tuple(a, b)) { +pub fn key_set(list: List(#(a, b)), key: a, value: b) -> List(#(a, b)) { case list { - [] -> [tuple(key, value)] - [tuple(k, _), ..rest] if k == key -> [tuple(key, value), ..rest] + [] -> [#(key, value)] + [#(k, _), ..rest] if k == key -> [#(key, value), ..rest] [first, ..rest] -> [first, ..key_set(rest, key, value)] } } @@ -1170,7 +1170,7 @@ pub fn each(list: List(a), f: fn(a) -> b) -> Nil { fn do_partition(list, categorise, trues, falses) { case list { - [] -> tuple(reverse(trues), reverse(falses)) + [] -> #(reverse(trues), reverse(falses)) [x, ..xs] -> case categorise(x) { True -> do_partition(xs, categorise, [x, ..trues], falses) @@ -1182,7 +1182,7 @@ fn do_partition(list, categorise, trues, falses) { pub fn partition( list: List(a), with categorise: fn(a) -> Bool, -) -> tuple(List(a), List(a)) { +) -> #(List(a), List(a)) { do_partition(list, categorise, [], []) } @@ -1248,7 +1248,7 @@ pub fn window(l: List(a), by n: Int) -> List(List(a)) { /// [] /// ``` /// -pub fn window_by_2(l: List(a)) -> List(tuple(a, a)) { +pub fn window_by_2(l: List(a)) -> List(#(a, a)) { zip(l, drop(l, 1)) } @@ -1485,11 +1485,11 @@ pub fn combinations(items: List(a), by n: Int) -> List(List(a)) { } } -fn do_combination_pairs(items: List(a)) -> List(List(tuple(a, a))) { +fn do_combination_pairs(items: List(a)) -> List(List(#(a, a))) { case items { [] -> [] [x, ..xs] -> { - let first_combinations = map(xs, with: fn(other) { tuple(x, other) }) + let first_combinations = map(xs, with: fn(other) { #(x, other) }) [first_combinations, ..do_combination_pairs(xs)] } } @@ -1504,7 +1504,7 @@ fn do_combination_pairs(items: List(a)) -> List(List(tuple(a, a))) { /// [tuple(1, 2), tuple(1, 3), tuple(2, 3)] /// ``` /// -pub fn combination_pairs(items: List(a)) -> List(tuple(a, a)) { +pub fn combination_pairs(items: List(a)) -> List(#(a, a)) { do_combination_pairs(items) |> flatten } diff --git a/src/gleam/map.gleam b/src/gleam/map.gleam index 15b936a..3d9917c 100644 --- a/src/gleam/map.gleam +++ b/src/gleam/map.gleam @@ -45,7 +45,7 @@ pub external fn size(Map(k, v)) -> Int = /// > new() |> insert("key", 0) |> to_list() /// [tuple("key", 0)] /// -pub external fn to_list(Map(key, value)) -> List(tuple(key, value)) = +pub external fn to_list(Map(key, value)) -> List(#(key, value)) = "maps" "to_list" /// Converts a list of 2-element tuples `tuple(key, value)` to a map. @@ -53,7 +53,7 @@ pub external fn to_list(Map(key, value)) -> List(tuple(key, value)) = /// If two tuples have the same key the last one in the list will be the one /// that is present in the map. /// -pub external fn from_list(List(tuple(key, value))) -> Map(key, value) = +pub external fn from_list(List(#(key, value))) -> Map(key, value) = "maps" "from_list" external fn is_key(key, Map(key, v)) -> Bool = @@ -286,14 +286,10 @@ pub fn update( |> insert(map, key, _) } -fn do_fold( - list: List(tuple(k, v)), - initial: acc, - fun: fn(k, v, acc) -> acc, -) -> acc { +fn do_fold(list: List(#(k, v)), initial: acc, fun: fn(k, v, acc) -> acc) -> acc { case list { [] -> initial - [tuple(k, v), ..tail] -> do_fold(tail, fun(k, v, initial), fun) + [#(k, v), ..tail] -> do_fold(tail, fun(k, v, initial), fun) } } diff --git a/src/gleam/os.gleam b/src/gleam/os.gleam index 6dabe74..374c5e2 100644 --- a/src/gleam/os.gleam +++ b/src/gleam/os.gleam @@ -62,5 +62,5 @@ pub external fn system_time(TimeUnit) -> Int = /// Returns the current OS system time as a tuple of Ints /// /// http://erlang.org/doc/man/os.html#timestamp-0 -pub external fn erlang_timestamp() -> tuple(Int, Int, Int) = +pub external fn erlang_timestamp() -> #(Int, Int, Int) = "os" "timestamp" diff --git a/src/gleam/pair.gleam b/src/gleam/pair.gleam index f0de5a9..644a7f9 100644 --- a/src/gleam/pair.gleam +++ b/src/gleam/pair.gleam @@ -5,8 +5,8 @@ /// > first(tuple(1, 2)) /// 1 /// -pub fn first(pair: tuple(a, b)) -> a { - let tuple(a, _) = pair +pub fn first(pair: #(a, b)) -> a { + let #(a, _) = pair a } @@ -17,8 +17,8 @@ pub fn first(pair: tuple(a, b)) -> a { /// > second(tuple(1, 2)) /// 2 /// -pub fn second(pair: tuple(a, b)) -> b { - let tuple(_, a) = pair +pub fn second(pair: #(a, b)) -> b { + let #(_, a) = pair a } @@ -29,9 +29,9 @@ pub fn second(pair: tuple(a, b)) -> b { /// > swap(tuple(1, 2)) /// tuple(2, 1) /// -pub fn swap(pair: tuple(a, b)) -> tuple(b, a) { - let tuple(a, b) = pair - tuple(b, a) +pub fn swap(pair: #(a, b)) -> #(b, a) { + let #(a, b) = pair + #(b, a) } /// Returns a new pair with the first element having had `with` applied to @@ -42,9 +42,9 @@ pub fn swap(pair: tuple(a, b)) -> tuple(b, a) { /// > tuple(1, 2) |> map_first(fn(n) { n * 2 }) /// 2 /// -pub fn map_first(of pair: tuple(a, b), with fun: fn(a) -> c) -> tuple(c, b) { - let tuple(a, b) = pair - tuple(fun(a), b) +pub fn map_first(of pair: #(a, b), with fun: fn(a) -> c) -> #(c, b) { + let #(a, b) = pair + #(fun(a), b) } /// Returns a new pair with the second element having had `with` applied to @@ -55,7 +55,7 @@ pub fn map_first(of pair: tuple(a, b), with fun: fn(a) -> c) -> tuple(c, b) { /// > tuple(1, 2) |> map_second(fn(n) { n * 2 }) /// 4 /// -pub fn map_second(of pair: tuple(a, b), with fun: fn(b) -> c) -> tuple(a, c) { - let tuple(a, b) = pair - tuple(a, fun(b)) +pub fn map_second(of pair: #(a, b), with fun: fn(b) -> c) -> #(a, c) { + let #(a, b) = pair + #(a, fun(b)) } diff --git a/src/gleam/queue.gleam b/src/gleam/queue.gleam index 09791df..ef02796 100644 --- a/src/gleam/queue.gleam +++ b/src/gleam/queue.gleam @@ -136,13 +136,13 @@ pub fn push_front(onto queue: Queue(a), this item: a) -> Queue(a) { /// > |> queue.pop_back() /// Error(Nil) /// -pub fn pop_back(from queue: Queue(a)) -> Result(tuple(a, Queue(a)), Nil) { +pub fn pop_back(from queue: Queue(a)) -> Result(#(a, Queue(a)), Nil) { case queue { Queue(in: [], out: []) -> Error(Nil) Queue(in: [], out: out) -> pop_back(Queue(in: list.reverse(out), out: [])) Queue(in: [first, ..rest], out: out) -> { let queue = Queue(in: rest, out: out) - Ok(tuple(first, queue)) + Ok(#(first, queue)) } } } @@ -170,13 +170,13 @@ pub fn pop_back(from queue: Queue(a)) -> Result(tuple(a, Queue(a)), Nil) { /// > |> queue.pop_back() /// Error(Nil) /// -pub fn pop_front(from queue: Queue(a)) -> Result(tuple(a, Queue(a)), Nil) { +pub fn pop_front(from queue: Queue(a)) -> Result(#(a, Queue(a)), Nil) { case queue { Queue(in: [], out: []) -> Error(Nil) Queue(in: in, out: []) -> pop_front(Queue(in: [], out: list.reverse(in))) Queue(in: in, out: [first, ..rest]) -> { let queue = Queue(in: in, out: rest) - Ok(tuple(first, queue)) + Ok(#(first, queue)) } } } diff --git a/src/gleam/set.gleam b/src/gleam/set.gleam index 7d9a91e..61bb47a 100644 --- a/src/gleam/set.gleam +++ b/src/gleam/set.gleam @@ -168,13 +168,10 @@ pub fn take(from set: Set(member), keeping desired: List(member)) -> Set(member) Set(map.take(from: set.map, keeping: desired)) } -fn order( - first: Set(member), - second: Set(member), -) -> tuple(Set(member), Set(member)) { +fn order(first: Set(member), second: Set(member)) -> #(Set(member), Set(member)) { case map.size(first.map) > map.size(second.map) { - True -> tuple(first, second) - False -> tuple(second, first) + True -> #(first, second) + False -> #(second, first) } } @@ -188,7 +185,7 @@ fn order( /// [1, 2, 3] /// pub fn union(of first: Set(member), and second: Set(member)) -> Set(member) { - let tuple(larger, smaller) = order(first, second) + let #(larger, smaller) = order(first, second) fold(over: smaller, from: larger, with: fn(m, a) { insert(a, m) }) } @@ -205,6 +202,6 @@ pub fn intersection( of first: Set(member), and second: Set(member), ) -> Set(member) { - let tuple(larger, smaller) = order(first, second) + let #(larger, smaller) = order(first, second) take(from: larger, keeping: to_list(smaller)) } diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index 8bef422..ad58aae 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -282,9 +282,9 @@ external fn erl_split(String, String) -> List(String) = pub fn split_once( x: String, on substring: String, -) -> Result(tuple(String, String), Nil) { +) -> Result(#(String, String), Nil) { case erl_split(x, substring) { - [first, rest] -> Ok(tuple(first, rest)) + [first, rest] -> Ok(#(first, rest)) _ -> Error(Nil) } } @@ -444,9 +444,7 @@ pub fn trim_right(string: String) -> String { /// > pop_grapheme("") /// Error(Nil) /// -pub external fn pop_grapheme( - string: String, -) -> Result(tuple(String, String), Nil) = +pub external fn pop_grapheme(string: String) -> Result(#(String, String), Nil) = "gleam_stdlib" "string_pop_grapheme" /// Converts a string to a list of Graphemes. @@ -456,7 +454,7 @@ pub external fn pop_grapheme( /// pub fn to_graphemes(string: String) -> List(String) { case pop_grapheme(string) { - Ok(tuple(grapheme, rest)) -> [grapheme, ..to_graphemes(rest)] + Ok(#(grapheme, rest)) -> [grapheme, ..to_graphemes(rest)] _ -> [] } } diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index 4e15a2b..d9fc1ac 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -97,7 +97,7 @@ external fn erl_parse_query(String) -> Dynamic = /// Ok([tuple("a", "1"), tuple("b", "2")]) /// ``` /// -pub fn parse_query(query: String) -> Result(List(tuple(String, String)), Nil) { +pub fn parse_query(query: String) -> Result(List(#(String, String)), Nil) { let bool_value = fn(x) { result.map(dynamic.bool(x), fn(_) { "" }) } let query_param = dynamic.typed_tuple2( _, @@ -120,7 +120,7 @@ type ErlQueryToStringOption { } external fn erl_query_to_string( - List(tuple(String, String)), + List(#(String, String)), List(ErlQueryToStringOption), ) -> Dynamic = "uri_string" "compose_query" @@ -137,7 +137,7 @@ external fn erl_query_to_string( /// "a=1&b=2" /// ``` /// -pub fn query_to_string(query: List(tuple(String, String))) -> String { +pub fn query_to_string(query: List(#(String, String))) -> String { query |> erl_query_to_string([Encoding(Utf8)]) |> dynamic.string @@ -156,7 +156,7 @@ pub fn query_to_string(query: List(tuple(String, String))) -> String { /// ``` /// pub fn percent_encode(value: String) -> String { - query_to_string([tuple("k", value)]) + query_to_string([#("k", value)]) |> string.replace(each: "k=", with: "") } @@ -235,11 +235,11 @@ external fn erl_to_string(Map(UriKey, Dynamic)) -> Dynamic = /// pub fn to_string(uri: Uri) -> String { let field = fn(key: UriKey, value: Option(anything)) -> Result( - tuple(UriKey, Dynamic), + #(UriKey, Dynamic), Nil, ) { case value { - Some(v) -> Ok(tuple(key, dynamic.from(v))) + Some(v) -> Ok(#(key, dynamic.from(v))) None -> Error(Nil) } } @@ -322,8 +322,8 @@ pub fn merge(base: Uri, relative: Uri) -> Result(Uri, Nil) { Ok(resolved) } Uri(scheme: None, host: None, ..) -> { - let tuple(new_path, new_query) = case relative.path { - "" -> tuple(base.path, option.or(relative.query, base.query)) + let #(new_path, new_query) = case relative.path { + "" -> #(base.path, option.or(relative.query, base.query)) _ -> { let path_segments = case string.starts_with(relative.path, "/") { True -> string.split(relative.path, "/") @@ -336,7 +336,7 @@ pub fn merge(base: Uri, relative: Uri) -> Result(Uri, Nil) { path_segments |> remove_dot_segments() |> join_segments() - tuple(path, relative.query) + #(path, relative.query) } } let resolved = |