Repository navigation
feat(ts): translate repeat, repeat_n, once_with, and a hash map's and set's extract_if, with Debug of a B-tree set's operations and the ExtractIfs - #547
Merged
Conversation
Quest-Claim: 6f94836345f47824
… set's extract_if, with Debug of a B-tree set's operations and the ExtractIfs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ach their own Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…latten Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 3, 2026 21:17
|
This run was cancelled before it finished. |
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.

Problem
iter::repeat,repeat_n, andonce_withhad no mapping, nor didHashMap::extract_ifandHashSet::extract_if.Debugof aBTreeSet's set operations and of a list'sExtractIfwas refused as an unsupported call. Continues quest/m3/ts-iter-source-debug.md after #542.Approach
rt.iterRepeat,rt.iterRepeatN,rt.iterOnceWith: each item is a clone of the element, exceptrepeat_n's last, which is the element itself.Repeatskips nothing, and itscountandlastpanic withiterator is infinite.RepeatNdrops its element when an advance passes the last item, and its owncountandlastclone nothing. ATakeof aRepeatreads from the back as it does from the front, as std's specialization does.once_with's closure is called on the first read from either end; anFnclosure goes throughrt.once, as std calls it throughFnOnce, and one never called drops with the iterator.dropsnow sees the element aRepeatNholds inside its private struct.rt.hashExtractIf,hashExtractIfMut(values JS copies, lent as places), andhashExtractKeysIftake out what the closure accepts as they read, inhashIter's order and through collided chains too. They keep what they haven't read and hint(0, unread)as hashbrown's does.Debug:Repeat { element },RepeatN { count, element }, andOnceWith(Some(_))(unpadded). ABTreeSet'sDifferenceandIntersectionwrite the way std picked (Stitch,Search,Iterate,Answer), andUnionandSymmetricDifferencewrite theirMergeIterInnerwith the key it holds back. To make that state readable, a newSearchclass replaces both the intersection'siterFilterand the difference's set lookup. A list'sExtractIfwritespeek, and a hash map's and set's writeExtractIf { .. }.countandlastof an iterator that holds aRepeator aRepeatN, or flattens one, take the owned path, which reaches their owncountandlast(as aCyclealready did).Debugof astr's searches (Splitand its forms,Matches,MatchIndices,Lines,SplitWhitespace) is now refused with a precise reason. std writes its searcher's state (finger, the Two-Way searcher'scrit_pos/period/byteset/memory) in UTF-8 bytes, and the runtime searches in UTF-16 by aPattern. Matching it means porting std's searchers or replaying them, which can land on its own, so the quest is rewritten to that remainder.Tests are differential against native Rust:
lang/shapesfmt::sourcesand the newfmt::setscoverDebugfresh,{:#?},{:x?}, padded, and after reads from either end;lang/clonesclones::sourcescovers clone and drop order, panics, and adaptors;lang/collectionscollections::extractscovers keys of each kind, colliding keys, and partial reads;rejectcovers thestrrefusal.Impact
Alternatives
strsearch would cost each plain search something. Measuring that is left to the rewritten quest.Follow-ups
Debugof astr's searches.extract_if, which doesn't translate at all, with itsDebug.quest/m3/ts-vec-rest.mdnow saysVec::extract_ifis refused for every element type, not only copied ones, and includes itsDebug.Review
Codex (
quest review), gpt-6.1-sol, medium effort. Round 3 on head 26df0cd: no findings.repeat_n(x).chain(empty()).count()of items that clone observably but never drop tookiterCount, which folds and clones.count/lastof an iterator holding aRepeatorRepeatNnow take the owned path, which reaches their own.Flattenof iterators that a function makes. The type walk now follows the items an iterator yields when they are iterators themselves.🤖 Generated with Claude Code