Skip to content

Commit e20cf17

Browse files
committed
v0.58.0
1 parent 13c2100 commit e20cf17

File tree

6 files changed

+9
-151
lines changed

6 files changed

+9
-151
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v0.58.0 - 2025-03-23
4+
5+
- The deprecated `pop` and `pop_map` functions have been removed from the
6+
`list` module.
7+
38
## v0.57.0 - 2025-03-11
49

510
- The minimum supported Gleam version has been increased to 1.9.0.

gleam.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "gleam_stdlib"
2-
version = "0.57.0"
2+
version = "0.58.0"
33
gleam = ">= 1.9.0"
44
licences = ["Apache-2.0"]
55
description = "A standard library for the Gleam programming language"

src/gleam/function.gleam

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
/// Takes a function that takes two arguments and returns a new function that
2-
/// takes the same two arguments, but in reverse order.
3-
///
4-
@deprecated("This function has been deprecated. Use a function literal instead: `fn(a, b) { fun(b, a) }`")
5-
pub fn flip(fun: fn(a, b) -> c) -> fn(b, a) -> c {
6-
fn(b, a) { fun(a, b) }
7-
}
8-
91
/// Takes a single argument and always returns its input value.
102
///
113
pub fn identity(x: a) -> a {
124
x
135
}
146

15-
/// Takes an argument and a single function,
16-
/// calls that function with that argument
17-
/// and returns that argument instead of the function return value.
7+
/// Takes an argument and a single function, calls that function with that
8+
/// argument and returns that argument instead of the function return value.
9+
///
1810
/// Useful for running synchronous side effects in a pipeline.
1911
///
2012
pub fn tap(arg: a, effect: fn(a) -> b) -> a {

src/gleam/list.gleam

-85
Original file line numberDiff line numberDiff line change
@@ -1636,91 +1636,6 @@ pub fn key_filter(
16361636
})
16371637
}
16381638

1639-
/// Removes the first element in a given list for which the predicate function returns `True`.
1640-
///
1641-
/// Returns `Error(Nil)` if no such element is found.
1642-
///
1643-
/// ## Examples
1644-
///
1645-
/// ```gleam
1646-
/// pop([1, 2, 3], fn(x) { x > 2 })
1647-
/// // -> Ok(#(3, [1, 2]))
1648-
/// ```
1649-
///
1650-
/// ```gleam
1651-
/// pop([1, 2, 3], fn(x) { x > 4 })
1652-
/// // -> Error(Nil)
1653-
/// ```
1654-
///
1655-
/// ```gleam
1656-
/// pop([], fn(_) { True })
1657-
/// // -> Error(Nil)
1658-
/// ```
1659-
///
1660-
@deprecated("This function will be removed in the next gleam_stdlib version")
1661-
pub fn pop(
1662-
in list: List(a),
1663-
one_that is_desired: fn(a) -> Bool,
1664-
) -> Result(#(a, List(a)), Nil) {
1665-
pop_loop(list, is_desired, [])
1666-
}
1667-
1668-
fn pop_loop(haystack, predicate, checked) {
1669-
case haystack {
1670-
[] -> Error(Nil)
1671-
[first, ..rest] ->
1672-
case predicate(first) {
1673-
True -> Ok(#(first, append(reverse(checked), rest)))
1674-
False -> pop_loop(rest, predicate, [first, ..checked])
1675-
}
1676-
}
1677-
}
1678-
1679-
/// Removes the first element in a given list for which the given function returns
1680-
/// `Ok(new_value)`, then returns the wrapped `new_value` as well as list with the value removed.
1681-
///
1682-
/// Returns `Error(Nil)` if no such element is found.
1683-
///
1684-
/// ## Examples
1685-
///
1686-
/// ```gleam
1687-
/// pop_map([[], [2], [3]], first)
1688-
/// // -> Ok(#(2, [[], [3]]))
1689-
/// ```
1690-
///
1691-
/// ```gleam
1692-
/// pop_map([[], []], first)
1693-
/// // -> Error(Nil)
1694-
/// ```
1695-
///
1696-
/// ```gleam
1697-
/// pop_map([], first)
1698-
/// // -> Error(Nil)
1699-
/// ```
1700-
///
1701-
@deprecated("This function will be removed in the next gleam_stdlib version")
1702-
pub fn pop_map(
1703-
in haystack: List(a),
1704-
one_that is_desired: fn(a) -> Result(b, c),
1705-
) -> Result(#(b, List(a)), Nil) {
1706-
pop_map_loop(haystack, is_desired, [])
1707-
}
1708-
1709-
fn pop_map_loop(
1710-
list: List(a),
1711-
mapper: fn(a) -> Result(b, e),
1712-
checked: List(a),
1713-
) -> Result(#(b, List(a)), Nil) {
1714-
case list {
1715-
[] -> Error(Nil)
1716-
[first, ..rest] ->
1717-
case mapper(first) {
1718-
Ok(mapped) -> Ok(#(mapped, append(reverse(checked), rest)))
1719-
Error(_) -> pop_map_loop(rest, mapper, [first, ..checked])
1720-
}
1721-
}
1722-
}
1723-
17241639
/// Given a list of 2-element tuples, finds the first tuple that has a given
17251640
/// key as the first element. This function will return the second element
17261641
/// of the found tuple and list with tuple removed.

test/gleam/function_test.gleam

-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
import gleam/function
2-
import gleam/int
32
import gleam/should
43
import gleam/string
54

6-
pub fn flip_test() {
7-
let fun = fn(s: String, i: Int) {
8-
s
9-
|> string.append("String: '", _)
10-
|> string.append("', Int: '")
11-
|> string.append(int.to_string(i))
12-
|> string.append("'")
13-
}
14-
15-
let flipped_fun = function.flip(fun)
16-
17-
fun("Bob", 1)
18-
|> should.equal("String: 'Bob', Int: '1'")
19-
20-
flipped_fun(2, "Alice")
21-
|> should.equal("String: 'Alice', Int: '2'")
22-
}
23-
245
pub fn identity_test() {
256
1
267
|> function.identity

test/gleam/list_test.gleam

-35
Original file line numberDiff line numberDiff line change
@@ -828,41 +828,6 @@ pub fn key_filter_test() {
828828
|> should.equal([])
829829
}
830830

831-
pub fn pop_test() {
832-
[1, 2, 3]
833-
|> list.pop(fn(x) { x > 2 })
834-
|> should.equal(Ok(#(3, [1, 2])))
835-
836-
[1, 2, 3]
837-
|> list.pop(fn(x) { x > 4 })
838-
|> should.equal(Error(Nil))
839-
840-
[]
841-
|> list.pop(fn(_x) { True })
842-
|> should.equal(Error(Nil))
843-
844-
// TCO test
845-
list.repeat(0, recursion_test_cycles + 10)
846-
|> list.pop(fn(x) { x > recursion_test_cycles + 1 })
847-
}
848-
849-
pub fn pop_map_test() {
850-
let get = fn(x) {
851-
case x > 0 {
852-
True -> Ok(x * 2)
853-
False -> Error(Nil)
854-
}
855-
}
856-
list.pop_map([0, 2, 3], get)
857-
|> should.equal(Ok(#(4, [0, 3])))
858-
859-
list.pop_map([0, -1], get)
860-
|> should.equal(Error(Nil))
861-
862-
list.pop_map([], get)
863-
|> should.equal(Error(Nil))
864-
}
865-
866831
pub fn key_pop_test() {
867832
list.key_pop([#("a", 0), #("b", 1)], "a")
868833
|> should.equal(Ok(#(0, [#("b", 1)])))

0 commit comments

Comments
 (0)