aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2020-05-25 10:49:28 +0100
committerLouis Pilfold <louis@lpil.uk>2020-05-26 19:19:29 +0100
commit90eb83c27ffad8172b4b5d05435216c21741ea73 (patch)
tree3b912f806586764ef99b33c18cbd0d2b1e20c229 /src
parentf310627585fa8bec37bee7b3ac5e783d0cfbc77a (diff)
downloadgleam_stdlib-90eb83c27ffad8172b4b5d05435216c21741ea73.tar.gz
gleam_stdlib-90eb83c27ffad8172b4b5d05435216c21741ea73.zip
set.to_list
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)
+}