Skip to content

Commit 627ff7f

Browse files
ankddevlpil
authored andcommitted
chore: add changelog entry
1 parent 05d4afd commit 627ff7f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,48 @@
7272
- Redundant `_ as x` patterns are now deprecated in favour of `x`.
7373
([eutampieri](https://github.com/eutampieri))
7474

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+
75117
### Build tool
76118

77119
- New projects are generated using OTP28 on GitHub Actions.

0 commit comments

Comments
 (0)