Hi Marcel, hi Tobias,<br>
<br>
I would rather call it a coincidence that this constructor takes the same format as we use internally in the Bag. Maybe we should rename this into something like #newFromCounts:?<br>
<br>
For a real use case, I use my new BenchmarkSimulator to count primitive calls and end up with a dictionary primitiveCounts that maps primitive numbers to counts. I think this is a valid use case and deserves its own protocol. Otherwise, I would need to do something like this:<br>
<br>
    <font color="#000000">primitiveCounts</font><font color="#000000"> </font><b>:=</b><font color="#000000"> </font><font color="#000000">Dictionary</font><font color="#000000"> </font><font color="#000080">new</font><font color="#000000"> </font><font color="#000080">at:</font><font color="#000000"> </font><font color="#800000">6</font><font color="#000000"> </font><font color="#000080">put:</font><font color="#000000"> </font><font color="#800000">2</font><font color="#000000">;</font><font color="#000000"> </font><font color="#000080">at:</font><font color="#000000"> </font><font color="#800000">7</font><font color="#000000"> </font><font color="#000080">put:</font><font color="#000000"> </font><font color="#800000">1</font><font color="#000000">;</font><font color="#000000"> </font><font color="#000080">at:</font><font color="#000000"> </font><font color="#800000">61</font><font color="#000000"> </font><font color="#000080">put:</font><font color="#000000"> </font><font color="#800000">17</font><font color="#000000">;</font><font color="#000000"> </font><font color="#000080">yourself</font><font color="#000000">.</font><font color="#000000"><br>
    (</font><font color="#000000">primitiveCounts</font><font color="#000000"> </font><font color="#000080">associations</font><font color="#000000"> </font><font color="#000080">collect:</font><font color="#000000"> </font><font color="#008000">[</font><font color="#000000">:</font><font color="#000080">assoc</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"> </font><font color="#000000">Array</font><font color="#000000"> </font><font color="#000080">new:</font><font color="#000000"> </font><font color="#000080">assoc</font><font color="#000000"> </font><font color="#000080">value</font><font color="#000000"> </font><font color="#000080">withAll:</font><font color="#000000"> </font><font color="#000080">assoc</font><font color="#000000"> </font><font color="#000080">key</font><font color="#008000">]</font><font color="#000000">)</font><font color="#000000"> </font><font color="#000080">flatten</font><font color="#000000"> </font><font color="#000080">as:</font><font color="#000000"> </font><font color="#000000">Bag</font><br>
<br>
Which really feels a bit cumbersome. :-)<br>
<br>
Best,<br>
Christoph<br>
<br>
<font color="#808080">---<br>
</font><font color="#808080"><i>Sent from </i></font><font color="#808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></font><br>
<br>
On 2021-11-16T12:04:54+01:00, marcel.taeumel@hpi.de wrote:<br>
<br>
> > That contents is a dict is implementation detail not to be leaked.<br>
> <br>
> To be fair, there is an actual extension point in #contentsClass. Yet, it remains an implementation detail, hidden from clients. Clients should use #newFrom: or #withAll: to fill a bag with existing contents.<br>
> <br>
> Best,<br>
> Marcel<br>
> Am 16.11.2021 11:58:09 schrieb Tobias Pape <das.linux at gmx.de>:<br>
> -1<br>
> <br>
> this is to my eyes doubtlessly private :)<br>
> That contents is a dict is implementation detail not to be leaked.<br>
> <br>
> Best regards<br>
> -Tobias<br>
> <br>
> > On 16. Nov 2021, at 11:28, Marcel Taeumel wrote:<br>
> ><br>
> >> ==================== Summary ====================<br>
> >><br>
> >> Name: Collections-ct.962<br>
> >> Author: ct<br>
> >> Time: 13 November 2021, 2:29:12.457577 am<br>
> >> UUID: 762c672f-abb5-194e-9f54-14cce19aa7f9<br>
> >> Ancestors: Collections-pre.961<br>
> >><br>
> >> Adds convenience constructor to Bag.<br>
> >><br>
> >> Bag newFromContents: (Dictionary new at: #mon put: 7; at: #tue put: 2; at: #wed put: 4; yourself).<br>
> >><br>
> >> =============== Diff against Collections-pre.961 ===============<br>
> >><br>
> >> Item was added:<br>
> >> + ----- Method: Bag class>>newFromContents: (in category 'instance creation') -----<br>
> >> + newFromContents: aDictionary<br>
> >> +<br>
> >> + ^ self new setContents: aDictionary!<br>
> <br>
> <br>
> <br>
> -------------- next part --------------<br>
> An HTML attachment was scrubbed...<br>
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211116/ee077bd0/attachment.html><br>
> <br>