On Fri, Jul 12, 2002 at 12:35:18PM -0400, darren chamberlain wrote:
> > I was looking for a way to get the first n values from a list, so that
> > I could do something like:
> >   [% FOREACH item = mylist.sort('date').first(10) %]
> > [Or perhaps we need a more generic list.slice mechanism? (Although I'd
> > still like the more intuitive list.first(10) than having to say
> > list.slice(0..9) or somesuch]
> 
> I think a more general splice would be more correct and more generally
> useful.  Something like

*nod* ... I was pretty much expecting someone to push for this (although
surely it would be 'slice' rather than 'splice'?

>    [% FOREACH item = mylist.sort('date').splice(0, 10) %]
> You could create first/last/etc methods in terms of splice:

*nod*. I think I'd have a 'slice' method as well. Many people find
splice syntax quite hard to understand, and I think the syntactic sugar
is worth it here...

> And so on.  Attached is a diff against the version in CVS (2.64), but
> not tests yet.  If it's generally useful, we can commit it.

Looks good to me ...

Thanks a lot,

Tony
 (Sorry for the slow response ... 12th July is a public holiday in NI)


Reply via email to