last n entries of an OrderedCollection

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

last n entries of an OrderedCollection

sergio_101-2
wondering of there is a built in function to spit out the last n
entires of an ordered collection..
in a pinch, this worked:
| ipcount newList |
ipcount := self repository size.
newList := OrderedCollection new.
(ipcount - anInteger) to: ipcount do: [ :n | newList add: (self
repository at: n) ].

but i am guessing that is a total kludge...
thanks!
--

----
peace,
sergio
photographer, journalist, visionary

http://www.coffee-black.com
http://www.painlessfrugality.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: last n entries of an OrderedCollection

Andreas.Raab
On 4/11/2010 8:14 PM, sergio_101 wrote:

> wondering of there is a built in function to spit out the last n
> entires of an ordered collection..
> in a pinch, this worked:
> | ipcount newList |
> ipcount := self repository size.
> newList := OrderedCollection new.
> (ipcount - anInteger) to: ipcount do: [ :n | newList add: (self
> repository at: n) ].
>
> but i am guessing that is a total kludge...

Use #last: e.g.,

        collection := (1 to: 50) asOrderedCollection.
        collection last: 5.            "45 .. 50"

There is also #first: and the companions #allButFirst: and #allButLast:,
e.g.,

        collection first: 5.           "1 .. 5"
        collection allButFirst: 5.     "6 .. 50"
        collection allButLast: 5.      "1 .. 45"

And of course these work with strings too, thus:

        'image.bmp' last: 4. ".bmp"
        'image.bmp' allButLast: 4. "image"

Cheers,
   - Andreas

Cheers,
   - Andreas
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: last n entries of an OrderedCollection

sergio_101-2
dge...
>
> Use #last: e.g.,
>

wow!

thanks!

i glossed right past that!

i saw 'last'.. not 'last:'

thanks again!

--

----
peace,
sergio
photographer, journalist, visionary

http://www.coffee-black.com
http://www.painlessfrugality.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: last n entries of an OrderedCollection

sergio_101-2
In reply to this post by Andreas.Raab
> Use #last: e.g.,
>


i take that back...

looking again, the reason i didn't see that was because it's inherited
from SequenceableCollection..

next time i go looking for functions, i will look up the hierarchy if
i don't immediately see it..

thanks again..



--

----
peace,
sergio
photographer, journalist, visionary

http://www.coffee-black.com
http://www.painlessfrugality.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners