3
3
4
4
import gleam/string_builder
5
5
import gleam/dynamic . { Dynamic }
6
+ import gleam/iterator
6
7
import gleam/list
7
8
import gleam/order
8
9
import gleam/result
@@ -312,13 +313,6 @@ pub fn concat(strings: List(String)) -> String {
312
313
|> string_builder.to_string
313
314
}
314
315
315
- fn repeat_help(chunk: String, result: List(String), repeats: Int) -> String {
316
- case repeats <= 0 {
317
- True -> concat(result)
318
- False -> repeat_help(chunk, [chunk, ..result], repeats - 1)
319
- }
320
- }
321
-
322
316
/// Create a new string by repeating a string a given number of times.
323
317
///
324
318
/// This function runs in linear time.
@@ -329,7 +323,9 @@ fn repeat_help(chunk: String, result: List(String), repeats: Int) -> String {
329
323
/// "hahaha"
330
324
///
331
325
pub fn repeat(string: String, times times: Int) -> String {
332
- repeat_help(string, [], times)
326
+ iterator.repeat(string)
327
+ |> iterator.take(times)
328
+ |> concat
333
329
}
334
330
335
331
/// Join many strings together with a given separator.
@@ -344,14 +340,11 @@ pub fn repeat(string: String, times times: Int) -> String {
344
340
pub fn join(strings: List(String), with separator: String) -> String {
345
341
strings
346
342
|> list.intersperse(with: separator)
347
- |> string_builder.from_strings
348
- |> string_builder.to_string
343
+ |> concat
349
344
}
350
345
351
346
type Direction {
352
-
353
347
Leading
354
-
355
348
Trailing
356
349
Both
357
350
}
@@ -466,8 +459,7 @@ external fn int_to_utf_codepoint(Int) -> UtfCodepoint =
466
459
pub fn utf_codepoint ( value : Int ) -> Result ( UtfCodepoint , Nil ) {
467
460
case value {
468
461
i if i > 1114111 -> Error ( Nil )
469
- i if i == 65534 -> Error ( Nil )
470
- i if i == 65535 -> Error ( Nil )
462
+ 65534 | 65535 -> Error ( Nil )
471
463
i if i >= 55296 && i <= 57343 -> Error ( Nil )
472
464
i -> Ok ( int_to_utf_codepoint ( i ) )
473
465
}
0 commit comments