[Dlang-internal] [OT] What do you think about declaring functions with lambda syntax?

ddcovery antoniocabreraperez at gmail.com
Fri Dec 4 11:12:23 UTC 2020


Example:

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

ulong factorial(ulong n) =>
   n>1 ? factorial(n-1)*n : 1
;

T[] sorted(T)(T[] xs) =>
   xs.length == 0 ? [] :
     xs[1..$].filter!(x=> x < xs[0]).array.sorted ~
     xs[0..1] ~
     xs[1..$].filter!(x=> x >= xs[0]).array.sorted
;

void main() =>
   [5,6,7,2,3].sorted.map!(i=>i.to!ulong.factorial).writeln
;



More information about the Dlang-internal mailing list