Created
March 25, 2024 00:29
-
-
Save manveru/f96c4a60c62a1e947ff6dc37011b9956 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gleam/iterator | |
import gleam/string | |
import gleam/io | |
pub fn main() { | |
iterator.unfold(["1,2,3,4,5,6,6,7"], fn(acc) { | |
case acc { | |
[] -> iterator.Done | |
[e] | [e, ..] -> | |
case binary_split(e, <<",":utf8>>) { | |
[] -> iterator.Done | |
[value, ..rest] -> iterator.Next(value, rest) | |
} | |
} | |
}) | |
|> iterator.take(5) | |
|> iterator.to_list() | |
|> string.join(":") | |
|> io.debug() | |
} | |
@external(erlang, "binary", "split") | |
fn binary_split(s: String, p: BitArray) -> List(String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment