digitalmars.D.learn - partial with struct
- Salih Dincer (30/30) Dec 10 2024 Hi,
- Salih Dincer (9/19) Dec 10 2024 I figured it out, but it's not sense! Because as the number of
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 79
Dec 10 2024
On Tuesday, 10 December 2024 at 19:43:58 UTC, Salih Dincer wrote:```d auto nums = [ "zero", "one", "two", "six", "ten", "Twenty", "Thirty" ]; alias foo = partial!(S.filter, nums); foo('t').writeln; // okay #line 1 //foo!(true)('t').writeln; //compile error ```I figured it out, but it's not sense! Because as the number of overload functions increases, side effects will occur. Moreover, it is very ugly: ```d alias foo(bool B = false) = partial!(S.filter!B, nums); foo!true('t').writeln; // ["Twenty", "Thirty"] ``` SDB 79
Dec 10 2024