www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Example of filtering a Linked List that hold a custom class (Tango)

reply "JJDuck" <hamilton serenahamilton.com> writes:
let say I have a Linked List(tango) that holds custom class and 
how do I filter the LinkedList to extract the items that I want 
according to a particular field (a integer field) from my custom 
class?

Is it easier to do it using phobos' Array?
If it does, care to have an example on Phobos too?

Thanks a lot
Jun 05 2014
parent Justin Whear <justin economicmodeling.com> writes:
On Thu, 05 Jun 2014 17:50:37 +0000, JJDuck wrote:

 let say I have a Linked List(tango) that holds custom class and how do I
 filter the LinkedList to extract the items that I want according to a
 particular field (a integer field) from my custom class?
 
 Is it easier to do it using phobos' Array?
 If it does, care to have an example on Phobos too?
 
 Thanks a lot
Using Phobos this should work for any container type with a range interface: // Using a singly-linked list, but any container should work (MyClass[], RedBlackTree!MyClass, etc.) SList!MyClass slist = ... auto filtered = objs.filter!(o => o.myfield = 7);
Jun 05 2014