Skip to content

Instantly share code, notes, and snippets.

@manveru
Created March 25, 2024 00:29
Show Gist options
  • Save manveru/f96c4a60c62a1e947ff6dc37011b9956 to your computer and use it in GitHub Desktop.
Save manveru/f96c4a60c62a1e947ff6dc37011b9956 to your computer and use it in GitHub Desktop.
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