From 735a7a21bd1a310ab062acee9b26c51cd8a3b509 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Wed, 14 Dec 2022 20:55:00 +0100 Subject: [PATCH] Add example showing first class closure to `do` (#7473) # Description Demonstrates that you can use `do` to execute stored closures and evaluate their captures properly. # Tests + Formatting As an example test increases coverage of the usage to execute first class closures. Additional tests using that found in `tests/shell/pipeline/commands/internal.rs` --- crates/nu-command/src/core_commands/do_.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/nu-command/src/core_commands/do_.rs b/crates/nu-command/src/core_commands/do_.rs index b7f6a9ee08..2aaadf0df2 100644 --- a/crates/nu-command/src/core_commands/do_.rs +++ b/crates/nu-command/src/core_commands/do_.rs @@ -183,6 +183,11 @@ impl Command for Do { example: r#"do { echo hello }"#, result: Some(Value::test_string("hello")), }, + Example { + description: "Run a stored first-class closure", + example: r#"let text = "I am enclosed"; let hello = {|| echo $text}; do $hello"#, + result: Some(Value::test_string("I am enclosed")), + }, Example { description: "Run the closure and ignore both shell and external program errors", example: r#"do -i { thisisnotarealcommand }"#,