From c8b1eedb814c260fe9db6b6b8925823382b60620 Mon Sep 17 00:00:00 2001 From: Santi Lertsumran Date: Wed, 25 Sep 2024 17:12:44 +0700 Subject: [PATCH] feat: update stdlib function `at` of list is deprecated (#4) * feat: update stdlib function `at` of list is deprecated * style: formatted * ci: update gleam-version --- .github/workflows/test.yml | 2 +- manifest.toml | 11 +++++++++++ src/minigen.gleam | 14 ++++++++++++-- test/minigen/minigen/interop_test.gleam | 2 +- test/minigen/minigen_test.gleam | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 manifest.toml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf2096e..5e6ed8d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: - uses: erlef/setup-beam@v1 with: otp-version: "26.0.2" - gleam-version: "0.32.4" + gleam-version: "1.4.1" rebar3-version: "3" # elixir-version: "1.15.4" - run: gleam deps download diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..46bd12c --- /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.32" } +gleeunit = { version = "~> 1.0" } diff --git a/src/minigen.gleam b/src/minigen.gleam index 83deff1..0f74158 100644 --- a/src/minigen.gleam +++ b/src/minigen.gleam @@ -353,7 +353,17 @@ pub fn element_of_list(ls: List(a)) -> Generator(Result(a, Nil)) { ls |> list.length |> integer - |> map(list.at(ls, _)) + |> map(at(ls, _)) +} + +fn at(in list: List(a), get index: Int) -> Result(a, Nil) { + case index >= 0 { + True -> + list + |> list.drop(index) + |> list.first + False -> Error(Nil) + } } /// Creates a generator that changes the order of the elements in a list. @@ -396,7 +406,7 @@ pub fn shuffled_list(ls: List(a)) -> Generator(List(a)) { use indexes <- map(gen) use acc, i <- list.fold(indexes, #([], ls)) let #(selected_elems, rest_elems) = acc - let #(before, [chosen, ..after]) = list.split(rest_elems, i) + let assert #(before, [chosen, ..after]) = list.split(rest_elems, i) let next_selected_elems = list.prepend(selected_elems, chosen) let next_rest_elems = list.append(before, after) #(next_selected_elems, next_rest_elems) diff --git a/test/minigen/minigen/interop_test.gleam b/test/minigen/minigen/interop_test.gleam index 3c0d835..ea80ab5 100644 --- a/test/minigen/minigen/interop_test.gleam +++ b/test/minigen/minigen/interop_test.gleam @@ -1,5 +1,5 @@ -import minigen/interop import gleeunit/should +import minigen/interop pub fn uniform_s_test() { let init_state = diff --git a/test/minigen/minigen_test.gleam b/test/minigen/minigen_test.gleam index 3bec49d..18c7e7f 100644 --- a/test/minigen/minigen_test.gleam +++ b/test/minigen/minigen_test.gleam @@ -1,6 +1,6 @@ -import minigen import gleam/list import gleeunit/should +import minigen pub fn always_test() { minigen.always(5.0)