From 76c24ee6e35715cd14bb892d7b6b8d775c680bf7 Mon Sep 17 00:00:00 2001 From: Nikolai Neff-Sarnow Date: Sat, 30 Nov 2024 10:10:22 +0100 Subject: [PATCH] Add documentation example to `array.sorted()` (#5475) Co-authored-by: Malo <57839069+MDLC01@users.noreply.github.com> --- crates/typst-library/src/foundations/array.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/typst-library/src/foundations/array.rs b/crates/typst-library/src/foundations/array.rs index 9c8aecac2..4667ee765 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,