Skip to content

Commit

Permalink
feat: update stdlib function at of list is deprecated (#4)
Browse files Browse the repository at this point in the history
* feat: update stdlib function `at` of list is deprecated

* style: formatted

* ci: update gleam-version
  • Loading branch information
mrgleam authored Sep 25, 2024
1 parent a2575ec commit c8b1eed
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
@@ -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" }
14 changes: 12 additions & 2 deletions src/minigen.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/minigen/minigen/interop_test.gleam
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import minigen/interop
import gleeunit/should
import minigen/interop

pub fn uniform_s_test() {
let init_state =
Expand Down
2 changes: 1 addition & 1 deletion test/minigen/minigen_test.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import minigen
import gleam/list
import gleeunit/should
import minigen

pub fn always_test() {
minigen.always(5.0)
Expand Down

0 comments on commit c8b1eed

Please sign in to comment.