@@ -3622,6 +3622,115 @@ pub fn main() {
36223622 ) ;
36233623}
36243624
3625+ #[ test]
3626+ fn stdlib_list_each_is_not_marked_as_pure ( ) {
3627+ assert_no_warnings ! (
3628+ (
3629+ "gleam" ,
3630+ "gleam/list" ,
3631+ r#"
3632+ pub fn each(list, f) {
3633+ case list {
3634+ [] -> Nil
3635+ [first, ..rest] -> {
3636+ f(first)
3637+ each(rest, f)
3638+ }
3639+ }
3640+ }
3641+ "#
3642+ ) ,
3643+ "
3644+ import gleam/list
3645+ pub fn main() {
3646+ list.each([1, 2, 3, 4], fn(x) { echo x })
3647+ Nil
3648+ }
3649+ "
3650+ ) ;
3651+ }
3652+
3653+ #[ test]
3654+ fn dict_each_function_is_not_marked_as_pure ( ) {
3655+ assert_no_warnings ! (
3656+ (
3657+ "gleam_stdlib" ,
3658+ "gleam/dict" ,
3659+ r#"
3660+ pub type Dict(key, value)
3661+
3662+ @external(erlang, "maps", "new")
3663+ @external(javascript, "../dict.mjs", "make")
3664+ pub fn new() -> Dict(k, v)
3665+
3666+ pub fn each(dict: Dict(k, v), fun: fn(k, v) -> a) -> Nil {
3667+ fold(dict, Nil, fn(nil, k, v) {
3668+ fun(k, v)
3669+ nil
3670+ })
3671+ }
3672+
3673+ @external(javascript, "../dict.mjs", "fold")
3674+ pub fn fold(
3675+ over dict: Dict(k, v),
3676+ from initial: acc,
3677+ with fun: fn(acc, k, v) -> acc,
3678+ ) -> acc {
3679+ let fun = fn(key, value, acc) { fun(acc, key, value) }
3680+ do_fold(fun, initial, dict)
3681+ }
3682+
3683+ @external(erlang, "maps", "fold")
3684+ fn do_fold(fun: fn(k, v, acc) -> acc, initial: acc, dict: Dict(k, v)) -> acc
3685+ "#
3686+ ) ,
3687+ "
3688+ import gleam/dict
3689+ pub fn main() {
3690+ dict.each(dict.new(), fn(_, _) { echo 1 })
3691+ Nil
3692+ }
3693+ "
3694+ ) ;
3695+ }
3696+
3697+ #[ test]
3698+ fn dict_fold_function_is_not_marked_as_pure ( ) {
3699+ assert_no_warnings ! (
3700+ (
3701+ "gleam_stdlib" ,
3702+ "gleam/dict" ,
3703+ r#"
3704+ pub type Dict(key, value)
3705+
3706+ @external(erlang, "maps", "new")
3707+ @external(javascript, "../dict.mjs", "make")
3708+ pub fn new() -> Dict(k, v)
3709+
3710+ @external(javascript, "../dict.mjs", "fold")
3711+ pub fn fold(
3712+ over dict: Dict(k, v),
3713+ from initial: acc,
3714+ with fun: fn(acc, k, v) -> acc,
3715+ ) -> acc {
3716+ let fun = fn(key, value, acc) { fun(acc, key, value) }
3717+ do_fold(fun, initial, dict)
3718+ }
3719+
3720+ @external(erlang, "maps", "fold")
3721+ fn do_fold(fun: fn(k, v, acc) -> acc, initial: acc, dict: Dict(k, v)) -> acc
3722+ "#
3723+ ) ,
3724+ "
3725+ import gleam/dict
3726+ pub fn main() {
3727+ dict.fold(dict.new(), Nil, fn(_, _, _) { Nil })
3728+ Nil
3729+ }
3730+ "
3731+ ) ;
3732+ }
3733+
36253734#[ test]
36263735fn calling_local_variable_not_marked_as_pure ( ) {
36273736 assert_no_warnings ! (
0 commit comments