wip: prototyping what hamt amending might look like. #35
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.
More for discussion than anything else -- not final functional code.
I started with the idea of a
func (b *Builder) StartWith(n ipld.Node) (ipld.MapAssembler, error)
method -- in other words, something on the type that implementsNodeAssembler
which has a fairly standard signature that we could make feature-detactable through a standard interface -- and just tried to see how that would go.I think this probably does a large amount of what we'd want.
We could combine this with some kind of
ipld.AmendMap(newMem NodeAssembler, basis Node) (MapAssembler, error)
method in the main IPLD packages (now that we've done go-ipld-prime#228 and released that in v0.12.0, especially), which will feature-detect this function, or, fall back onto doing a dumb copy and returning an assembler you can continue with in the semantically same way. This would make the "amend" concept usable universally, but also work efficiently when we have a function like this one implemented.There's tricky bits relating to verifying whether any are actually matching the existing structure you try to modify, but these are incidentals of this hamt implementation and whether it serializes all its parameters, how we decide to verify that, etc. Not relevant to the concept of interface generalization, if we're looking for what patterns can be extracted here.