get the first n elements of an Collection
hey all.. this is more of a style question than anything else.. what is the most 'smalltalk' way to grab the first n elements of an ordered collection? using an interval? using an iterator? thanks! -- ---- peace, sergio photographer, journalist, visionary http://www.ThoseOptimizeGuys.com http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
#first: On Thu, Sep 27, 2012 at 5:39 PM, sergio_101 <sergio.rrd@gmail.com> wrote:
hey all..
this is more of a style question than anything else..
what is the most 'smalltalk' way to grab the first n elements of an ordered collection?
using an interval? using an iterator?
thanks!
-- ---- peace, sergio photographer, journalist, visionary
http://www.ThoseOptimizeGuys.com http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
-- Mariano http://marianopeck.wordpress.com
Hi Sergio, You can do aCollection first: n Cheers 2012/9/27 sergio_101 <sergio.rrd@gmail.com>
hey all..
this is more of a style question than anything else..
what is the most 'smalltalk' way to grab the first n elements of an ordered collection?
using an interval? using an iterator?
thanks!
-- ---- peace, sergio photographer, journalist, visionary
http://www.ThoseOptimizeGuys.com http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
-- Bernat Romagosa.
thanks, guys.. for whatever reason, i couldn't seem to find that in SequenceableCollection. but after your posts, i did a search, and it was there.. my bad.. -- ---- peace, sergio photographer, journalist, visionary http://www.ThoseOptimizeGuys.com http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
On Thu, Sep 27, 2012 at 5:49 PM, sergio_101 <sergio.rrd@gmail.com> wrote:
for whatever reason, i couldn't seem to find that in SequenceableCollection. but after your posts, i did a search, and it was there.. my bad..
for these kinds of queries, never forget to check streams: aCollection asStream next: 10 In this case you can use #first: as others stated, but in many other cases streams will be the only way to solve your problem. -- Damien Cassou http://damiencassou.seasidehosting.st "Lambdas are relegated to relative obscurity until Java makes them popular by not having them." James Iry
On 29 Sep 2012, at 12:22, Damien Cassou <damien.cassou@gmail.com> wrote:
for these kinds of queries, never forget to check streams:
aCollection asStream next: 10
In this case you can use #first: as others stated, but in many other cases streams will be the only way to solve your problem.
Yes, that is a good idea as well, and not even as inefficient as it seams. But the selector is #readStream (or #writeStream). Actually, using ReadStream class>>#on:from:to: can solve lots of problems efficiently as well. -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill
myCollection first: n 2012/9/27 sergio_101 <sergio.rrd@gmail.com>
hey all..
this is more of a style question than anything else..
what is the most 'smalltalk' way to grab the first n elements of an ordered collection?
using an interval? using an iterator?
thanks!
-- ---- peace, sergio photographer, journalist, visionary
http://www.ThoseOptimizeGuys.com http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
-- *Guillaume Larcheveque*
participants (6)
-
Bernat Romagosa -
Damien Cassou -
Guillaume Larcheveque -
Mariano Martinez Peck -
sergio_101 -
Sven Van Caekenberghe