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

feat: implement unwrap_or in the OptionTrait #4196

Closed
1 of 2 tasks
Eikix opened this issue Oct 4, 2023 · 2 comments
Closed
1 of 2 tasks

feat: implement unwrap_or in the OptionTrait #4196

Eikix opened this issue Oct 4, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Eikix
Copy link
Contributor

Eikix commented Oct 4, 2023

Feature Request

Describe the Feature Request

Hey all!
Following this conversation on Kakarot, kkrt-labs/kakarot-ssj#322 (comment)
We wanted to see if it's possible to incorporate a unwrap_or method in the OptionTrait.

Describe Preferred Solution

Add one function in the OptionTrait:
unwrap_or

pseudo code:

fn unwrap_or(self: Option<T>, default: T) -> T {
    match self {
        Option::Some(x) => x,
        Option::None => default,
    } 
}

Additionally, I can implement unwrap_or_default

fn unwrap_or_default<+Default<T>>(self: Option<T>) -> T {
    match self {
        Option::Some(x) => x,
        Option::None => Default::default(),
    } 
}

Additional Context

If the feature request is approved, would you be willing to submit a PR?
(Help can be provided if you need assistance submitting a PR)

  • Yes
  • No
@Eikix Eikix added the enhancement New feature or request label Oct 4, 2023
@orizi orizi added the help wanted Extra attention is needed label Oct 4, 2023
@orizi
Copy link
Collaborator

orizi commented Oct 4, 2023

feel free to open a PR - sounds good.

@Eikix
Copy link
Contributor Author

Eikix commented Oct 4, 2023

Okay opening a PR soon (tm)

@Eikix Eikix closed this as completed Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants