diff --git a/gleam.toml b/gleam.toml index fca06bd..b65c751 100644 --- a/gleam.toml +++ b/gleam.toml @@ -14,9 +14,10 @@ repository = { type = "github", user = "chouzar", repo = "lamb" } # https://gleam.run/writing-gleam/gleam-toml/. [dependencies] -gleam_stdlib = ">= 0.34.0 and < 2.0.0" -gleam_erlang = ">= 0.26.0 and < 1.0.0" +gleam_stdlib = ">= 0.53.0 and < 2.0.0" +gleam_erlang = ">= 1.0.0 and < 2.0.0" [dev-dependencies] gleeunit = ">= 1.0.0 and < 2.0.0" benchee = ">= 1.3.0 and < 2.0.0" +gleam_yielder = ">= 1.1.0 and < 2.0.0" diff --git a/manifest.toml b/manifest.toml index da4b13f..808c73f 100644 --- a/manifest.toml +++ b/manifest.toml @@ -2,16 +2,18 @@ # You typically do not need to edit this file packages = [ - { name = "benchee", version = "1.3.1", build_tools = ["mix"], requirements = ["deep_merge", "statistex", "table"], otp_app = "benchee", source = "hex", outer_checksum = "76224C58EA1D0391C8309A8ECBFE27D71062878F59BD41A390266BF4AC1CC56D" }, + { name = "benchee", version = "1.4.0", build_tools = ["mix"], requirements = ["deep_merge", "statistex", "table"], otp_app = "benchee", source = "hex", outer_checksum = "299CD10DD8CE51C9EA3DDB74BB150F93D25E968F93E4C1FA31698A8E4FA5D715" }, { name = "deep_merge", version = "1.0.0", build_tools = ["mix"], requirements = [], otp_app = "deep_merge", source = "hex", outer_checksum = "CE708E5F094B9CD4E8F2BE4F00D2F4250C4095BE93F8CD6D018C753894885430" }, - { name = "gleam_erlang", version = "0.33.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "A1D26B80F01901B59AABEE3475DD4C18D27D58FA5C897D922FCB9B099749C064" }, - { name = "gleam_stdlib", version = "0.45.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "206FCE1A76974AECFC55AEBCD0217D59EDE4E408C016E2CFCCC8FF51278F186E" }, - { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, + { name = "gleam_erlang", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "D7A2E71CE7F6B513E62F9A9EF6DFDE640D9607598C477FCCADEF751C45FD82E7" }, + { name = "gleam_stdlib", version = "0.60.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "621D600BB134BC239CB2537630899817B1A42E60A1D46C5E9F3FAE39F88C800B" }, + { name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" }, + { name = "gleeunit", version = "1.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D33B7736CF0766ED3065F64A1EBB351E72B2E8DE39BAFC8ADA0E35E92A6A934F" }, { name = "statistex", version = "1.0.0", build_tools = ["mix"], requirements = [], otp_app = "statistex", source = "hex", outer_checksum = "FF9D8BEE7035028AB4742FF52FC80A2AA35CECE833CF5319009B52F1B5A86C27" }, ] [requirements] benchee = { version = ">= 1.3.0 and < 2.0.0" } -gleam_erlang = { version = ">= 0.26.0 and < 1.0.0" } -gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" } +gleam_erlang = { version = ">= 1.0.0 and < 2.0.0" } +gleam_stdlib = { version = ">= 0.50.0 and < 2.0.0" } +gleam_yielder = { version = ">= 1.1.0 and < 2.0.0" } gleeunit = { version = ">= 1.0.0 and < 2.0.0" } diff --git a/src/lamb.gleam b/src/lamb.gleam index a5f391b..c34624f 100644 --- a/src/lamb.gleam +++ b/src/lamb.gleam @@ -1,5 +1,5 @@ -import gleam/erlang import gleam/erlang/atom.{type Atom} +import gleam/erlang/reference.{type Reference} import gleam/result.{try} import lamb/query.{type Query} @@ -15,8 +15,7 @@ pub type Table(index, record) { ) } -type TableId = - erlang.Reference +type TableId = Reference type Name = atom.Atom @@ -45,7 +44,7 @@ pub fn create( registered registered: Bool, ) -> Result(Table(index, record), Error) { // Parameter docs: https://www.erlang.org/doc/apps/stdlib/ets.html#new/2 - let name = atom.create_from_string(name) + let name = atom.create(name) // If table needs registration check for naming collisions. case registered, ffi_table_id(name) { @@ -86,7 +85,7 @@ pub fn from_name(name: String) -> Result(Table(index, record), Nil) { fn from_string(name: String) -> Result(Atom, Nil) { name - |> atom.from_string() + |> atom.get() |> result.replace_error(Nil) } diff --git a/src/lamb/query/term.gleam b/src/lamb/query/term.gleam index fffbf1c..b6bad8d 100644 --- a/src/lamb/query/term.gleam +++ b/src/lamb/query/term.gleam @@ -3,25 +3,25 @@ import gleam/erlang/atom.{type Atom} import gleam/int pub fn tag(name: String) -> Atom { - atom.create_from_string(name) + atom.create(name) } pub fn any() -> Atom { - atom.create_from_string("_") + atom.create("_") } pub fn var(position: Int) -> Atom { case position { n if n >= 0 && n <= 100_000_000 -> - atom.create_from_string("$" <> int.to_string(n)) + atom.create("$" <> int.to_string(n)) _other -> panic as "can only specify a variable between 0 and 100_000_000" } } pub fn records() -> Atom { - atom.create_from_string("$_") + atom.create("$_") } pub fn vars() -> Atom { - atom.create_from_string("$$") + atom.create("$$") } diff --git a/test/benchmark.gleam b/test/benchmark.gleam index 74c650f..6f1bbec 100644 --- a/test/benchmark.gleam +++ b/test/benchmark.gleam @@ -2,7 +2,7 @@ import artifacts/user import gleam/erlang/process import gleam/int import gleam/io -import gleam/iterator +import gleam/yielder import gleam/list import lamb import lamb/query @@ -33,13 +33,13 @@ fn initialize_indexed_table( ) let enums = - iterator.from_list([0, 1, 2]) - |> iterator.cycle() + yielder.from_list([0, 1, 2]) + |> yielder.cycle() - let ids = iterator.range(1, quantity) + let ids = yielder.range(1, quantity) - iterator.map2(enums, ids, fn(enum, id) { #(id, enum) }) - |> iterator.each(fn(params) { + yielder.map2(enums, ids, fn(enum, id) { #(id, enum) }) + |> yielder.each(fn(params) { lamb.insert(table, params.0, user.generate(params.1)) }) @@ -58,13 +58,13 @@ fn initialize_bagged_table( ) let enums = - iterator.from_list([0, 1, 2]) - |> iterator.cycle() + yielder.from_list([0, 1, 2]) + |> yielder.cycle() - let ids = iterator.range(1, quantity) + let ids = yielder.range(1, quantity) - iterator.map2(enums, ids, fn(enum, id) { #(id, enum) }) - |> iterator.each(fn(params) { + yielder.map2(enums, ids, fn(enum, id) { #(id, enum) }) + |> yielder.each(fn(params) { let assert [group, ..] = list.shuffle([GroupA, GroupB, GroupC]) lamb.insert(table, group, user.generate(params.1)) }) diff --git a/test/lamb_test.gleam b/test/lamb_test.gleam index 5b3d633..4d82c53 100644 --- a/test/lamb_test.gleam +++ b/test/lamb_test.gleam @@ -1,5 +1,5 @@ import artifacts/user.{User} -import gleam/iterator +import gleam/yielder import gleam/list import gleeunit import gleeunit/should @@ -227,13 +227,13 @@ fn initialize_users_table(records quantity: Int) -> lamb.Table(Int, user.User) { lamb.create(name: "users", access: Private, kind: Set, registered: False) let enums = - iterator.from_list([0, 1, 2]) - |> iterator.cycle() + yielder.from_list([0, 1, 2]) + |> yielder.cycle() - let ids = iterator.range(1, quantity) + let ids = yielder.range(1, quantity) - iterator.map2(enums, ids, fn(enum, id) { #(id, enum) }) - |> iterator.each(fn(params) { + yielder.map2(enums, ids, fn(enum, id) { #(id, enum) }) + |> yielder.each(fn(params) { lamb.insert(table, params.0, user.generate(params.1)) })