a fast, general-purpose, persistent array structure for Gleam.
29

Configure Feed

Select the types of activity you want to include in your feed.

add `join`.

yoshi~ (Mar 24, 2025, 9:55 PM +0100) 24607da4 364d5c3c

+28 -2
+1
CHANGELOG.md
··· 2 2 ## v1.2.0 3 3 4 4 Add `from_reverse_list`, `append_reverse_list`, `prepend_reverse_list`. 5 + Add `join`. 5 6 6 7 ## v1.1.2 7 8
+27 -2
src/iv.gleam
··· 27 27 //// [from_yielder](#from_yielder "Consume any yielder to build an array"), 28 28 //// [initialise](#initialise "Use a constructor function for every element") \ 29 29 //// [to_list](#to_list "Convert to a list"), 30 - //// [to_yielder](#to_yielder "Create a yielder iterating through the array") 30 + //// [to_yielder](#to_yielder "Create a yielder iterating through the array"), 31 + //// [join](#join "Convert a string array to a string") 31 32 //// 32 33 //// #### Query 33 34 //// [is_empty](#is_empty "Is the array empty?"), ··· 354 355 case array { 355 356 Empty -> yielder.empty() 356 357 Array(root:, ..) -> yielder.unfold(iterator_new(root), iterator_next) 358 + } 359 + } 360 + 361 + /// Convert a string array to a single string by joining the items together 362 + /// using the given separator. 363 + /// 364 + /// ```gleam 365 + /// from_list(["trans", "rights", "are", "human", "rights"]) 366 + /// |> join(with: " ") 367 + /// // --> "trans rights are human rights" 368 + /// ``` 369 + /// 370 + /// <div style="text-align: right;"> 371 + /// <a href="#"> 372 + /// <small>Back to top ↑</small> 373 + /// </a> 374 + /// </div> 375 + pub fn join(strings: Array(String), with separator: String) -> String { 376 + case first(strings) { 377 + Error(_) -> "" 378 + Ok(first) -> { 379 + use result, string <- fold(drop_first(strings, 1), first) 380 + result <> separator <> string 381 + } 357 382 } 358 383 } 359 384 ··· 1360 1385 /// 1361 1386 /// This is useful in tail-recursive algorithms to first build-up a intermediary 1362 1387 /// list instead of appending all elements immediately. 1363 - /// 1388 + /// 1364 1389 /// This function runs in _O(n)_ time, only depending on the size of the appended list. 1365 1390 /// 1366 1391 /// ```gleam