<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
                                        Hi Christoph --<div><br></div><div>So you want to convert something that looks like a bag to actually be an instance of Bag? Uhh... I expect that you use Dictionary instead of Bag in the first place because of performance? Well, it feels like you would want to be able to convert a Dictionary to a Morph, too, if that dict happens to have #color and #bounds set? Doesn't feel right. Like importing something from JSON, getting a Dictionary and now wanting to find the system's matching classes to keep on working with domain-specific objects.</div><div><br></div><div>I would write your example like this:</div><div><br></div><div><span style="font-size: 10pt">counts := Dictionary new at: 6 put: 2; at: 7 put: 1; at: 61 put: 17; yourself.</span><br></div><div>bag := Bag new.</div><div>counts keysAndValuesDo: [:object :count |</div><div>   bag add: object withOccurrences: count].</div><div><br></div><div>Or use a bag in the first place.</div><div><br></div><div>Well, I think I could live with something like Dictionary >> #asBag if each association's #value happens to be an integer.</div><div><br></div><div>Why do you want to have that anyway? Just for HistogramMorph? You could as well make that compatible with Dictionary.</div><div><br></div><div>Best,</div><div>Marcel</div><div class="mb_sig"></div>
                                        <blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px">
                        <p style="color: #AAAAAA; margin-top: 10px;">Am 16.11.2021 14:41:19 schrieb christoph.thiede@student.hpi.uni-potsdam.de <christoph.thiede@student.hpi.uni-potsdam.de>:</p><div style="font-family:Arial,Helvetica,sans-serif">
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>
    <span style="color: #000000">primitiveCounts</span><span style="color: #000000"> </span><b>:=</b><span style="color: #000000"> </span><span style="color: #000000">Dictionary</span><span style="color: #000000"> </span><span style="color: #000080">new</span><span style="color: #000000"> </span><span style="color: #000080">at:</span><span style="color: #000000"> </span><span style="color: #800000">6</span><span style="color: #000000"> </span><span style="color: #000080">put:</span><span style="color: #000000"> </span><span style="color: #800000">2</span><span style="color: #000000">;</span><span style="color: #000000"> </span><span style="color: #000080">at:</span><span style="color: #000000"> </span><span style="color: #800000">7</span><span style="color: #000000"> </span><span style="color: #000080">put:</span><span style="color: #000000"> </span><span style="color: #800000">1</span><span style="color: #000000">;</span><span style="color: #000000"> </span><span style="color: #000080">at:</span><span style="color: #000000"> </span><span style="color: #800000">61</span><span style="color: #000000"> </span><span style="color: #000080">put:</span><span style="color: #000000"> </span><span style="color: #800000">17</span><span style="color: #000000">;</span><span style="color: #000000"> </span><span style="color: #000080">yourself</span><span style="color: #000000">.</span><span style="color: #000000"><br>
    (</span><span style="color: #000000">primitiveCounts</span><span style="color: #000000"> </span><span style="color: #000080">associations</span><span style="color: #000000"> </span><span style="color: #000080">collect:</span><span style="color: #000000"> </span><span style="color: #008000">[</span><span style="color: #000000">:</span><span style="color: #000080">assoc</span><span style="color: #000000"> </span><span style="color: #808080">|</span><span style="color: #000000"> </span><span style="color: #000000">Array</span><span style="color: #000000"> </span><span style="color: #000080">new:</span><span style="color: #000000"> </span><span style="color: #000080">assoc</span><span style="color: #000000"> </span><span style="color: #000080">value</span><span style="color: #000000"> </span><span style="color: #000080">withAll:</span><span style="color: #000000"> </span><span style="color: #000080">assoc</span><span style="color: #000000"> </span><span style="color: #000080">key</span><span style="color: #008000">]</span><span style="color: #000000">)</span><span style="color: #000000"> </span><span style="color: #000080">flatten</span><span style="color: #000000"> </span><span style="color: #000080">as:</span><span style="color: #000000"> </span><span style="color: #000000">Bag</span><br>
<br>
Which really feels a bit cumbersome. :-)<br>
<br>
Best,<br>
Christoph<br>
<br>
<span style="color: #808080">---<br>
</span><span style="color: #808080"><i>Sent from </i></span><span style="color: #808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><span style="color: #808080">Squeak Inbox Talk</span></u></a></i></span><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>
> </div></blockquote></div>