Skip to content

Commit

Permalink
allow last to work with ranges (nushell#11906)
Browse files Browse the repository at this point in the history
# Description

This PR allows `last` to work with ranges in the same way that `first`
does. It also adds a couple examples demonstrating it.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
  • Loading branch information
fdncred authored Feb 20, 2024
1 parent c0bac5a commit 63ccc62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/nu-command/src/filters/first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ impl Command for First {
example: "0x[01 23 45] | first 2",
result: Some(Value::binary(vec![0x01, 0x23], Span::test_data())),
},
Example {
description: "Return the first item of a range",
example: "1..3 | first",
result: Some(Value::test_int(1)),
},
]
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/nu-command/src/filters/last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl Command for Last {
Type::Any,
),
(Type::Binary, Type::Binary),
(Type::Range, Type::Any),
])
.optional(
"rows",
Expand Down Expand Up @@ -60,6 +61,11 @@ impl Command for Last {
description: "Return the last 2 bytes of a binary value",
result: Some(Value::binary(vec![0x23, 0x45], Span::test_data())),
},
Example {
example: "1..3 | last",
description: "Return the last item of a range",
result: Some(Value::test_int(3)),
},
]
}

Expand Down

0 comments on commit 63ccc62

Please sign in to comment.