On Wednesday, 3 November 2021 at 00:50:51 UTC, Siarhei Siamashka wrote:
On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote:

It's supported in many modern programming languages and it's not a unique feature of the D language alone. Your code can be changed to something like this:

    import std.stdio, std.algorithm, std.conv, std.string;

    void main()
    {
      auto numbers = [-3, 14, 47, -49, -30, 15, 4, -82, 99, 26];
      char negativity, even;

write("Would you like in list (n=negatives, p=positives, b=both)? ");
      readf(" %c", &negativity);

write("Would you like in list (e=evens, o=odds, b=both)? ");
      readf(" %c", &even);

      numbers.filter!(x => !((negativity == 'n' && x > 0) ||
                             (negativity == 'p' && x < 0)))
             .filter!(x => !((even == 'e' && (x % 2)) ||
                             (even == 'o' && !(x % 2))))
             .map!text.join("\n").writeln;
    }

Wow! your code seem so nice, I like it although I don't know how exactly it works. For now I'll keep learning traditional imperative programming style then after that I'll look in the functional one, it's new to me.

Reply via email to