Skip to content

Enhance builder-likeness of commit::topo::Builder in gix-traverse #1716

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

Merged

Conversation

neithernut
Copy link
Contributor

Previously, the only way to create a Builder would be via Builder::from_iters. That function takes as arguments both the tips and ends, and used to be the only possibility for specifying either of them during the building process.

I would argue that the whole point of a builder is the ability to start with a minimal, setup and configure the resulting entity bit by bit. This would imo include the optional ends of a Topo, and I would also argue that there are valid use-cases in which a user would also like to add multiple distinct sets of tips without the need for Iterator chaining or, in the worst case, collecting them in another data structure first.

These changes introduce a set of functions enabling alternative usage patterns.

Currently, `Builder::from_iters` takes as arguments both the tips and
ends, and it's the only possibility for specifying either of them during
the building process. Considering that `ends` in `Builder::from_iters`
is an `Option`, this is not very builder-like and obstructs some
use-cases.

This change introduces a fn which allows adding additional ends after
initial construction of a "fresh" `Builder`.
Currently, `Builder::from_iters` takes as arguments both the tips and
ends. Previously, this would be the only possibility for specifying
either of them during the building process. To enhance the
builder-likeness of `Builder`, we recently introduced a fn for adding
additional ends.

This change introduces a fn which allows adding additional tips after
initial construction of a "fresh" `Builder`, allowing for more usage
patterns.
Previously, the only way to create a `Builder` would be via
`Builder::from_iters`. That fn takes as arguments both the tips and
ends, and used to be the only possibility for specifying either of them
during the building process. However, in order to enhance the builder-
likeness of `Builder`, we recently introduced fns `with_tips` and
`with_ends` for adding additional tips and ends.

With those fns, the only component which needs to be supplied up-front
is `find`. Users can specify and empty `Iterator` and `None` for `tips`
and `ends` respectively when calling `Builder::from_iters` and add
additional tips and ends at their leisure, without the need to chain
`Iterator`s or collecting them in some external data structure.

Now, calling `Builder::from_iters` with a empty lists for tips and ends
is a bit awkward. Thus, we provide a new method for creating a bare
`Builder`.
@neithernut neithernut force-pushed the traverse-topo-builder-enhancements branch from 3852de6 to 67d876c Compare December 9, 2024 12:55
Previously, the only way to create a `Builder` would be via
`Builder::from_iters`. That fn takes as arguments both the tips and
ends, and used to be the only possibility for specifying either of them
during the building process. However, in order to enhance the builder-
likeness of `Builder`, we recently introduced various fns allowing for
alternative build flows.

This fn reduces code duplication by using those new fns for implementing
`from_iters`.
@neithernut neithernut force-pushed the traverse-topo-builder-enhancements branch from 67d876c to 29e3bbf Compare December 9, 2024 12:58
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

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

Thanks a lot for contributing - these changes make perfect sense!

@Byron Byron enabled auto-merge December 9, 2024 14:01
@Byron Byron merged commit 67f20b1 into GitoxideLabs:main Dec 9, 2024
20 checks passed
@neithernut neithernut deleted the traverse-topo-builder-enhancements branch December 9, 2024 21:03
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.

2 participants