[Zope-dev] Functional programming

Pavlos Christoforou pavlos@gaaros.com
Thu, 24 Feb 2000 12:31:12 -0500 (EST)


On Thu, 24 Feb 2000, Tres Seaver wrote:

> 
> Agreed.  filter() is particularly nice, as it eliminates the nesting of the
> <dtml-if> inside the <dtml-in>.  For instance, to grab all contained objects
> which have a "browseable" property, set to true:
> 
>   <dtml-in "_.filter( lambda x: x.hasattr( 'browseable' )
>                             and x.browseabe, objectValues() )">


True, but it an be easily accomplished with an external method in your
acquisition path. I actually have a bunch of such utlities ...

For instance you can have an external method like (untested):

def filter(self,seq,val):
	'''Return elements in sequence (seq) which have an attribute val
and it is true'''

	return filter(lambda x,s=seq,v=val: x.hasattr(v)
                             and getattr(x,v),s)
 and call it from DTML like:


<dtml-in "filter(objectValues(),'browsable')"> 

simple and IMO more elegant than even having it in the _. 

Actually we could create a number of generalised utilities and post it
somehwere so anybody can download the file and use them.

As always security/ safety are concerns ...

Pavlos