aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/list.gleam4
-rw-r--r--src/gleam/set.gleam14
2 files changed, 16 insertions, 2 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index bb35252..c0414d4 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -721,10 +721,10 @@ fn do_sort(
/// ## Examples
///
/// > import gleam/int
-/// > list.sort([4, 3, 6, 5, 4, 1, 2], int.compare)
+/// > list.sort([4, 3, 6, 5, 4, 1, 2], by: int.compare)
/// [1, 2, 3, 4, 4, 5, 6]
///
-pub fn sort(list: List(a), sort_by compare: fn(a, a) -> Order) -> List(a) {
+pub fn sort(list: List(a), by compare: fn(a, a) -> Order) -> List(a) {
do_sort(list, compare, length(list))
}
diff --git a/src/gleam/set.gleam b/src/gleam/set.gleam
index 7b52064..a654200 100644
--- a/src/gleam/set.gleam
+++ b/src/gleam/set.gleam
@@ -73,3 +73,17 @@ pub fn contains(in set: Set(element), this member: element) -> Bool {
pub fn delete(from set: Set(element), this member: element) -> Set(element) {
Set(map: map.delete(set.map, member))
}
+
+/// Convert the set into a list of the contained elements.
+///
+/// The list has no specific ordering, any unintentional ordering may change in
+/// future versions of Gleam or Erlang.
+///
+/// ## Examples
+///
+/// > new() |> insert(2) |> to_list
+/// [2]
+///
+pub fn to_list(set: Set(element)) -> List(element) {
+ map.keys(set.map)
+}