<div dir="ltr"><div dir="ltr"><div>I note false polymorphism with Integer>>take:</div><div>of course both are related, since Integer>>take: (11 take: 4) tells how many different ways you can #take: 4 elements from a Set of size 11...<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le jeu. 9 mai 2019 à 15:27, <<a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">A new version of Collections was added to project The Inbox:<br>
<a href="http://source.squeak.org/inbox/Collections-mt.832.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/inbox/Collections-mt.832.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Collections-mt.832<br>
Author: mt<br>
Time: 9 May 2019, 3:27:06.069782 pm<br>
UUID: b3c087f4-c2bc-d542-91d7-9c214ae3a97f<br>
Ancestors: Collections-nice.831<br>
<br>
Adds #take: to create a sub-collection from any collection by specifying the number of elements. Works like #first: for sequenceable collections but does not fail if collection is too small.<br>
<br>
=============== Diff against Collections-nice.831 ===============<br>
<br>
Item was added:<br>
+ ----- Method: CharacterSet>>take: (in category 'accessing') -----<br>
+ take: n<br>
+ <br>
+       self shouldNotImplement.!<br></blockquote><div>Why? a simple do: loop seems feasible.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Item was added:<br>
+ ----- Method: Collection>>take: (in category 'accessing') -----<br>
+ take: n<br>
+       "Enumerate this collection and return the first n elements or less."<br>
+ <br>
+       | index result |<br>
+       index := 1.     <br>
+       result := self species new: (n min: self size).<br>
+       self associationsDo: [:each | <br>
+               result add: each.<br>
+               (index := index + 1) > n ifTrue: [^ result]]. <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+       ^ result!<br></blockquote><div>First reaction: I did not understand associationsDo:... Why not just do:?</div><div>After verification: I see that default Behavior of associationsDo: is to do: and this avoids a redefinition of take: in Dictionary...</div><div>I don't find it unsurprising, but if it works...<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Item was added:<br>
+ ----- Method: SequenceableCollection>>take: (in category 'accessing') -----<br>
+ take: n<br>
+ <br>
+       ^ self first: (n min: self size)!<br>
<br>
Item was added:<br>
+ ----- Method: Stream>>take: (in category 'accessing') -----<br>
+ take: n<br>
+ <br>
+       ^ self next: n!<br>
<br>
<br>
</blockquote></div></div>