Skip to content

Commit 120a4b6

Browse files
authored
Update doc comments for Seq sorting (#1006)
Explain what stable means, fix mention of "list", remove mention of overly technical sounding "Schwartzian transform".
1 parent 8b4f520 commit 120a4b6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

containers/src/Data/Sequence/Internal/Sorting.hs

+8-7
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,17 @@ import Data.Sequence.Internal
7676
foldWithIndexNode)
7777
import Utils.Containers.Internal.State (State(..), execState)
7878
-- | \( O(n \log n) \). 'sort' sorts the specified 'Seq' by the natural
79-
-- ordering of its elements. The sort is stable. If stability is not
79+
-- ordering of its elements. The sort is stable, meaning the order of equal
80+
-- elements is preserved. If stability is not
8081
-- required, 'unstableSort' can be slightly faster.
8182
--
8283
-- @since 0.3.0
8384
sort :: Ord a => Seq a -> Seq a
8485
sort = sortBy compare
8586

8687
-- | \( O(n \log n) \). 'sortBy' sorts the specified 'Seq' according to the
87-
-- specified comparator. The sort is stable. If stability is not required,
88+
-- specified comparator. The sort is stable, meaning the order of equal
89+
-- elements is preserved. If stability is not required,
8890
-- 'unstableSortBy' can be slightly faster.
8991
--
9092
-- @since 0.3.0
@@ -96,11 +98,11 @@ sortBy cmp (Seq xs) =
9698
(buildIQ cmp (\s (Elem x) -> IQ s x IQNil) 0 xs)
9799

98100
-- | \( O(n \log n) \). 'sortOn' sorts the specified 'Seq' by comparing
99-
-- the results of a key function applied to each element. @'sortOn' f@ is
101+
-- the results of a key function applied to each element. The sort is stable,
102+
-- meaning the order of equal elements is preserved. @'sortOn' f@ is
100103
-- equivalent to @'sortBy' ('compare' ``Data.Function.on`` f)@, but has the
101104
-- performance advantage of only evaluating @f@ once for each element in the
102-
-- input list. This is called the decorate-sort-undecorate paradigm, or
103-
-- Schwartzian transform.
105+
-- input 'Seq'.
104106
--
105107
-- An example of using 'sortOn' might be to sort a 'Seq' of strings
106108
-- according to their length:
@@ -151,8 +153,7 @@ unstableSortBy cmp (Seq xs) =
151153
-- comparing the results of a key function applied to each element.
152154
-- @'unstableSortOn' f@ is equivalent to @'unstableSortBy' ('compare' ``Data.Function.on`` f)@,
153155
-- but has the performance advantage of only evaluating @f@ once for each
154-
-- element in the input list. This is called the
155-
-- decorate-sort-undecorate paradigm, or Schwartzian transform.
156+
-- element in the input 'Seq'.
156157
--
157158
-- An example of using 'unstableSortOn' might be to sort a 'Seq' of strings
158159
-- according to their length:

0 commit comments

Comments
 (0)