[PEAK] How do I extract a subset?

Phillip J. Eby pje at telecommunity.com
Wed Apr 16 11:19:05 EDT 2008


At 11:32 AM 4/16/2008 +0300, Peter Damoc wrote:
>Hello,
>
>I have an app where I use a trellis.Set to hold some records, a 
>trellis.SortedSet to keep them in order but now I need to filter the 
>records based on some criteria.
>
>records = trellis.Set()
>filtered_records = trellis.???
>sorted_records = trellis.SortedSet(data=filtered_records)
>
>How can I do this?

In the simple case, you could just write a rule that returns a new 
set.  If you want to be more sophisticated, you can write a rule that 
adds or deletes records in filtered_records using records.added and 
records.deleted.


>Also, if I have an observer that watches over sorted_records, 
>shouldn't it be triggered if a change in the  underlying set is made?

Yes.  Of course, by "change" here, it would mean additions or 
removals from the set, not changes to mutable values associated with 
those objects.  SortedSet is intended for sets of immutable objects 
at the present time.




More information about the PEAK mailing list