Skip to content

Add Cell<T> utility class#12

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

Add Cell<T> utility class#12
Tyrrrz merged 6 commits intoprimefrom
copilot/add-cell-generic-class

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

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
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 Outdated
Comment thread PowerKit.Tests/CellTests.cs Outdated
…e test to top

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/ba9d35c7-a7e7-49b3-917b-76df59dfd2e6

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@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
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 12, 2026

@copilot please fix build errors

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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()
Copy link

Copilot AI Apr 12, 2026

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.
…efault_Null_Test)

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/2eacd487-83e7-4da3-8f07-7cd178a593c9

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 12, 2026

@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