aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2024-05-24 16:14:08 +0100
committerLouis Pilfold <louis@lpil.uk>2024-05-24 16:14:08 +0100
commitb98705f890a2828c48dfdab291a22f145309d646 (patch)
tree5510dfce70f1d00bac770dad446bfb05147ce8d7
parentf66ad5672d061bbaba0af9458da6f1f4fe0211d9 (diff)
downloadgleam_stdlib-b98705f890a2828c48dfdab291a22f145309d646.tar.gz
gleam_stdlib-b98705f890a2828c48dfdab291a22f145309d646.zip
Remove list.at
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/gleam/list.gleam50
-rw-r--r--test/gleam/list_test.gleam14
3 files changed, 11 insertions, 54 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 42c5a4c..6e31ea5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@
- `dynamic.unsafe_coerce` function has been deprecated.
- Fixed `bit_array` slices of slices sometimes being incorrect on JavaScript.
- The `dict` module gains the `combine` function.
+- The deprecated `list.at` function has been removed.
## v0.37.0 - 2024-04-19
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index e758876..2e8e019 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -1118,40 +1118,6 @@ pub fn intersperse(list: List(a), with elem: a) -> List(a) {
}
}
-/// Returns the element in the Nth position in the list, with 0 being the first
-/// position.
-///
-/// `Error(Nil)` is returned if the list is not long enough for the given index
-/// or if the index is less than 0.
-///
-/// ## Examples
-///
-/// ```gleam
-/// at([1, 2, 3], 1)
-/// // -> Ok(2)
-/// ```
-///
-/// ```gleam
-/// at([1, 2, 3], 5)
-/// // -> Error(Nil)
-/// ```
-///
-@deprecated("
-
-Gleam lists are immutable linked lists, so indexing into them is a slow operation that must traverse the list.
-
-In functional programming it is very rare to use indexing, so if you are using indexing then a different algorithm or a different data structure is likely more appropriate.
-")
-pub fn at(in list: List(a), get index: Int) -> Result(a, Nil) {
- case index >= 0 {
- True ->
- list
- |> drop(index)
- |> first
- False -> Error(Nil)
- }
-}
-
/// Removes any duplicate elements from a given list.
///
/// This function returns in loglinear time.
@@ -1274,14 +1240,18 @@ fn sequences(
// consecutive equal items) while a descreasing sequence is strictly
// decreasing (no consecutive equal items), this is needed to make the
// algorithm stable!
- order.Gt, Descending | order.Lt, Ascending | order.Eq, Ascending ->
+ order.Gt, Descending
+ | order.Lt, Ascending
+ | order.Eq, Ascending ->
sequences(rest, compare, growing, direction, new, acc)
// We were growing an ascending (descending) sequence and the new item
// is smaller (bigger) than the previous one, this means we have to stop
// growing this sequence and start with a new one whose first item will
// be the one we just found.
- order.Gt, Ascending | order.Lt, Descending | order.Eq, Descending -> {
+ order.Gt, Ascending
+ | order.Lt, Descending
+ | order.Eq, Descending -> {
let acc = case direction {
Ascending -> [do_reverse(growing, []), ..acc]
Descending -> [growing, ..acc]
@@ -1404,8 +1374,8 @@ fn merge_ascendings(
[first1, ..rest1], [first2, ..rest2] ->
case compare(first1, first2) {
order.Lt -> merge_ascendings(rest1, list2, compare, [first1, ..acc])
- order.Gt | order.Eq ->
- merge_ascendings(list1, rest2, compare, [first2, ..acc])
+ order.Gt
+ | order.Eq -> merge_ascendings(list1, rest2, compare, [first2, ..acc])
}
}
}
@@ -1430,8 +1400,8 @@ fn merge_descendings(
[first1, ..rest1], [first2, ..rest2] ->
case compare(first1, first2) {
order.Lt -> merge_descendings(list1, rest2, compare, [first2, ..acc])
- order.Gt | order.Eq ->
- merge_descendings(rest1, list2, compare, [first1, ..acc])
+ order.Gt
+ | order.Eq -> merge_descendings(rest1, list2, compare, [first1, ..acc])
}
}
}
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam
index bdec124..dea77ff 100644
--- a/test/gleam/list_test.gleam
+++ b/test/gleam/list_test.gleam
@@ -588,20 +588,6 @@ pub fn intersperse_test() {
|> list.intersperse(0)
}
-pub fn at_test() {
- list.at([1, 2, 3], 2)
- |> should.equal(Ok(3))
-
- list.at([1, 2, 3], 5)
- |> should.equal(Error(Nil))
-
- list.at([], 0)
- |> should.equal(Error(Nil))
-
- list.at([1, 2, 3, 4, 5, 6], -1)
- |> should.equal(Error(Nil))
-}
-
pub fn unique_test() {
list.unique([1, 1, 2, 3, 4, 4, 4, 5, 6])
|> should.equal([1, 2, 3, 4, 5, 6])