Skip to content

Add ProtectedUniqueArrayGene to preserve protected prefix elements un… - #1961

Open
aschenzle wants to merge 2 commits into
masterfrom
feat/protected-unique-array-gene
Open

aschenzle wants to merge 2 commits into
masterfrom
feat/protected-unique-array-gene

Conversation

@aschenzle

Copy link
Copy Markdown
Collaborator

Introduces ProtectedUniqueArrayGene<T>, an ArrayGene<T> specialization (uniqueElements = true) that protects its leading protectedCount elements from deletion while still allowing search to mutate their values in place and grow/shrink trailing elements. This supports inferred non-empty set types (such as DynamoDB SS and NS) that must never shrink below their seeded/protected elements while remaining mutable during search.

class ProtectedUniqueArrayGene<T>(
name: String,
template: T,
protectedCount: Int? = null,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

shouldn't this be 0 (no protected elements) by default?

@aschenzle aschenzle Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Given one of the goals of the structure is to protect some elements from mutation, omitting it (while still choosing to use this gene type) assumes the user wants to protect all initial elements. When omitted and set to null, the initialization sets it to elements.size(). If we set it to 0 by default, we can't do that because we don't know if the user omitted it OR set it to 0. Basically it's an opt-out of protection vs an opt-in. My opinion is that the name of the gene is intention revealing so a user should expect protection by default. Anyhow, happy to change the behaviour to opt in if you think it's better that way.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@jgaleotti Are you ok with this?

@aschenzle
aschenzle requested a review from jgaleotti November 28, 2026 04:39
@arcuri82
arcuri82 force-pushed the feat/protected-unique-array-gene branch from 9685908 to fc20430 Compare November 30, 2026 09:22
@arcuri82
arcuri82 removed their request for review December 1, 2026 06:59
@arcuri82

arcuri82 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

@aschenzle hi! recall in PRs to ask @jgaleotti review and, when he is happy with changes, he ll ask for mine ;)

Base automatically changed from fix/array-gene-unique-elements-mutation to master December 1, 2026 07:01
@arcuri82
arcuri82 force-pushed the feat/protected-unique-array-gene branch from fc20430 to 1138428 Compare December 1, 2026 07:01
@aschenzle
aschenzle force-pushed the feat/protected-unique-array-gene branch from 1138428 to 79ddb02 Compare December 2, 2026 06:15
@jgaleotti
jgaleotti requested a review from arcuri82 December 2, 2026 19:00
@aschenzle
aschenzle force-pushed the feat/protected-unique-array-gene branch from 2f88a6c to 89ba432 Compare December 3, 2026 23:47
@aschenzle
aschenzle requested a review from arcuri82 December 4, 2026 00:50
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.

3 participants