Tuple List

Salih Dincer salihdb at hotmail.com
Thu Sep 5 13:39:53 UTC 2024


On Wednesday, 4 September 2024 at 08:58:34 UTC, Sergey wrote:
>
> Something like:
> ```d
> l2.byPair.filter!"a.value > 0".map!(a => a.key).writeln;
> ```

Thank you for your answers, my forum friends. For tuples that are 
not fully integrated into the language yet, byPair() is a nice 
possibility. Because you don't need to import std.typecons. 
Moreover, instead of a complicated syntax, associative array 
makes life easier. Here is an example:

```d
import std.range, std.algorithm,
        std.stdio;

void main()
{
   //import std.array : byPair;/*
   import std.typecons : Tuple;

   alias T = Tuple!(string, "key", int, "value");
   auto list = [T("Mutfak", 41), T("WC", 0),
                T("Salon", 42),
                T("Atelye", 0)
   ];

   list.map!"a.key".writeln;
   // ["Mutfak", "WC", "Salon", "Atelye"] ✓

   /*/

   auto list = ["Mutfak": 41, "WC": 0,
                "Salon": 42,
                "Atelye": 0
   ];
   list.byPair.map!"a.key".writeln;
   // ["WC", "Mutfak", "Atelye", "Salon"] ❓
   // but the order is uncertain!

   //*/
}
```

SDB at 79


More information about the Digitalmars-d-learn mailing list