Repository navigation
Option#filter and #flatten - #32
Merged
Merged
Conversation
nz
enabled auto-merge
August 7, 2026 18:18
nz
force-pushed
the
feat/option-combinators
branch
from
August 7, 2026 18:27
188d0dc to
a4b3412
Compare
lutzcc1
previously approved these changes
Aug 7, 2026
Fill the non-mutating gaps against Rust's Option so application code has a combinator instead of unwrap!: filter keeps a Some only when the predicate holds, flatten removes one level of nesting. Both sit in the intersection of Rust and Ruby idiom via Enumerable precedent; flatten raises TypeMismatchError on inner values Rust's types would have rejected at compile time. unzip is declined: Ruby has no unzip idiom to anchor it. The mutating combinators (insert, get_or_insert, take, replace) are likewise omitted: an Option here is a value, not a slot. unwrap_or_default is declined; Ruby has no per-type default convention to lean on. Fixes #23.
nz
force-pushed
the
feat/option-combinators
branch
from
August 7, 2026 19:38
a4b3412 to
3dc3dc9
Compare
lutzcc1
approved these changes
Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #23.
Adds
filter(Some survives only if the predicate holds) andflatten(one level of nesting removed). Both sit in the intersection of Rust and Ruby idiom — Enumerable gives them Ruby precedent, and their semantics matchOption::filter/Option::flatten.flattenraisesTypeMismatchErrorwhen the inner value isn't an Option, a case Rust rejects at compile time, handled in the gem's pedantic style.Declined, with rationale:
unzip— Rust-idiomatic but has no Ruby analogue to anchor it (nothing in Enumerable unzips), so it falls outside the both-idioms sweet spot this gem targets. It also wasn't on the issue's priority list.unwrap_or_default— Ruby has no per-type default convention (Integerhas no.default);unwrap_or(0)at the call site is clearer than any registry we could invent. The commented-out sketch in the source is removed.insert,get_or_insert,take,replace) — the issue itself suggests declining; an Option here is a return value, not a mutable slot. The stale TODO comment list is replaced with a one-line statement of that decision.xorfrom the issue's table already landed in #13. Specified as doctests.