File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 72
72
- Redundant ` _ as x ` patterns are now deprecated in favour of ` x ` .
73
73
([ eutampieri] ( https://github.com/eutampieri ) )
74
74
75
+ - The compiler will now raise warning for inefficient use of ` list.length() `
76
+ when trying to check is list empty via ` 0 < list.length(list) ` or ` list.length(list) > 0 ` as well as in other cases. For example, the following code:
77
+ ``` gleam
78
+ import gleam/list
79
+
80
+ pub fn main() {
81
+ let arr = [1, 46]
82
+ let _ = 0 < list.length(arr)
83
+ let _ = list.length(arr) > 0
84
+ }
85
+ ```
86
+
87
+ Would result in following warnings:
88
+
89
+ ```
90
+ warning: Inefficient use of `list.length`
91
+ ┌─ /data/data/com.termux/files/home/test_gleam/src/test_gleam.gleam:5:13
92
+ │
93
+ 5 │ let _ = 0 < list.length(arr)
94
+ │ ^^^^^^^^^^^^^^^^^^^^
95
+
96
+ The `list.length` function has to iterate across the whole
97
+ list to calculate the length, which is wasteful if you only
98
+ need to know if the list is empty or not.
99
+
100
+ Hint: You can use `the_list != []` instead.
101
+
102
+ warning: Inefficient use of `list.length`
103
+ ┌─ /data/data/com.termux/files/home/test_gleam/src/test_gleam.gleam:6:13
104
+ │
105
+ 6 │ let _ = list.length(arr) > 0
106
+ │ ^^^^^^^^^^^^^^^^^^^^
107
+
108
+ The `list.length` function has to iterate across the whole
109
+ list to calculate the length, which is wasteful if you only
110
+ need to know if the list is empty or not.
111
+
112
+ Hint: You can use `the_list != []` instead.
113
+ ```
114
+
115
+ ([ Andrey Kozhev] ( https://github.com/ankddev ) )
116
+
75
117
### Build tool
76
118
77
119
- New projects are generated using OTP28 on GitHub Actions.
You can’t perform that action at this time.
0 commit comments