Skip to content

Commit

Permalink
Respond to comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ploeh committed Jul 30, 2024
1 parent 5a23b15 commit d331475
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions _posts/2024-07-01-an-immutable-priority-collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,20 @@ <h2 id="comments-header">
</div>
<div class="comment-date">2024-07-29 13:53 UTC</div>
</div>

<div class="comment" id="caea05695c184c8294874896fa8b7553">
<div class="comment-author"><a href="/">Mark Seemann</a> <a href="#caea05695c184c8294874896fa8b7553">#</a></div>
<div class="comment-content">
<p>
Thank you for writing. Whether or not a <em>wither</em> works in this case depends on language implementation details. For example, the F# example code doesn't allow <a href="https://learn.microsoft.com/dotnet/fsharp/language-reference/copy-and-update-record-expressions">copy-and-update expressions</a> because the record constructor is <code>private</code>. This is as it should be, since otherwise, client code would be able to circumvent the encapsulation.
</p>
<p>
I haven't tried to refactor the C# class to a <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/record">record</a>, and I don't recall whether C# <em>with expressions</em> respect custom constructors. That's a good exercise for any reader to try out; unfortunately, I don't have time for that at the moment.
</p>
<p>
As to your other point, it's definitely conceivable that a library developer could add more convenient methods to the <code><span style="color:#2b91af;">PriorityCollection</span>&lt;<span style="color:#2b91af;">T</span>&gt;</code> class, including one that uses a simple formula to redistribute existing priorities to make way for the new one. As far as I can tell, though, you'd be able to implement such more convenient APIs as extension methods that are implemented using the basic affordances already on display here. If so, we may consider the constructor and the <code><span style="color:#2b91af;">IReadOnlyCollection</span>&lt;<span style="color:#2b91af;">Prioritized</span>&lt;<span style="color:#2b91af;">T</span>&gt;&gt;</code> interface as the fundamental API. Everything else, including the <code>Edit</code> method, could build off that.
</p>
</div>
<div class="comment-date">2024-07-30 06:46 UTC</div>
</div>
</div>

0 comments on commit d331475

Please sign in to comment.