Skip to content

Commit 23ab0fa

Browse files
committed
Add note about stability to documentation
1 parent 5524a9f commit 23ab0fa

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Data/Array.purs

+5-1
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ foreign import scanr :: forall a b. (a -> b -> b) -> b -> Array a -> Array b
790790
--------------------------------------------------------------------------------
791791

792792
-- | Sort the elements of an array in increasing order, creating a new array.
793+
-- | Sorting is stable: the order of equal elements is preserved.
793794
-- |
794795
-- | ```purescript
795796
-- | sort [2, -3, 1] = [-3, 1, 2]
@@ -800,6 +801,8 @@ sort xs = sortBy compare xs
800801

801802
-- | Sort the elements of an array in increasing order, where elements are
802803
-- | compared using the specified partial ordering, creating a new array.
804+
-- | Sorting is stable: the order of elements is preserved if they are equal
805+
-- | according to the specified partial ordering.
803806
-- |
804807
-- | ```purescript
805808
-- | compareLength a b = compare (length a) (length b)
@@ -813,7 +816,8 @@ sortBy comp = sortByImpl comp case _ of
813816
LT -> -1
814817

815818
-- | Sort the elements of an array in increasing order, where elements are
816-
-- | sorted based on a projection
819+
-- | sorted based on a projection. Sorting is stable: the order of elements is
820+
-- | preserved if they are equal according to the projection.
817821
-- |
818822
-- | ```purescript
819823
-- | sortWith (_.age) [{name: "Alice", age: 42}, {name: "Bob", age: 21}]

src/Data/Array/ST.purs

+7-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ empty = new
8686
-- | Create a mutable copy of an immutable array.
8787
foreign import thaw :: forall h a. Array a -> ST h (STArray h a)
8888

89-
-- | Sort a mutable array in place.
89+
-- | Sort a mutable array in place. Sorting is stable: the order of equal
90+
-- | elements is preserved.
9091
sort :: forall a h. Ord a => STArray h a -> ST h (STArray h a)
9192
sort = sortBy compare
9293

@@ -101,7 +102,9 @@ foreign import shiftImpl
101102
-> STArray h a
102103
-> ST h (Maybe a)
103104

104-
-- | Sort a mutable array in place using a comparison function.
105+
-- | Sort a mutable array in place using a comparison function. Sorting is
106+
-- | stable: the order of elements is preserved if they are equal according to
107+
-- | the comparison function.
105108
sortBy
106109
:: forall a h
107110
. (a -> a -> Ordering)
@@ -119,7 +122,8 @@ foreign import sortByImpl
119122
-> STArray h a
120123
-> ST h (STArray h a)
121124

122-
-- | Sort a mutable array in place based on a projection.
125+
-- | Sort a mutable array in place based on a projection. Sorting is stable: the
126+
-- | order of elements is preserved if they are equal according to the projection.
123127
sortWith
124128
:: forall a b h
125129
. Ord b

0 commit comments

Comments
 (0)