Skip to content

Extend options stdlib #24849

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

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open

Extend options stdlib #24849

wants to merge 1 commit into from

Conversation

Nycto
Copy link
Contributor

@Nycto Nycto commented Apr 5, 2025

This changes adds more procs to the options stdlib. These are convenience functions that make life easier when interacting with Options -- I've wound up adding them to just about every app I have written with Nim.

assert some(-11).filterIt(it > 0) == none(int)
block:
var outcome: Option[T]
if value.isSome:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here where value is instantiated multiple times - also, this implementation has the surprising and expensive implementation characteristic that when action returns true, the value is copied twice instead of not at all - compare that with seq that leaves its elements untouched.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catches

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 this pull request may close these issues.

3 participants