Skip to content

Commit 8a179d6

Browse files
committed
Start sorting documentation
1 parent 1dae0c3 commit 8a179d6

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

.vuepress/configs/sidebar/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const sidebarEn: SidebarConfig = {
5454
'/book/modules.md',
5555
'/book/overlays.md',
5656
'/book/command_signature.md',
57+
'/book/sorting.md',
5758
'/book/testing.md',
5859
'/book/style_guide.md',
5960
],

book/sorting.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Sorting
2+
3+
Nushell offers many ways of sorting data, and which method you reach for will depend on the problem and what kind of data you're working with. Let's take a look at some of the ways you might wish to sort data.
4+
5+
## Basic sorting
6+
7+
Sorting a basic list works exactly how you might expect:
8+
9+
```nu
10+
> [9 3 8 1 4 6] | sort
11+
╭───┬───╮
12+
│ 0 │ 1 │
13+
│ 1 │ 3 │
14+
│ 2 │ 4 │
15+
│ 3 │ 6 │
16+
│ 4 │ 8 │
17+
│ 5 │ 9 │
18+
╰───┴───╯
19+
```
20+
21+
However, things get a bit more complex when you start combining types. For example, let's see what happens when we have a list with numbers _and_ strings:
22+
23+
```nu
24+
> ["foobar" 4 9 2 1 "hello" 8 6] | sort
25+
╭───┬────────╮
26+
│ 0 │ 1 │
27+
│ 1 │ 2 │
28+
│ 2 │ 4 │
29+
│ 3 │ 6 │
30+
│ 4 │ 8 │
31+
│ 5 │ 9 │
32+
│ 6 │ foobar │
33+
│ 7 │ hello │
34+
╰───┴────────╯
35+
```
36+
37+
We can see that the numbers are sorted in order, and the strings are sorted to the end of the list, also in order. If you are coming from other programming languages, this may not be quite what you expect. In Nushell, as a general rule, **data can always be sorted without erroring**.
38+
39+
::: tip
40+
If you _do_ want a sort containing differing types to error, see [strict sort](#strict-sort).
41+
:::
42+
43+
## Custom sorts
44+
45+
### Strict sort

0 commit comments

Comments
 (0)