Example of filtering a Linked List that hold a custom class (Tango)
Justin Whear via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 5 10:54:42 PDT 2014
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);
More information about the Digitalmars-d-learn
mailing list