December 10

Hi,

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

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

December 10

On Tuesday, 10 December 2024 at 19:43:58 UTC, Salih Dincer wrote:

>
  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:

  alias foo(bool B = false) = partial!(S.filter!B, nums);
  foo!true('t').writeln; // ["Twenty", "Thirty"]

SDB@79