partial with struct

Salih Dincer salihdb at hotmail.com
Tue Dec 10 19:43:58 UTC 2024


Hi,

I just do it directly with the S struct, why can't I filter with 
partial? (#line 1)

```d
import std.stdio, std.functional : partial;

void main()
{
   alias foo = partial!(S.filter, nums);
   foo('t').writeln; // okay
   #line 1
   //foo!(true)('t').writeln; //compile error
   S.filter!true(nums, 'T').writeln; // alternative
}

struct S
{
   import std.algorithm : F = filter;
   static auto filter(bool isEnd = false)(string[] str, char chr)
   {
     static if (isEnd)
     {
       alias pred = s => s[$-1] == chr;
       
     } else {

       alias pred = s => s[0] == chr;
     }
     return str.F!pred;
   }
}
```

SDB at 79


More information about the Digitalmars-d-learn mailing list