Merging Two Sorted Sequences, Attempt 2 #184
Open
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.
Description
This is an adaptation of the
std::merge
function from the C++ language into Swift. This is the second version I've done, after [#43]. The main changes are:merge
, instead of a method that extendsSequence
andLazySequenceProtocol
. This necessitates a new name for the lazy version (now calledlazilyMerge
), since a simple overload would prevent creating eagerly-generated mergers from lazy arguments. This is inline with other functions in this library that changed into free functions.Collection
extended support. Indexing support adds a new layer of indirection. There are two ways to handle that; either rewrite the code in theCollection
index methods, hoping desynchronisation doesn't happen during feature changes or bug fixes, or use the same code base by generalizing it with a bigger layer of indirection. That's what the previous version did, which was hard to implement. Giving up and directing users to just call the eager version is safer.Detailed Design
The task is implemented as a set of overloaded free functions; a configuration type to reuse the algorithm for set-union, -intersection, etc.; a lazy sequence wrapper; and an iterator that contains the core code.
Documentation Plan
There is a new Guide page provided.
Test Plan
There is a new test code file provided.
Source Impact
The change is additive. It does take two names out of the global space.
Checklist