@@ -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.
0 commit comments