diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..e851620 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" }, + { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, +] + +[requirements] +gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" } +gleeunit = { version = ">= 1.0.0 and < 2.0.0" } diff --git a/src/brilo.gleam b/src/brilo.gleam index ca67592..6168981 100644 --- a/src/brilo.gleam +++ b/src/brilo.gleam @@ -1,5 +1,23 @@ -import gleam/io +import gleam/iterator.{type Iterator, Done, Next} +import gleam/string -pub fn main() { - io.println("Hello from brilo!") +/// Creates an iterator that yields each grapheme from the given string. +/// +/// ## Examples +/// +/// ```gleam +/// iterator_from_string("abcd") +/// |> to_list +/// // -> ["a", "b", "c", "d"] +/// ``` +/// +pub fn iterator_from_string(string: String) -> Iterator(String) { + let yield = fn(s) { + case s |> string.pop_grapheme { + Ok(#(x, xs)) -> Next(x, xs) + _ -> Done + } + } + + iterator.unfold(from: string, with: yield) } diff --git a/test/brilo_test.gleam b/test/brilo_test.gleam index 3831e7a..627252e 100644 --- a/test/brilo_test.gleam +++ b/test/brilo_test.gleam @@ -1,3 +1,6 @@ +import brilo +import gleam/iterator +import gleam/string import gleeunit import gleeunit/should @@ -5,8 +8,12 @@ pub fn main() { gleeunit.main() } -// gleeunit test functions end in `_test` -pub fn hello_world_test() { - 1 - |> should.equal(1) +pub fn iterator_from_string_test() { + let string = "BRILO RULEZ! 🎆" + + string + |> brilo.iterator_from_string + |> iterator.to_list + |> string.join("") + |> should.equal(string) }