Skip to content

Add Cell<T> utility class - #12

Merged
Tyrrrz merged 6 commits into
primefrom
copilot/add-cell-generic-class
Apr 12, 2026
Merged

Tyrrrz merged 6 commits into
primefrom
copilot/add-cell-generic-class

Conversation

Copilot AI commented Apr 12, 2026 •

Copy link
Copy Markdown
Contributor

Ports Box<T> from Gress as Cell<T> — a generic container for a value that may or may not be set. Unlike Nullable<T>, it treats null as a valid stored value, distinguishing "no value" from "value is null".

Changes

  • PowerKit/Cell.cs — internal Cell<T> with Store(T value), TryOpen(out T value) → bool, and OpenOrDefault(T defaultValue = default!) → T
  • PowerKit.Tests/CellTests.cs — covers unset, set non-null, set null, and OpenOrDefault cases
var cell = new Cell<string?>();

cell.TryOpen(out _);           // false — nothing stored yet
cell.OpenOrDefault("hello");   // "hello" — falls back to default

cell.Store(null);
cell.TryOpen(out var v);       // true — null is a valid stored value
cell.OpenOrDefault("hello");   // null — stored value takes precedence

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/30a1e39c-5a31-4ad8-be5d-42701a4510eb

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Comment thread PowerKit/Cell.cs Resolved
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/7192607d-2576-429f-ab7b-3f0ff07bc0cb

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI requested a review from Tyrrrz April 12, 2026 16:32
Comment thread PowerKit.Tests/CellTests.cs Resolved
Comment thread PowerKit.Tests/CellTests.cs Resolved
@Tyrrrz
Tyrrrz marked this pull request as ready for review April 12, 2026 16:41
Copilot AI review requested due to automatic review settings April 12, 2026 16:41
@Tyrrrz

Tyrrrz commented Apr 12, 2026

Copy link
Copy Markdown
Owner

@copilot please fix build errors

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an internal Cell<T> utility to represent an optionally-set value where null can still be a valid stored value (distinguishing “unset” vs “set to null”), plus unit tests validating the behavior.

Changes:

  • Introduce Cell<T> with Store, TryOpen, and OpenOrDefault.
  • Add tests for unset, set (non-null), set (null), and OpenOrDefault fallback behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
PowerKit/Cell.cs Adds the Cell<T> container implementation with set/open APIs.
PowerKit.Tests/CellTests.cs Adds unit tests covering the new Cell<T> behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit.Tests/CellTests.cs Outdated
}

[Fact]
public void OpenOrDefault_Unset_Test()

Copilot AI Apr 12, 2026

Copy link

Choose a reason for hiding this comment

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

There are two test methods with the same name/signature OpenOrDefault_Unset_Test in this file, which will cause a compile-time error. Rename the second one (the one that stores null) to a distinct name that reflects the scenario (e.g., OpenOrDefault_Null_Test).

Suggested change
public void OpenOrDefault_Unset_Test()
public void OpenOrDefault_Null_Test()

Copilot uses AI. Check for mistakes.

Copilot AI commented Apr 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please fix build errors

Fixed in fa82809 — there was a duplicate OpenOrDefault_Unset_Test method; the second one (testing the null-stored case) has been renamed to OpenOrDefault_Null_Test.

@Tyrrrz
Tyrrrz merged commit 4fc0e57 into prime Apr 12, 2026
7 checks passed
@Tyrrrz
Tyrrrz deleted the copilot/add-cell-generic-class branch April 12, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants