summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Neff-Sarnow <nineff@gmail.com>2024-11-30 10:10:22 +0100
committerGitHub <noreply@github.com>2024-11-30 09:10:22 +0000
commit76c24ee6e35715cd14bb892d7b6b8d775c680bf7 (patch)
tree8fc88fa86d04cf4e54db9f199b7186658d88645a
parentd40c8ab6ab4f7051a12e5ce9433439f3a5afb99f (diff)
Add documentation example to `array.sorted()` (#5475)
Co-authored-by: Malo <57839069+MDLC01@users.noreply.github.com>
-rw-r--r--crates/typst-library/src/foundations/array.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/typst-library/src/foundations/array.rs b/crates/typst-library/src/foundations/array.rs
index 9c8aecac..4667ee76 100644
--- a/crates/typst-library/src/foundations/array.rs
+++ b/crates/typst-library/src/foundations/array.rs
@@ -815,6 +815,19 @@ impl Array {
///
/// Returns an error if two values could not be compared or if the key
/// function (if given) yields an error.
+ ///
+ /// To sort according to multiple criteria at once, e.g. in case of equality
+ /// between some criteria, the key function can return an array. The results
+ /// are in lexicographic order.
+ ///
+ /// ```example
+ /// #let array = (
+ /// (a: 2, b: 4),
+ /// (a: 1, b: 5),
+ /// (a: 2, b: 3),
+ /// )
+ /// #array.sorted(key: it => (it.a, it.b))
+ /// ```
#[func]
pub fn sorted(
self,