Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate how succeed can return a value #4545

Closed
dontlaugh opened this issue Dec 25, 2024 · 2 comments · Fixed by #4547
Closed

Demonstrate how succeed can return a value #4545

dontlaugh opened this issue Dec 25, 2024 · 2 comments · Fixed by #4547

Comments

@dontlaugh
Copy link
Contributor

This page has instructions on how succeed can return a value, but we don't demonstate that.

I don't know if we could show it succinctly without defining a sub

sub use-succeed() {
  given 42 {
    when Int {
        # say "Int";
        succeed "Found";
        say "never this!";
    }
    when 42 { say 42 }
    default { say "dunno?" }
  }
}

say use-succeed();

Or using do given, perhaps. Like my $value = do given { ... }

@raiph
Copy link
Contributor

raiph commented Dec 25, 2024

Or using do given, perhaps.

Yep. Just prepend a say do in front of the existing example in the doc:

say do given 42 {
    when Int {
        say "Int";
        succeed "Found";
        say "never this!";
    }
    when 42 { say 42 }
    default { say "dunno?" }
}
# OUTPUT: «Int␤Found␤»

@dontlaugh
Copy link
Contributor Author

I've opened a PR with a small modification on your suggestion #4547

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants