June 05, 2014 Example of filtering a Linked List that hold a custom class (Tango) | ||||
---|---|---|---|---|
| ||||
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 |
June 05, 2014 Re: Example of filtering a Linked List that hold a custom class (Tango) | ||||
---|---|---|---|---|
| ||||
Posted in reply to JJDuck | 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);
|
Copyright © 1999-2021 by the D Language Foundation