Skip to content

Commit 4411f58

Browse files
GearsDatapackslpil
authored andcommitted
Replace do_* with direct externals
1 parent b8785ed commit 4411f58

File tree

10 files changed

+56
-266
lines changed

10 files changed

+56
-266
lines changed

src/gleam/bit_array.gleam

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,17 @@ fn is_utf8_loop(bits: BitArray) -> Bool {
7979
///
8080
/// Returns an error if the bit array is invalid UTF-8 data.
8181
///
82-
pub fn to_string(bits: BitArray) -> Result(String, Nil) {
83-
do_to_string(bits)
84-
}
85-
86-
@external(erlang, "gleam_stdlib", "identity")
87-
fn unsafe_to_string(a: BitArray) -> String
88-
8982
@external(javascript, "../gleam_stdlib.mjs", "bit_array_to_string")
90-
fn do_to_string(bits: BitArray) -> Result(String, Nil) {
83+
pub fn to_string(bits: BitArray) -> Result(String, Nil) {
9184
case is_utf8(bits) {
9285
True -> Ok(unsafe_to_string(bits))
9386
False -> Error(Nil)
9487
}
9588
}
9689

90+
@external(erlang, "gleam_stdlib", "identity")
91+
fn unsafe_to_string(a: BitArray) -> String
92+
9793
/// Creates a new bit array by joining multiple binaries.
9894
///
9995
/// ## Examples

src/gleam/dict.gleam

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,9 @@ fn do_has_key(key: k, dict: Dict(k, v)) -> Bool {
124124

125125
/// Creates a fresh dict that contains no values.
126126
///
127-
pub fn new() -> Dict(k, v) {
128-
do_new()
129-
}
130-
131127
@external(erlang, "maps", "new")
132128
@external(javascript, "../gleam_stdlib.mjs", "new_map")
133-
fn do_new() -> Dict(k, v)
129+
pub fn new() -> Dict(k, v)
134130

135131
/// Fetches a value from a dict for a given key.
136132
///
@@ -149,13 +145,9 @@ fn do_new() -> Dict(k, v)
149145
/// // -> Error(Nil)
150146
/// ```
151147
///
152-
pub fn get(from: Dict(k, v), get: k) -> Result(v, Nil) {
153-
do_get(from, get)
154-
}
155-
156148
@external(erlang, "gleam_stdlib", "map_get")
157149
@external(javascript, "../gleam_stdlib.mjs", "map_get")
158-
fn do_get(dict: Dict(k, v), key: k) -> Result(v, Nil)
150+
pub fn get(from: Dict(k, v), get: k) -> Result(v, Nil)
159151

160152
/// Inserts a value into the dict with the given key.
161153
///
@@ -216,12 +208,8 @@ fn do_map_values(f: fn(k, v) -> a, dict: Dict(k, v)) -> Dict(k, a) {
216208
/// // -> ["a", "b"]
217209
/// ```
218210
///
219-
pub fn keys(dict: Dict(k, v)) -> List(k) {
220-
do_keys(dict)
221-
}
222-
223211
@external(erlang, "maps", "keys")
224-
fn do_keys(dict: Dict(k, v)) -> List(k) {
212+
pub fn keys(dict: Dict(k, v)) -> List(k) {
225213
let list_of_pairs = to_list(dict)
226214
do_keys_loop(list_of_pairs, [])
227215
}
@@ -253,12 +241,8 @@ fn do_keys_loop(list: List(#(k, v)), acc: List(k)) -> List(k) {
253241
/// // -> [0, 1]
254242
/// ```
255243
///
256-
pub fn values(dict: Dict(k, v)) -> List(v) {
257-
do_values(dict)
258-
}
259-
260244
@external(erlang, "maps", "values")
261-
fn do_values(dict: Dict(k, v)) -> List(v) {
245+
pub fn values(dict: Dict(k, v)) -> List(v) {
262246
let list_of_pairs = to_list(dict)
263247
do_values_loop(list_of_pairs, [])
264248
}
@@ -363,12 +347,8 @@ fn do_take_loop(
363347
/// // -> from_list([#("a", 0), #("b", 2), #("c", 3)])
364348
/// ```
365349
///
366-
pub fn merge(into dict: Dict(k, v), from new_entries: Dict(k, v)) -> Dict(k, v) {
367-
do_merge(dict, new_entries)
368-
}
369-
370350
@external(erlang, "maps", "merge")
371-
fn do_merge(dict: Dict(k, v), new_entries: Dict(k, v)) -> Dict(k, v) {
351+
pub fn merge(into dict: Dict(k, v), from new_entries: Dict(k, v)) -> Dict(k, v) {
372352
new_entries
373353
|> to_list
374354
|> fold_inserts(dict)

src/gleam/dynamic.gleam

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,9 @@ fn put_expected(error: DecodeError, expected: String) -> DecodeError {
115115
/// // -> "String"
116116
/// ```
117117
///
118-
pub fn classify(data: Dynamic) -> String {
119-
do_classify(data)
120-
}
121-
122118
@external(erlang, "gleam_stdlib", "classify_dynamic")
123119
@external(javascript, "../gleam_stdlib.mjs", "classify_dynamic")
124-
fn do_classify(a: Dynamic) -> String
120+
pub fn classify(data: Dynamic) -> String
125121

126122
/// Checks to see whether a `Dynamic` value is an int, and returns that int if it
127123
/// is.

src/gleam/float.gleam

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ import gleam/order.{type Order}
2929
/// // -> Error(Nil)
3030
/// ```
3131
///
32-
pub fn parse(string: String) -> Result(Float, Nil) {
33-
do_parse(string)
34-
}
35-
3632
@external(erlang, "gleam_stdlib", "parse_float")
3733
@external(javascript, "../gleam_stdlib.mjs", "parse_float")
38-
fn do_parse(a: String) -> Result(Float, Nil)
34+
pub fn parse(string: String) -> Result(Float, Nil)
3935

4036
/// Returns the string representation of the provided `Float`.
4137
///
@@ -46,13 +42,9 @@ fn do_parse(a: String) -> Result(Float, Nil)
4642
/// // -> "2.3"
4743
/// ```
4844
///
49-
pub fn to_string(x: Float) -> String {
50-
do_to_string(x)
51-
}
52-
5345
@external(erlang, "gleam_stdlib", "float_to_string")
5446
@external(javascript, "../gleam_stdlib.mjs", "float_to_string")
55-
fn do_to_string(a: Float) -> String
47+
pub fn to_string(x: Float) -> String
5648

5749
/// Restricts a `Float` between a lower and upper bound.
5850
///
@@ -196,13 +188,9 @@ pub fn max(a: Float, b: Float) -> Float {
196188
/// // -> 3.0
197189
/// ```
198190
///
199-
pub fn ceiling(x: Float) -> Float {
200-
do_ceiling(x)
201-
}
202-
203191
@external(erlang, "math", "ceil")
204192
@external(javascript, "../gleam_stdlib.mjs", "ceiling")
205-
fn do_ceiling(a: Float) -> Float
193+
pub fn ceiling(x: Float) -> Float
206194

207195
/// Rounds the value to the next lowest whole number as a `Float`.
208196
///
@@ -213,13 +201,9 @@ fn do_ceiling(a: Float) -> Float
213201
/// // -> 2.0
214202
/// ```
215203
///
216-
pub fn floor(x: Float) -> Float {
217-
do_floor(x)
218-
}
219-
220204
@external(erlang, "math", "floor")
221205
@external(javascript, "../gleam_stdlib.mjs", "floor")
222-
fn do_floor(a: Float) -> Float
206+
pub fn floor(x: Float) -> Float
223207

224208
/// Rounds the value to the nearest whole number as an `Int`.
225209
///
@@ -235,12 +219,8 @@ fn do_floor(a: Float) -> Float
235219
/// // -> 3
236220
/// ```
237221
///
238-
pub fn round(x: Float) -> Int {
239-
do_round(x)
240-
}
241-
242222
@external(erlang, "erlang", "round")
243-
fn do_round(x: Float) -> Int {
223+
pub fn round(x: Float) -> Int {
244224
case x >=. 0.0 {
245225
True -> js_round(x)
246226
_ -> 0 - js_round(negate(x))
@@ -259,13 +239,9 @@ fn js_round(a: Float) -> Int
259239
/// // -> 2
260240
/// ```
261241
///
262-
pub fn truncate(x: Float) -> Int {
263-
do_truncate(x)
264-
}
265-
266242
@external(erlang, "erlang", "trunc")
267243
@external(javascript, "../gleam_stdlib.mjs", "truncate")
268-
fn do_truncate(a: Float) -> Int
244+
pub fn truncate(x: Float) -> Int
269245

270246
/// Converts the value to a given precision as a `Float`.
271247
/// The precision is the number of allowed decimal places.

src/gleam/int.gleam

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,9 @@ pub fn square_root(x: Int) -> Result(Float, Nil) {
104104
/// // -> Error(Nil)
105105
/// ```
106106
///
107-
pub fn parse(string: String) -> Result(Int, Nil) {
108-
do_parse(string)
109-
}
110-
111107
@external(erlang, "gleam_stdlib", "parse_int")
112108
@external(javascript, "../gleam_stdlib.mjs", "parse_int")
113-
fn do_parse(a: String) -> Result(Int, Nil)
109+
pub fn parse(string: String) -> Result(Int, Nil)
114110

115111
/// Parses a given string as an int in a given base if possible.
116112
/// Supports only bases 2 to 36, for values outside of which this function returns an `Error(Nil)`.
@@ -162,13 +158,9 @@ fn do_base_parse(a: String, b: Int) -> Result(Int, Nil)
162158
/// // -> "2"
163159
/// ```
164160
///
165-
pub fn to_string(x: Int) {
166-
do_to_string(x)
167-
}
168-
169161
@external(erlang, "erlang", "integer_to_binary")
170162
@external(javascript, "../gleam_stdlib.mjs", "to_string")
171-
fn do_to_string(a: Int) -> String
163+
pub fn to_string(x: Int) -> String
172164

173165
/// Prints a given int to a string using the base number provided.
174166
/// Supports only bases 2 to 36, for values outside of which this function returns an `Error(Nil)`.
@@ -283,13 +275,9 @@ pub fn to_base36(x: Int) -> String {
283275
/// // -> -3.0
284276
/// ```
285277
///
286-
pub fn to_float(x: Int) -> Float {
287-
do_to_float(x)
288-
}
289-
290278
@external(erlang, "erlang", "float")
291279
@external(javascript, "../gleam_stdlib.mjs", "identity")
292-
fn do_to_float(a: Int) -> Float
280+
pub fn to_float(x: Int) -> Float
293281

294282
/// Restricts an int between a lower and upper bound.
295283
///

src/gleam/io.gleam

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ import gleam/string
1212
/// // Hi mum
1313
/// ```
1414
///
15-
pub fn print(string: String) -> Nil {
16-
do_print(string)
17-
}
18-
1915
@external(erlang, "gleam_stdlib", "print")
2016
@external(javascript, "../gleam_stdlib.mjs", "print")
21-
fn do_print(string string: String) -> Nil
17+
pub fn print(string: String) -> Nil
2218

2319
/// Writes a string to standard error (stderr).
2420
///
@@ -32,13 +28,9 @@ fn do_print(string string: String) -> Nil
3228
/// // Hi pop
3329
/// ```
3430
///
35-
pub fn print_error(string: String) -> Nil {
36-
do_print_error(string)
37-
}
38-
3931
@external(erlang, "gleam_stdlib", "print_error")
4032
@external(javascript, "../gleam_stdlib.mjs", "print_error")
41-
fn do_print_error(string string: String) -> Nil
33+
pub fn print_error(string: String) -> Nil
4234

4335
/// Writes a string to standard output (stdout), appending a newline to the end.
4436
///
@@ -50,13 +42,9 @@ fn do_print_error(string string: String) -> Nil
5042
/// // Hi mum
5143
/// ```
5244
///
53-
pub fn println(string: String) -> Nil {
54-
do_println(string)
55-
}
56-
5745
@external(erlang, "gleam_stdlib", "println")
5846
@external(javascript, "../gleam_stdlib.mjs", "console_log")
59-
fn do_println(string string: String) -> Nil
47+
pub fn println(string: String) -> Nil
6048

6149
/// Writes a string to standard error (stderr), appending a newline to the end.
6250
///
@@ -68,13 +56,9 @@ fn do_println(string string: String) -> Nil
6856
/// // Hi pop
6957
/// ```
7058
///
71-
pub fn println_error(string: String) -> Nil {
72-
do_println_error(string)
73-
}
74-
7559
@external(erlang, "gleam_stdlib", "println_error")
7660
@external(javascript, "../gleam_stdlib.mjs", "console_error")
77-
fn do_println_error(string string: String) -> Nil
61+
pub fn println_error(string: String) -> Nil
7862

7963
/// Writes a value to standard error (stderr) yielding Gleam syntax.
8064
///

src/gleam/regex.gleam

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,11 @@ pub type Options {
5757
/// ```
5858
///
5959
@deprecated("Please use the gleam_regexp package instead")
60-
pub fn compile(
61-
pattern: String,
62-
with options: Options,
63-
) -> Result(Regex, CompileError) {
64-
do_compile(pattern, options)
65-
}
66-
6760
@external(erlang, "gleam_stdlib", "compile_regex")
6861
@external(javascript, "../gleam_stdlib.mjs", "compile_regex")
69-
fn do_compile(
62+
pub fn compile(
7063
pattern: String,
71-
with with: Options,
64+
with options: Options,
7265
) -> Result(Regex, CompileError)
7366

7467
/// Creates a new `Regex`.
@@ -115,13 +108,9 @@ pub fn from_string(pattern: String) -> Result(Regex, CompileError) {
115108
/// ```
116109
///
117110
@deprecated("Please use the gleam_regexp package instead")
118-
pub fn check(with regex: Regex, content string: String) -> Bool {
119-
do_check(regex, string)
120-
}
121-
122111
@external(erlang, "gleam_stdlib", "regex_check")
123112
@external(javascript, "../gleam_stdlib.mjs", "regex_check")
124-
fn do_check(regex: Regex, string: String) -> Bool
113+
pub fn check(with regex: Regex, content string: String) -> Bool
125114

126115
/// Splits a string.
127116
///
@@ -134,13 +123,9 @@ fn do_check(regex: Regex, string: String) -> Bool
134123
/// ```
135124
///
136125
@deprecated("Please use the gleam_regexp package instead")
137-
pub fn split(with regex: Regex, content string: String) -> List(String) {
138-
do_split(regex, string)
139-
}
140-
141126
@external(erlang, "gleam_stdlib", "regex_split")
142127
@external(javascript, "../gleam_stdlib.mjs", "regex_split")
143-
fn do_split(regex: Regex, string: String) -> List(String)
128+
pub fn split(with regex: Regex, content string: String) -> List(String)
144129

145130
/// Collects all matches of the regular expression.
146131
///
@@ -195,13 +180,9 @@ fn do_split(regex: Regex, string: String) -> List(String)
195180
/// ```
196181
///
197182
@deprecated("Please use the gleam_regexp package instead")
198-
pub fn scan(with regex: Regex, content string: String) -> List(Match) {
199-
do_scan(regex, string)
200-
}
201-
202183
@external(erlang, "gleam_stdlib", "regex_scan")
203184
@external(javascript, "../gleam_stdlib.mjs", "regex_scan")
204-
fn do_scan(regex: Regex, string: String) -> List(Match)
185+
pub fn scan(with regex: Regex, content string: String) -> List(Match)
205186

206187
/// Creates a new `String` by replacing all substrings that match the regular
207188
/// expression.

0 commit comments

Comments
 (0)